Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: Unwrapped CustomRotations linq.
Browse files Browse the repository at this point in the history
  • Loading branch information
RiotNOR committed May 16, 2023
1 parent b73ab67 commit d3ed73e
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobRole, CustomRotationGroup[]>
(CustomRotations.GroupBy(g => g.Rotations[0].Job.GetJobRole())
.ToDictionary(set => set.Key, set => set.OrderBy(i => i.JobId).ToArray()));
}

private static CustomRotationGroup[] LoadCustomRotationGroup(List<Assembly> assemblies)
{
var rotationList = new List<ICustomRotation>();
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<ClassJobID, List<ICustomRotation>>();
foreach (var rotation in rotationList)
{
var jobId = rotation.JobIDs[0];
if (!rotationGroups.ContainsKey(jobId))
{
rotationGroups.Add(jobId, new List<ICustomRotation>());
}
rotationGroups[jobId].Add(rotation);
}

var result = new List<CustomRotationGroup>();
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
Expand Down

0 comments on commit d3ed73e

Please sign in to comment.