mirror of
https://github.com/ncblakely/GiantsTools
synced 2024-11-24 07:05:37 +01:00
Add Discord URI service.
This commit is contained in:
parent
2159bbc8b9
commit
7c51747a26
@ -1,4 +1,4 @@
|
||||
namespace Giants.DataContract
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
7
Giants.DataContract/Contracts/V1/DiscordStatus.cs
Normal file
7
Giants.DataContract/Contracts/V1/DiscordStatus.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
public class DiscordStatus
|
||||
{
|
||||
public string DiscordUri { get; set; }
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Giants.DataContract
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
public class PlayerInfo
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Giants.DataContract
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Giants.DataContract
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Giants.DataContract
|
||||
namespace Giants.DataContract.V1
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
|
||||
public class ServerInfo : DataContract.ServerInfo, IIdentifiable
|
||||
public class ServerInfo : DataContract.V1.ServerInfo, IIdentifiable
|
||||
{
|
||||
public string id => this.HostIpAddress;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Giants.Services
|
||||
{
|
||||
public class VersionInfo : DataContract.VersionInfo, IIdentifiable
|
||||
public class VersionInfo : DataContract.V1.VersionInfo, IIdentifiable
|
||||
{
|
||||
public string id => GenerateId(this.AppName);
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
namespace Giants.Services
|
||||
{
|
||||
using Giants.Services.Core;
|
||||
using Giants.Services.Services;
|
||||
using Giants.Services.Store;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -16,6 +17,7 @@
|
||||
services.AddSingleton<IMemoryCache, MemoryCache>();
|
||||
services.AddSingleton<IUpdaterStore, CosmosDbUpdaterStore>();
|
||||
services.AddSingleton<IUpdaterService, UpdaterService>();
|
||||
services.AddSingleton<IDiscordService, DiscordService>();
|
||||
|
||||
services.AddHostedService<InitializerService>();
|
||||
services.AddHostedService<ServerRegistryCleanupService>();
|
||||
|
@ -1,6 +1,7 @@
|
||||
namespace Giants.Services
|
||||
{
|
||||
using AutoMapper;
|
||||
using Giants.DataContract.V1;
|
||||
|
||||
public static class Mapper
|
||||
{
|
||||
@ -17,10 +18,10 @@
|
||||
if (Instance == null)
|
||||
{
|
||||
var config = new MapperConfiguration(cfg => {
|
||||
cfg.CreateMap<DataContract.ServerInfo, Services.ServerInfo>();
|
||||
cfg.CreateMap<Services.ServerInfo, DataContract.ServerInfo>();
|
||||
cfg.CreateMap<Services.ServerInfo, DataContract.ServerInfoWithHostAddress>();
|
||||
cfg.CreateMap<Services.VersionInfo, DataContract.VersionInfo>();
|
||||
cfg.CreateMap<DataContract.V1.ServerInfo, ServerInfo>();
|
||||
cfg.CreateMap<ServerInfo, DataContract.V1.ServerInfo>();
|
||||
cfg.CreateMap<ServerInfo, ServerInfoWithHostAddress>();
|
||||
cfg.CreateMap<VersionInfo, DataContract.V1.VersionInfo>();
|
||||
});
|
||||
|
||||
Instance = new AutoMapper.Mapper(config);
|
||||
|
19
Giants.Services/Services/DiscordService.cs
Normal file
19
Giants.Services/Services/DiscordService.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace Giants.Services.Services
|
||||
{
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public class DiscordService : IDiscordService
|
||||
{
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
public DiscordService(IConfiguration configuration)
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public string GetDiscordUri()
|
||||
{
|
||||
return this.configuration["DiscordUri"];
|
||||
}
|
||||
}
|
||||
}
|
7
Giants.Services/Services/IDiscordService.cs
Normal file
7
Giants.Services/Services/IDiscordService.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Giants.Services
|
||||
{
|
||||
public interface IDiscordService
|
||||
{
|
||||
string GetDiscordUri();
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Giants.Services.Core;
|
||||
|
@ -1,12 +1,9 @@
|
||||
namespace Giants.Services
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Giants.Services.Core;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class InMemoryServerRegistryStore : IServerRegistryStore
|
||||
|
28
Giants.WebApi/Controllers/DiscordController.cs
Normal file
28
Giants.WebApi/Controllers/DiscordController.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace Giants.WebApi.Controllers
|
||||
{
|
||||
using Giants.DataContract.V1;
|
||||
using Giants.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DiscordController : ControllerBase
|
||||
{
|
||||
private readonly IDiscordService discordService;
|
||||
|
||||
public DiscordController(
|
||||
IDiscordService discordService)
|
||||
{
|
||||
this.discordService = discordService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public DiscordStatus GetDiscordStatus()
|
||||
{
|
||||
return new DiscordStatus
|
||||
{
|
||||
DiscordUri = this.discordService.GetDiscordUri()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Giants.DataContract;
|
||||
using Giants.DataContract.V1;
|
||||
using Giants.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -44,7 +44,7 @@ namespace Giants.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IEnumerable<DataContract.ServerInfoWithHostAddress>> GetServers()
|
||||
public async Task<IEnumerable<ServerInfoWithHostAddress>> GetServers()
|
||||
{
|
||||
IEnumerable<Services.ServerInfo> serverInfo = await this.serverRegistryService.GetAllServers();
|
||||
|
||||
@ -65,7 +65,7 @@ namespace Giants.Web.Controllers
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task AddServer([FromBody]DataContract.ServerInfo serverInfo)
|
||||
public async Task AddServer([FromBody] DataContract.V1.ServerInfo serverInfo)
|
||||
{
|
||||
ArgumentUtility.CheckForNull(serverInfo, nameof(serverInfo));
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Giants.DataContract;
|
||||
using Giants.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@ -22,11 +21,11 @@ namespace Giants.WebApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<DataContract.VersionInfo> GetVersionInfo(string appName)
|
||||
public async Task<DataContract.V1.VersionInfo> GetVersionInfo(string appName)
|
||||
{
|
||||
Services.VersionInfo versionInfo = await this.updaterService.GetVersionInfo(appName);
|
||||
|
||||
return mapper.Map<DataContract.VersionInfo>(versionInfo);
|
||||
return mapper.Map<DataContract.V1.VersionInfo>(versionInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,6 @@
|
||||
"ContainerId": "DefaultContainer",
|
||||
"ServerTimeoutPeriodInMinutes": "7",
|
||||
"ServerCleanupIntervalInMinutes": "1",
|
||||
"MaxServerCount": 1000
|
||||
"MaxServerCount": 1000,
|
||||
"DiscordUri": "https://discord.gg/Avj4azU"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user