aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
diff options
context:
space:
mode:
authorRogueAI42 <[email protected]>2017-06-11 17:34:38 +1000
committerRogueAI42 <[email protected]>2017-06-11 17:38:53 +1000
commit107a98686a105468b5f200ebcbd27343c1210ce4 (patch)
treef6b8403368ddf0b4be2569c0ac8c237635e7b764 /ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
parentc3deaa23fffb7011efb2b5b0f7fc3e754d21f600 (diff)
downloadshiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.gz
shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.tar.bz2
shiftos_thereturn-107a98686a105468b5f200ebcbd27343c1210ce4.zip
ReflectMan Saves The Day..............
Refactored every part in the code that used that damn foreach loop. All assemblies are now loaded on startup into an array, and the results of GetType() on each are concatenated into another array. The parts of the code that were loading the assemblies and scanning them themselves now look to ReflectMan.Types, and all disk I/O is limited to the first time ReflectMan is accessed. While I was there I also replaced some other foreach loops with array comprehensions and such to speed things up - there is a noticeable improvement. It doesn't seem to have broken anything, but I'd appreciate if someone could do more stress testing for me.
Diffstat (limited to 'ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs')
-rw-r--r--ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs57
1 files changed, 19 insertions, 38 deletions
diff --git a/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
index 6e692a7..10ba809 100644
--- a/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
+++ b/ShiftOS.WinForms/ShiftnetSites/MainHomepage.cs
@@ -39,49 +39,30 @@ namespace ShiftOS.WinForms.ShiftnetSites
{
//Get the Fundamentals List
flfundamentals.Controls.Clear();
- foreach (var exe in Directory.GetFiles(Environment.CurrentDirectory))
+ foreach (var type in Array.FindAll(ReflectMan.Types, t => t.GetInterfaces().Contains(typeof(IShiftnetSite)) && t.BaseType == typeof(UserControl) && Shiftorium.UpgradeAttributesUnlocked(t)))
{
- if (exe.EndsWith(".exe") || exe.EndsWith(".dll"))
+ var attrs = type.GetCustomAttributes(false);
+ var attribute = attrs.FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute;
+ if (attribute != null)
{
- try
+ if (attrs.OfType<ShiftnetFundamentalAttribute>().Any())
{
- var asm = Assembly.LoadFile(exe);
- foreach (var type in asm.GetTypes())
+ var dash = new Label();
+ dash.Text = " - ";
+ dash.AutoSize = true;
+ flfundamentals.Controls.Add(dash);
+ dash.Show();
+ var link = new LinkLabel();
+ link.Text = attribute.Name;
+ link.Click += (o, a) =>
{
- if (type.GetInterfaces().Contains(typeof(IShiftnetSite)))
- {
- if (type.BaseType == typeof(UserControl))
- {
- var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute;
- if (attribute != null)
- {
- if (Shiftorium.UpgradeAttributesUnlocked(type))
- {
- if (type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetFundamentalAttribute) != null)
- {
- var dash = new Label();
- dash.Text = " - ";
- dash.AutoSize = true;
- flfundamentals.Controls.Add(dash);
- dash.Show();
- var link = new LinkLabel();
- link.Text = attribute.Name;
- link.Click += (o, a) =>
- {
- GoToUrl?.Invoke(attribute.Url);
- };
- flfundamentals.Controls.Add(link);
- flfundamentals.SetFlowBreak(link, true);
- link.Show();
- link.LinkColor = SkinEngine.LoadedSkin.ControlTextColor;
- }
- }
- }
- }
- }
- }
+ GoToUrl?.Invoke(attribute.Url);
+ };
+ flfundamentals.Controls.Add(link);
+ flfundamentals.SetFlowBreak(link, true);
+ link.Show();
+ link.LinkColor = SkinEngine.LoadedSkin.ControlTextColor;
}
- catch { }
}
}