/// <summary> /// Loads data from the disk database (file or SQL) as in-memory data for manipulation. /// </summary> private void LoadDataFromDatabase(DataSet database, string cerberusConfigPath) { try { database.ReadXml(cerberusConfigPath); } catch (Exception e) { LoggerSAP.Critical("Failed to load Cerberus Configuration from: {0}. Exception: {1}, message: {2}", cerberusConfigPath, e.ToString(), e.Message); throw; } }
/// <summary> /// Program's entry point on a program instance. Useful for testing program behavior. /// </summary> /// <param name="args">Command line arguments</param> /// <returns>Success indicator</returns> public ProgramReturnValue RunProgram(string[] args) { Initialize(); IntroduceYourself(); var arguments = new Arguments(args); foreach (var arg in new[] { "config", "response", "output", "enginelog" }) { if (!arguments.Contains(arg)) { LoggerSAP.Error("Missing argument: {0}", arg); LoggerSAP.Log(); ShowUsage(); return(ProgramReturnValue.ErrorInvalidCommandLine); } } // verify arguments are valid // check if input files exist foreach (var arg in new[] { "config", "response" }) { if (!File.Exists(arguments[arg])) { LoggerSAP.Error("Argument \"{0}\" points to a non-existing file:\n{1}", arg, arguments[arg]); return(ProgramReturnValue.ErrorInvalidCommandLine); } } // check if output files are valid file names foreach (var arg in new[] { "output", "enginelog" }) { FileInfo fileInfo = null; string fileNameError = null; try{ fileInfo = new FileInfo(arguments[arg]); } catch (ArgumentException) { fileNameError = "Filename contains incorrect characters"; } catch (PathTooLongException) { fileNameError = "File path is too long"; } catch (NotSupportedException) { fileNameError = "Filename contains a colon (:)"; } if (!String.IsNullOrEmpty(fileNameError)) { LoggerSAP.Error("Argument \"{0}\" contains invalid file name:\n{1}", arg, fileNameError); return(ProgramReturnValue.ErrorInvalidCommandLine); } } LoggerSAP.Log("{0} is starting.", ExeID); //OSLEBot engine executes using ThreadPool - each rule is queued separately. //since OSLEBot code does block threads, many extra threads will be created by ThreadPool which may impair performance. //setting max threadpool threads will limit the number of threadpool threads ThreadPool.SetMaxThreads(Environment.ProcessorCount, Environment.ProcessorCount); var executor = new OSLEBotExecutor(); try { var result = executor.Run(arguments["response"], arguments["config"], arguments["output"], arguments["enginelog"]); if (result != OSLEBotExecutor.OSLEBotResult.Success) { throw new InvalidOperationException("OSLEBot failed."); } } catch (Exception e) { LoggerSAP.Critical("OSLEBot execution unsuccessful, because: {0}: {1}", e.ToString(), e.Message); return(ProgramReturnValue.InternalFailure); } return(ProgramReturnValue.Success); }