public static void Start(string[] args) { log4net.GlobalContext.Properties["LogName"] = "Console"; XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config")); var engine = RIFFSection.GetDefaultEngine(); var config = engine.BuildEngineConfiguration(); var environment = RFEnvironments.StartConsole(engine.Environment, config, engine.Database, new string[] { engine.Assembly }); var context = environment.Start(); var engineConsole = config.Console; if (engineConsole != null) { engineConsole.Initialize(context, config, engine.Database); } var executor = new RFConsoleExecutor(config, context, engine, engineConsole); Console.WriteLine(">>> Loaded engine {0} from {1} in environment {2}", engine?.EngineName, engine?.Assembly, engine.Environment); if (args.Length > 0) { // batch mode executor.ExecuteCommand(String.Join(" ", args)); } else { // interactive mode do { try { System.Console.Write("> "); var input = ReadLine(); executor.ExecuteCommand(input); } catch (Exception ex) { Console.WriteLine("EXCEPTION: {0}", ex.Message); } } while (!executor._isExiting); } environment.Stop(); }
public void StartEnvironment() { try { Console.WriteLine("Welcome to RIFF {0}", RFCore.sVersion); // currently only a single engine is supported var engine = RIFFSection.GetDefaultEngine(); var engineConfig = engine.BuildEngineConfiguration(); try { rfEventLog.WriteEntry(String.Format("Starting engine {0} in environment {1} from {2} (RFCore {3})", engine.EngineName, engine.Environment, engine.Assembly, RFCore.sVersion), EventLogEntryType.Information); } catch (SecurityException) { RFStatic.Log.Error(this, "EventLog source has not been created. Please run \"RIFF.Service.exe /install\" as Administrator to create."); return; } if (_args != null && _args.Length > 0) { _environment = RFEnvironments.StartConsole(engine.Environment, engineConfig, engine.Database, new string[] { engine.Assembly }); _context = _environment.Start(); if (_args[0] == "command") { // run console command var engineConsole = engineConfig.Console; if (engineConsole != null) { engineConsole.Initialize(_context, engineConfig, engine.Database); } var executor = new RFConsoleExecutor(engineConfig, _context, engine, engineConsole); executor.ExecuteCommand(String.Join(" ", _args.Skip(1))); } else { // run named service var param = String.Join(" ", _args); var tokens = new Interfaces.Formats.CSV.CSVParser(param, ' ').Where(t => !string.IsNullOrWhiteSpace(t)).ToArray(); var serviceName = tokens[0]; var serviceParam = tokens.Length > 1 ? tokens[1] : null; RFStatic.Log.Info(this, $"Starting service: {serviceName}" + (serviceParam != null ? $"with param: {serviceParam}" : string.Empty)); _context.RaiseEvent(this, new RFServiceEvent { ServiceName = serviceName, ServiceCommand = "start", ServiceParams = serviceParam }); } } else { if (RFSettings.GetAppSetting("UseMSMQ", true)) { CleanUpMSMQ(Environment.MachineName, engine.Environment); } // WCF service _environment = RFEnvironments.StartLocal(engine.Environment, engineConfig, engine.Database, new string[] { engine.Assembly }); _context = _environment.Start(); _context.RaiseEvent(this, new RFServiceEvent { ServiceName = RFSchedulerService.SERVICE_NAME, ServiceCommand = "start", ServiceParams = null }); var wcfService = new RFService(_context, engineConfig, engine.Database); var uriSetting = RFSettings.GetAppSetting("RFServiceUri"); if (uriSetting.NotBlank()) { _serviceHost = new ServiceHost(wcfService, new Uri(uriSetting)); } else { _serviceHost = new ServiceHost(wcfService); } _serviceHost.Open(); } } catch (Exception ex) { rfEventLog.WriteEntry("OnStart Error: " + ex.Message, EventLogEntryType.Error); RFStatic.Log.Exception(this, ex, "Error initializing RFService."); throw; } }