private void testSourceButton_Click(object sender, EventArgs e) { var scan = new PluginScanner(sourceFolderTxt.Text); scan.RefreshPlugins(); var table = new VersionTable <string>(); sourceTestResult.Text = "Scanning"; sourceTestResult.Refresh(); string[] all = null; var task1 = new Thread(() => { all = scan.CurrentlyAvailable.ToArray(); }); task1.Start(); while (task1.IsAlive) { Application.DoEvents(); } if (!all.Any()) { sourceTestResult.Text = "No binaries found"; return; } List <string> versions = null; var task2 = new Thread(() => { foreach (var path in all) { table.SubmitVersion(path, (typePath, versionName, major) => versionName.Replace("_", ".")); } versions = table.AllVersions().ToList(); }); task2.Start(); while (task2.IsAlive) { Application.DoEvents(); } if (!versions.Any()) { sourceFolderTxt.Text = "No versioned entry points found"; return; } sourceTestResult.Text = "Found: " + string.Join("; ", versions); }
/// <summary> /// Shut down all proxies /// </summary> public string ShutdownAll() { var errs = new StringBuilder(); foreach (var conn in _versionTable.AllVersions()) { try { conn?.HostedSite?.Dispose(); } catch (Exception ex) { errs.AppendLine(ex.ToString()); } } return(errs.ToString()); }
public static string Generate(VersionTable <SiteHost> _versionTable, TimeSpan _warmUp, string _watchFolder, bool _isScanning, Exception _lastScanError) { var body = T.g("body"); var page = T.g("html")[ T.g("head")[ T.g("title")["Wrapper proxy test page"], T.g("style")[".good {stroke: #0A0; } .bad {stroke: #A00; } path { stroke-width: 2.5px; fill: none; opacity: 0.5;}"] ], body ]; body.Add(T.g("h1")["Status"]); if (_warmUp.Ticks == 0) { body.Add(T.g("p")["The proxy is starting up. Versions will be listed below as they are ready."]); } else { body.Add(T.g("p")["Three flavours"]); body.Add(T.g("p")["The proxy is active. Initial warm up took: " + _warmUp]); } body.Add(T.g("p")["Currently loaded: " + _versionTable.VersionsAvailable()]); body.Add(T.g("p")["Watch folder: ", T.g("tt")[_watchFolder], " ", (_isScanning) ? ("Scan is in progress") : ("Scanner is idle")]); // ReSharper disable once InconsistentlySynchronizedField if (_lastScanError != null) { body.Add(T.g("p")["Last scan error: ", _lastScanError.ToString()]); } // run a health check against all versions and spit them out here... body.Add(T.g("h1")["Health check"]); var list = _versionTable.AllVersions().ToList(); foreach (var version in list) { var result = version.HostedSite.DirectCall(HealthRequest); body.Add(T.g("h3")["Version " + version.VersionName]); body.Add(T.g("p")[version.CallCount + " calls, " + (100 * version.SuccessRate).ToString("0.00") + "% successful"]); body.Add(T.g("p")[result.StatusCode + " " + result.StatusMessage]); if (result.Content != null) { body.Add(T.g("pre")[Encoding.UTF8.GetString(result.Content)]); } if (version.LastError != null) { body.Add(T.g("p")["Last proxy error: " + version.LastError]); } } body.Add(T.g("h1")["Recent log entries"]); // This double container lets us put the scroll-bar on the left. I just like it better that way :-) body.Add(T.g("div", "style", "direction:rtl;overflow-y:scroll;height:40%;")[ T.g("pre", "style", "direction: ltr;")[LocalTrace.ReadAll()] ]); // Some graphs body.Add(T.g("h1")["Recent History"], T.g("p")["Logarithmic time scale. Left is last few seconds, right is last week."]); foreach (var version in list) { body.Add(T.g("h3")["Version " + version.MajorVersion]); body.Add(T.g("div")[RenderGraph(version.SuccessHistory, version.FailureHistory)]); } return(page.ToString()); }