public static void InitializeEngine() { var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); var clientControllerAssembly = RFSettings.GetAppSetting("ControllersAssembly", null); if (!string.IsNullOrWhiteSpace(clientControllerAssembly)) { builder.RegisterControllers(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetModules().First().Name == clientControllerAssembly)); builder.RegisterApiControllers(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetModules().First().Name == clientControllerAssembly)); } var engine = RIFFSection.GetDefaultEngine(); var config = engine.BuildEngineConfiguration(); EngineConfig = engine; var enableWebProcessing = RFSettings.GetAppSetting("EnableWebProcessing", false); var context = enableWebProcessing ? RFEnvironments.StartConsole(engine.Environment, config, engine.Database, new string[] { "RIFF.Core", "RIFF.Framework", engine.Assembly }).Start() : RFEnvironments.StartWeb(engine.Environment, engine.Database, new string[] { "RIFF.Core", "RIFF.Framework", engine.Assembly }); UserRole = context.UserRole; // this context is for read-only operations builder.RegisterInstance(context).As <IRFProcessingContext>(); builder.RegisterInstance(context).As <IRFSystemContext>(); builder.RegisterInstance(config).As <RFEngineDefinition>(); var engineConsole = config.Console; if (config.Console == null) { throw new Exception("Error initializing engine. Check log for details."); } engineConsole.Initialize(context, config, engine.Database); ConsoleExecutor = new RFConsoleExecutor(config, context, engine, engineConsole); Context = context; var httpConfig = GlobalConfiguration.Configuration; builder.RegisterWebApiFilterProvider(httpConfig); Container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(Container)); httpConfig.DependencyResolver = new AutofacWebApiDependencyResolver(Container); }
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 FrameworkFixture() { Log("Initializing unit tests."); log4net.GlobalContext.Properties["LogName"] = "Test"; XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo("log4net.config")); Engine = RIFFSection.GetDefaultEngine(); Config = Engine.BuildEngineConfiguration(); ConnString = Engine.Database; KeyDomain = Config.KeyDomain; SeedDatabase(); Env = RFEnvironments.StartLocal("TEST", Config, Engine.Database, new List <string> { "RIFF.Tests.dll" }); Context = Env.Start(); }
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; } }