2020-05-04 17:50:02 -04:00
|
|
|
|
using IW4MAdmin.Application.IO;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2020-05-04 17:50:02 -04:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Factories
|
|
|
|
|
{
|
|
|
|
|
public class GameLogReaderFactory : IGameLogReaderFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
public GameLogReaderFactory(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IGameLogReader CreateGameLogReader(Uri[] logUris, IEventParser eventParser)
|
|
|
|
|
{
|
|
|
|
|
var baseUri = logUris[0];
|
2022-02-11 16:33:05 -05:00
|
|
|
|
if (baseUri.Scheme == Uri.UriSchemeHttp || baseUri.Scheme == Uri.UriSchemeHttps)
|
2020-05-04 17:50:02 -04:00
|
|
|
|
{
|
2022-02-11 16:33:05 -05:00
|
|
|
|
return new GameLogReaderHttp(logUris, eventParser,
|
|
|
|
|
_serviceProvider.GetRequiredService<ILogger<GameLogReaderHttp>>());
|
2020-05-04 17:50:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 16:33:05 -05:00
|
|
|
|
if (baseUri.Scheme == Uri.UriSchemeFile)
|
2020-05-04 17:50:02 -04:00
|
|
|
|
{
|
2022-02-11 16:33:05 -05:00
|
|
|
|
return new GameLogReader(baseUri.LocalPath, eventParser,
|
|
|
|
|
_serviceProvider.GetRequiredService<ILogger<GameLogReader>>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (baseUri.Scheme == Uri.UriSchemeNetTcp)
|
|
|
|
|
{
|
|
|
|
|
return new NetworkGameLogReader(logUris, eventParser,
|
|
|
|
|
_serviceProvider.GetRequiredService<ILogger<NetworkGameLogReader>>());
|
2020-05-04 17:50:02 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException($"No log reader implemented for Uri scheme \"{baseUri.Scheme}\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|