From d3ed73eec0bc9d43799d4086a060b56504f997a7 Mon Sep 17 00:00:00 2001 From: Riot Date: Tue, 16 May 2023 18:44:46 +0200 Subject: [PATCH] fix: Unwrapped CustomRotations linq. --- RotationSolver/Updaters/RotationUpdater.cs | 56 +++++++++++++++++----- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 6726daddb..3a2546219 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -107,23 +107,57 @@ private static void LoadRotationsFromLocal(string relayFolder) } } - - CustomRotations = ( - from a in assemblies - from t in TryGetTypes(a) - where t.GetInterfaces().Contains(typeof(ICustomRotation)) - && !t.IsAbstract && !t.IsInterface - select GetRotation(t) into rotation - where rotation != null - group rotation by rotation.JobIDs[0] into rotationGrp - select new CustomRotationGroup(rotationGrp.Key, rotationGrp.First().JobIDs, CreateRotationSet(rotationGrp.ToArray()))).ToArray(); - + CustomRotations = LoadCustomRotationGroup(assemblies); CustomRotationsDict = new SortedList (CustomRotations.GroupBy(g => g.Rotations[0].Job.GetJobRole()) .ToDictionary(set => set.Key, set => set.OrderBy(i => i.JobId).ToArray())); } + private static CustomRotationGroup[] LoadCustomRotationGroup(List assemblies) + { + var rotationList = new List(); + foreach (var assembly in assemblies) + { + foreach (var type in TryGetTypes(assembly)) + { + if (type.GetInterfaces().Contains(typeof(ICustomRotation)) + && !type.IsAbstract && !type.IsInterface) + { + var rotation = GetRotation(type); + if (rotation != null) + { + rotationList.Add(rotation); + } + } + } + } + + var rotationGroups = new Dictionary>(); + foreach (var rotation in rotationList) + { + var jobId = rotation.JobIDs[0]; + if (!rotationGroups.ContainsKey(jobId)) + { + rotationGroups.Add(jobId, new List()); + } + rotationGroups[jobId].Add(rotation); + } + + var result = new List(); + foreach (var kvp in rotationGroups) + { + var jobId = kvp.Key; + var rotations = kvp.Value.ToArray(); + result.Add(new CustomRotationGroup(jobId, rotations[0].JobIDs, CreateRotationSet(rotations))); + } + + + return result.ToArray(); + } + + + private static async Task DownloadRotationsAsync(string relayFolder, bool mustDownload) { // Code to download rotations from remote server