diff options
| author | RogueAI42 <[email protected]> | 2017-06-11 17:34:38 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-06-11 17:38:53 +1000 |
| commit | 107a98686a105468b5f200ebcbd27343c1210ce4 (patch) | |
| tree | f6b8403368ddf0b4be2569c0ac8c237635e7b764 /ShiftOS.WinForms/Applications/Shiftnet.cs | |
| parent | c3deaa23fffb7011efb2b5b0f7fc3e754d21f600 (diff) | |
| download | shiftos_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/Applications/Shiftnet.cs')
| -rw-r--r-- | ShiftOS.WinForms/Applications/Shiftnet.cs | 113 |
1 files changed, 47 insertions, 66 deletions
diff --git a/ShiftOS.WinForms/Applications/Shiftnet.cs b/ShiftOS.WinForms/Applications/Shiftnet.cs index 6ccdb19..136f680 100644 --- a/ShiftOS.WinForms/Applications/Shiftnet.cs +++ b/ShiftOS.WinForms/Applications/Shiftnet.cs @@ -150,79 +150,60 @@ namespace ShiftOS.WinForms.Applications { txturl.Text = url; - foreach(var exe in Directory.GetFiles(Environment.CurrentDirectory)) + try { - if(exe.EndsWith(".exe") || exe.EndsWith(".dll")) + foreach (var type in Array.FindAll(ReflectMan.Types, t => t.GetInterfaces().Contains(typeof(IShiftnetSite)) && t.BaseType == typeof(UserControl) && Shiftorium.UpgradeAttributesUnlocked(t))) { - try + var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute && (x as ShiftnetSiteAttribute).Url == url) as ShiftnetSiteAttribute; + if (attribute != null) { - var asm = Assembly.LoadFile(exe); - foreach (var type in asm.GetTypes()) - { - if (type.GetInterfaces().Contains(typeof(IShiftnetSite))) + var obj = (IShiftnetSite)Activator.CreateInstance(type, null); + obj.GoToUrl += (u) => { - if (type.BaseType == typeof(UserControl)) - { - var attribute = type.GetCustomAttributes(false).FirstOrDefault(x => x is ShiftnetSiteAttribute) as ShiftnetSiteAttribute; - if (attribute != null) - { - if (attribute.Url == url) - { - if (Shiftorium.UpgradeAttributesUnlocked(type)) - { - var obj = (IShiftnetSite)Activator.CreateInstance(type, null); - obj.GoToUrl += (u) => - { - History.Push(CurrentUrl); - NavigateToUrl(u); - }; - obj.GoBack += () => - { - string u = History.Pop(); - Future.Push(u); - NavigateToUrl(u); - }; - CurrentPage = obj; - this.pnlcanvas.Controls.Clear(); - this.pnlcanvas.Controls.Add((UserControl)obj); - ((UserControl)obj).Show(); - ((UserControl)obj).Dock = DockStyle.Fill; - obj.OnUpgrade(); - obj.OnSkinLoad(); - obj.Setup(); - AppearanceManager.SetWindowTitle(this, attribute.Name + " - Shiftnet"); - return; - } - } - } - } - } - } - } - catch (Exception ex) - { - pnlcanvas.Controls.Clear(); - var tlbl = new Label(); - tlbl.Text = "Server error in \"" + url + "\" application."; - tlbl.Tag = "header1"; - tlbl.AutoSize = true; - tlbl.Location = new Point(10, 10); - tlbl.Dock = DockStyle.Top; - pnlcanvas.Controls.Add(tlbl); - tlbl.Show(); - - var crash = new Label(); - crash.Dock = DockStyle.Fill; - crash.AutoSize = false; - crash.Text = ex.ToString(); - pnlcanvas.Controls.Add(crash); - crash.Show(); - crash.BringToFront(); - ControlManager.SetupControls(pnlcanvas); - return; + History.Push(CurrentUrl); + NavigateToUrl(u); + }; + obj.GoBack += () => + { + string u = History.Pop(); + Future.Push(u); + NavigateToUrl(u); + }; + CurrentPage = obj; + this.pnlcanvas.Controls.Clear(); + this.pnlcanvas.Controls.Add((UserControl)obj); + ((UserControl)obj).Show(); + ((UserControl)obj).Dock = DockStyle.Fill; + obj.OnUpgrade(); + obj.OnSkinLoad(); + obj.Setup(); + AppearanceManager.SetWindowTitle(this, attribute.Name + " - Shiftnet"); + return; } } } + catch (Exception ex) + { + pnlcanvas.Controls.Clear(); + var tlbl = new Label(); + tlbl.Text = "Server error in \"" + url + "\" application."; + tlbl.Tag = "header1"; + tlbl.AutoSize = true; + tlbl.Location = new Point(10, 10); + tlbl.Dock = DockStyle.Top; + pnlcanvas.Controls.Add(tlbl); + tlbl.Show(); + + var crash = new Label(); + crash.Dock = DockStyle.Fill; + crash.AutoSize = false; + crash.Text = ex.ToString(); + pnlcanvas.Controls.Add(crash); + crash.Show(); + crash.BringToFront(); + ControlManager.SetupControls(pnlcanvas); + return; + } pnlcanvas.Controls.Clear(); var lbl = new Label(); lbl.Text = "Page not found!"; |
