private TaskResponse RunTask(TaskDefinition definition) { var exporter = this.LISpMiner.Exporter; var importer = this.LISpMiner.Importer; try { var request = new TaskRequest(this); var response = new TaskResponse(); if (this.LISpMiner != null && request.Task != null) { var status = "Not generated"; var numberOfRules = 0; var hypothesesCountMax = Int32.MaxValue; exporter.Output = String.Format("{0}/results_{1}_{2:yyyyMMdd-Hmmss}.xml", request.DataFolder, request.TaskFileName, DateTime.Now); exporter.Template = String.Format(@"{0}\Sewebar\Template\{1}", exporter.LMExecutablesPath, request.GetTemplate(definition.DefaultTemplate)); exporter.TaskName = request.TaskName; exporter.NoEscapeSeqUnicode = true; try { // try to export results exporter.Execute(); if (!System.IO.File.Exists(exporter.Output)) { throw new LISpMinerException("Task possibly does not exist but no appLog generated"); } this.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 importer.Input = request.TaskPath; importer.NoCheckPrimaryKeyUnique = true; if (!string.IsNullOrEmpty(request.Alias)) { importer.Alias = String.Format(@"{0}\Sewebar\Template\{1}", importer.LMExecutablesPath, request.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 (definition.Launcher.Status == ExecutableStatus.Ready) { var taskLauncher = definition.Launcher; taskLauncher.TaskName = request.TaskName; taskLauncher.ShutdownDelaySec = 0; taskLauncher.Execute(); } else { Log.Debug("Waiting for result generation"); } // run export once again to refresh results and status if (status != "Interrupted" && exporter.Status == ExecutableStatus.Ready) { exporter.Execute(); } break; // * Running (běží generování) case "Running": // * Waiting (čeká na spuštění -- pro TaskPooler, zatím neimplementováno) case "Waiting": definition.Launcher.ShutdownDelaySec = 10; break; // * Solved (úspěšně dokončena) case "Solved": case "Finnished": default: break; } response.OutputFilePath = exporter.Output; if (!System.IO.File.Exists(response.OutputFilePath)) { throw new Exception("Results generation did not succeed."); } } else { throw new Exception("No LISpMiner instance or task defined"); } return response; } finally { // clean up exporter.Output = String.Empty; exporter.Template = String.Empty; exporter.TaskName = String.Empty; importer.Input = String.Empty; importer.Alias = String.Empty; importer.NoCheckPrimaryKeyUnique = false; } }
private TaskResponse ExportTask(string taskName) { LMSwbExporter exporter = this.LISpMiner.Exporter; try { var request = new TaskInfoRequest(this); var response = new TaskResponse(); request.TaskName = taskName; if (this.LISpMiner != null && request.TaskName != null) { exporter.Output = String.Format("{0}/results_{1}_{2:yyyyMMdd-Hmmss}.xml", request.DataFolder, request.TaskFileName, DateTime.Now); exporter.Template = String.Format(@"{0}\Sewebar\Template\{1}", exporter.LMExecutablesPath, request.GetTemplate(DefaultTemplate)); exporter.TaskName = request.TaskName; exporter.NoEscapeSeqUnicode = true; // try to export results exporter.Execute(); if (!System.IO.File.Exists(exporter.Output)) { throw new LISpMinerException("Results generation did not succeed. Task possibly does not exist but no appLog generated."); } response.OutputFilePath = exporter.Output; } else { throw new Exception("No LISpMiner instance or task defined."); } return response; } finally { // clean up exporter.Output = String.Empty; exporter.Template = String.Empty; exporter.TaskName = String.Empty; } }