internal async Task PollTrainerCheckpoint(SynchronizedCollection <ExceptionTelemetry> exceptions, Predicate <OnlineTrainerBlobs> predicate) { // wait for files to show up for (int i = 0; i < 30; i++) { await Task.Delay(TimeSpan.FromSeconds(1)); if (exceptions.Count > 0) { Assert.Fail(string.Join(";", exceptions.Select(e => e.Message))); } // mwt-models if (!this.ModelContainer.Exists()) { continue; } // mwt-models/current if (!this.CurrentModel.Exists()) { continue; } // onlinetrainer if (!this.TrainerContainer.Exists()) { continue; } // onlinetrainer/20161128/002828 var blobs = this.TrainerContainer.ListBlobs(useFlatBlobListing: true); this.ModelBlobs = blobs.Where(b => b.Uri.ToString().EndsWith("model")) .OrderBy(uri => DateTime.ParseExact(uri.Parent.Prefix, "yyyyMMdd/HHmmss/", CultureInfo.InvariantCulture)) .ToList(); this.ModelTrackbackBlobs = blobs.Where(b => b.Uri.ToString().EndsWith("model.trackback")).ToList(); this.StateJsonBlobs = blobs.Where(b => !string.IsNullOrEmpty(b.Parent.Prefix) && b.Uri.ToString().EndsWith("state.json")).ToList(); if (predicate(this)) { return; } } Assert.Fail("Trainer didn't produce checkpoints"); }
internal async Task PollTrainerCheckpoint(SynchronizedCollection <ExceptionTelemetry> exceptions) { // wait for fiels to show up for (int i = 0; i < 30; i++) { await Task.Delay(TimeSpan.FromSeconds(1)); if (exceptions.Count > 0) { Assert.Fail(string.Join(";", exceptions.Select(e => e.Message))); } // mwt-models if (!this.ModelContainer.Exists()) { continue; } // mwt-models/current if (!this.CurrentModel.Exists()) { continue; } // onlinetrainer if (!this.TrainerContainer.Exists()) { continue; } // onlinetrainer/20161128/002828 var blobs = this.TrainerContainer.ListBlobs(useFlatBlobListing: true); this.ModelBlob = blobs.FirstOrDefault(b => b.Uri.ToString().EndsWith("model")); this.ModelTrackbackBlob = blobs.FirstOrDefault(b => b.Uri.ToString().EndsWith("model.trackback")); this.StateJsonBlob = blobs.FirstOrDefault(b => b.Uri.ToString().EndsWith("state.json")); if (this.ModelBlob == null || this.ModelTrackbackBlob == null || this.StateJsonBlob == null) { continue; } return; } Assert.Fail("Trainer didn't produce checkpoints"); }
void AssertNoExceptionsThroughAppInsights() { Assert.AreEqual(0, exceptions.Count, string.Join("\n", exceptions.Select(e => e.Exception.Message + " " + e.Message))); }
private static void LoadPluginsFromDisk() { #pragma warning disable S3885 // "Assembly.Load" should be used Assembly.LoadFile(Path.Combine(Application.StartupPath, "KeraLua.dll")); Assembly.LoadFile(Path.Combine(Application.StartupPath, "NLua.dll")); Assembly.LoadFile(Path.Combine(Application.StartupPath, "ICSharpCode.TextEditor.dll")); var directories = Directory.GetDirectories(Settings2.Instance.PluginSourceFolder); foreach (string directory in directories) { try { log.Info($"Processing directory <{directory}>"); var md5ForFolder = Utils.CreateMd5ForFolder(directory); var dllPath = $"{AppFolders.PluginsBinariesDir}\\{md5ForFolder}.dll"; Assembly dll; if (!File.Exists(dllPath)) { dll = CompilePlugin(directory); log.Info($"Plug-in from directory <{directory}> is compiled"); } else { dll = Assembly.LoadFile(dllPath); log.Info($"Plug-in from directory <{directory}> with hash {md5ForFolder} is already compiled"); } if (dll != null) { var type = dll.GetTypes().FirstOrDefault(k => k.IsClass && typeof(IPlugin3).IsAssignableFrom(k)); if (type != default(Type)) { IPlugin3 temp = null; if (typeof(Control).IsAssignableFrom(type)) { log.Info($"Plug-in from directory <{directory}> creates control(s) in it's constructor!"); MainWindow.Instance.Invoke((MethodInvoker) delegate { temp = (IPlugin3)Activator.CreateInstance(type); }); } else { temp = (IPlugin3)Activator.CreateInstance(type); } if (_pluginContainers.Select(l => l.Plugin).All(l => l.Name != temp.Name)) { if (!string.IsNullOrWhiteSpace(temp.Name)) { _pluginContainers.Add(new PluginContainer(temp)); log.Info($"Plug-in loaded: {temp.Name} {temp.Version}"); PluginLoaded?.Invoke(temp); } else { throw new MissingFieldException("<IPlugin2.Name> is empty"); } } else { log.Info($"Can't load plug-in [{temp.Name}]: already loaded"); } } else { throw new BadImageFormatException("Can't find IPlugin2 interface in plug-in image!"); } } else { throw new BadImageFormatException("Plug-in image is null!"); } } catch (Exception ex) { log.Info($"Can't load plug-in <{directory}>: {ex.Message}"); Notify.TrayPopup("[PluginManager] Plug-in error", $"Plug-in from folder '{directory}' cannot be loaded.\r\nClick here to open the website with updated versions of plug-ins", NotifyUserType.Warn, true, null, 10, (sender, args) => Process.Start(Globals.PluginsURL)); } } #pragma warning restore S3885 // "Assembly.Load" should be used }