/
AstroJohn
/
MailRobot
Обзор
Документация
Войти
/
AstroJohn
/
MailRobot
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
LogProcessingGate/ContestProcessorSelectorBase.cs
114 строк
4 KB
AstroJohn
FD-VHF-2026
31 июл 2026, 14:39
31 июл 2026, 14:39
47d39af
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using Common; using LogProcessingModels.Configuration; namespace LogProcessingGate { public abstract class ContestProcessorSelectorBase<TInterface> where TInterface: class { private readonly Dictionary<string, List<Type>> PROCESSOR_TYPES = new Dictionary<string, List<Type>>(); protected clsChecker_Parameters Parameters { get; } protected ContestProcessorSelectorBase(clsChecker_Parameters parameters) { Parameters = parameters; Initialize(parameters.WorkingDirectory); } protected void Initialize(string workingDirectory) { if (!typeof(TInterface).IsInterface) throw new Exception("Неверное использование класса ContestProcessorSelectorBase."); Assembly[] assemblies; try { assemblies = [ Assembly.LoadFrom(Path.Combine(workingDirectory, "CsParser.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "CsUbnSaver.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "LogScoring.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "UA1DZ.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "UA3XAN.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "VhfActivity.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "ZhukovMemorial.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "TwoCapitalsNew.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "UA1DZ.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "R3XChamp.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "SpbOpenVhf.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "WhiteNightsVhf.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "LoOpenVhf.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "FmSprint.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "FmSprintRegular.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "R3xVhfChamp.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "Ro1aHfSprint.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "FF.dll")), Assembly.LoadFrom(Path.Combine(workingDirectory, "FdVhf.dll")) ]; } catch { throw new Exception($"Invalid working directory path in configuration file: {workingDirectory}"); } var types = from a in assemblies from t in a.GetTypes() where t.IsClass && !t.IsAbstract && typeof(TInterface).IsAssignableFrom(t) let attributes = t.GetCustomAttributes(typeof(ContestProcessorAttribute), false) where attributes != null && attributes.Length > 0 select new { Type = t, Attributes = attributes.Cast<ContestProcessorAttribute>().ToArray() }; foreach (var t in types) { if (t.Attributes.Length == 0) continue; foreach (var attr in t.Attributes) { if (!PROCESSOR_TYPES.ContainsKey(attr.ContestName)) PROCESSOR_TYPES[attr.ContestName] = new List<Type>(); PROCESSOR_TYPES[attr.ContestName].Add(t.Type); } } } /// <summary> /// получает экземпляр класса обработчика по имени контеста /// </summary> /// <param name="contestName"></param> /// <returns></returns> protected IList<Type> GetProcessors(string contestName) { if (!PROCESSOR_TYPES.TryGetValue(contestName, out var types)) { types = new List<Type> { DefaultProcessor.GetType() }; } return types; } protected abstract TInterface DefaultProcessor { get; } } }