1
0
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:
Nick Blakely 2020-08-16 02:03:10 -07:00
parent 2159bbc8b9
commit 7c51747a26
19 changed files with 82 additions and 23 deletions

View File

@ -1,4 +1,4 @@
namespace Giants.DataContract
namespace Giants.DataContract.V1
{
using System;
using System.ComponentModel.DataAnnotations;

View File

@ -0,0 +1,7 @@
namespace Giants.DataContract.V1
{
public class DiscordStatus
{
public string DiscordUri { get; set; }
}
}

View File

@ -1,7 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Giants.DataContract
namespace Giants.DataContract.V1
{
public class PlayerInfo
{

View File

@ -1,4 +1,4 @@
namespace Giants.DataContract
namespace Giants.DataContract.V1
{
using System;
using System.Collections.Generic;

View File

@ -1,4 +1,4 @@
namespace Giants.DataContract
namespace Giants.DataContract.V1
{
using System;
using System.ComponentModel.DataAnnotations;

View File

@ -1,4 +1,4 @@
namespace Giants.DataContract
namespace Giants.DataContract.V1
{
using System;
using System.ComponentModel.DataAnnotations;

View File

@ -2,7 +2,7 @@
{
using System;
public class ServerInfo : DataContract.ServerInfo, IIdentifiable
public class ServerInfo : DataContract.V1.ServerInfo, IIdentifiable
{
public string id => this.HostIpAddress;

View File

@ -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);

View File

@ -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>();

View File

@ -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);

View 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"];
}
}
}

View File

@ -0,0 +1,7 @@
namespace Giants.Services
{
public interface IDiscordService
{
string GetDiscordUri();
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View 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()
};
}
}
}

View File

@ -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));

View File

@ -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);
}
}
}

View File

@ -11,5 +11,6 @@
"ContainerId": "DefaultContainer",
"ServerTimeoutPeriodInMinutes": "7",
"ServerCleanupIntervalInMinutes": "1",
"MaxServerCount": 1000
"MaxServerCount": 1000,
"DiscordUri": "https://discord.gg/Avj4azU"
}