private void CancelAll(ITaskLauncher pooler) { if (pooler == null) { throw new ArgumentException(); } using (pooler) { pooler.CancelAll = true; pooler.Execute(); } }
private void Cancel(ITaskLauncher pooler, string taskName) { if (pooler == null) { throw new ArgumentException(); } if (string.IsNullOrEmpty(taskName)) { CancelAll(pooler); } else { using (pooler) { // cancel task pooler.TaskCancel = true; pooler.TaskName = taskName; pooler.Execute(); } } }
private string Run(ITaskLauncher launcher, RunTaskDefinition definition) { if (launcher == null || definition == null) { throw new ArgumentException("No LISpMiner instance or task defined"); } var taskName = definition.TaskName; var taskFileName = definition.TaskFileName; var dataFolder = GetDataFolder(); using (var exporter = this.CreateExporter()) { var status = "Not generated"; exporter.Output = string.Format("{0}/results_{1}_{2:yyyyMMdd-Hmmss}.xml", dataFolder, taskFileName, DateTime.Now); exporter.Template = string.Format(@"{0}\Sewebar\Template\{1}", exporter.LMExecutablesPath, definition.Template); exporter.TaskName = taskName; exporter.NoEscapeSeqUnicode = true; try { // try to export results exporter.Execute(); if (!File.Exists(exporter.Output)) { throw new LISpMinerException("Task possibly does not exist but no appLog generated"); } int numberOfRules; int hypothesesCountMax; GetInfo(exporter.Output, out status, out numberOfRules, out hypothesesCountMax); } catch (LISpMinerException ex) { // task was never imported - does not exists. Therefore we need to import at first. Log.Debug(ex); // import task using (var importer = this.CreateImporter()) { var taskPath = string.Format("{0}/task_{1}_{2:yyyyMMdd-Hmmss}.xml", dataFolder, taskFileName, DateTime.Now); importer.Input = WriteToFile(taskPath, definition.Task); importer.NoCheckPrimaryKeyUnique = true; if (definition.HasAlias) { importer.Alias = String.Format(@"{0}\Sewebar\Template\{1}", importer.LMExecutablesPath, definition.Alias); } importer.Execute(); } } switch (status) { // * Not Generated (po zadání úlohy nebo změně v zadání) case "Not generated": // * Interrupted (přerušena -- buď kvůli time-outu nebo max počtu hypotéz) case "Interrupted": // run task - generate results if (launcher.Status == ExecutableStatus.Ready) { launcher.TaskName = taskName; launcher.ShutdownDelaySec = 0; launcher.Execute(); } else { Log.Debug("Waiting for result generation"); } // run export once again to refresh results and status if (status != "Interrupted") { exporter.Execute(); } break; // * Running (běží generování) case "Running": // * Waiting (čeká na spuštění -- pro TaskPooler, zatím neimplementováno) case "Waiting": break; // * Solved (úspěšně dokončena) case "Solved": case "Finnished": default: break; } if (!File.Exists(exporter.Output)) { throw new Exception("Results generation did not succeed."); } return(exporter.Output); } }