static void Main(string[] args) { if (args.Length == 0) { PrintUsage(); return; } switch (args[0].ToLower()) { case "job": OneOffJobRunner.Run(args); break; case "cronjob": CronJobRunner.Run(args); break; case "service": ServiceRunner.Run(); break; case "help": default: PrintUsage(); break; } }
public void Run_service() { MockRepository mocks = new MockRepository(); IApplicationSettings settings = mocks.CreateMock <IApplicationSettings>(); IServiceAgentAggregator aggregator = mocks.CreateMock <IServiceAgentAggregator>(); IServiceRunner runner = new ServiceRunner(aggregator, settings); using (mocks.Record()) { aggregator.ExecuteServiceAgentCycle(); LastCall.Repeat.Times(2, int.MaxValue); Expect.Call(settings.GetServiceSleepTime()).Return(10); LastCall.Repeat.Times(2, int.MaxValue); } using (mocks.Playback()) { runner.Start(); Thread.Sleep(500); runner.Stop(); } mocks.VerifyAll(); }
public void Start() { //Console.WriteLine("I started"); ServiceRunner <AgentService> .Run(config => { var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments) => { return(new AgentService()); }); serviceConfig.OnStart((service, extraArguments) => { //Console.WriteLine("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { // Console.WriteLine("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { //Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message); }); }); config.SetName("TPOMM.MonitoringAgentService"); config.SetDisplayName("TPOMM.MonitoringAgentService"); config.SetDescription("TPOMM Monitoring Agent Service for resource checking"); }); }
public Startup() { ConfigureConnectionFactory(); ConfigurationStore.Instance = new DatabaseStore(ConnectionFactory); ConfigurationStore = ConfigurationStore.Instance; _serviceRunner = new ServiceRunner(ConnectionFactory); }
static void Main(string[] args) { ServiceRunner <MainService> .Run(config => { config.SetServiceInfo(); config.Service(serviceConfig => { serviceConfig.UseAutofac(); serviceConfig.UseServiceFactory(); serviceConfig.OnStart((service, extraParams) => { service.Start(); }); serviceConfig.OnStop(service => { service.Stop(); }); serviceConfig.OnError(Console.WriteLine); }); }); }
public static void Main(string[] args) { ServiceRunner <ExampleService> .Run(config => { const string svcName = nameof(ExampleService); config.HostConfiguration.Name = svcName; var trace = new TraceSource(typeof(ExampleService).FullName, SourceLevels.All); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new ExampleService(controller, trace, config.HostConfiguration.Action == Enums.ActionEnum.RunInteractive)); }); serviceConfig.OnStart((service, extraParams) => { trace.TraceEvent(TraceEventType.Information, 1, $"Service {svcName} started"); service.Start(); }); serviceConfig.OnStop(service => { trace.TraceEvent(TraceEventType.Information, 2, $"Service {svcName} stopped"); service.Stop(); }); serviceConfig.OnError(e => { trace.TraceEvent(TraceEventType.Error, 3, $"Service {svcName} errored with exception:\n{e.ToString()}"); }); }); }); }
public static int Main(string[] args) { return(ServiceRunner.Run(() => { CreateWebHostBuilder(args).Build().Run(); })); }
static void Main(string[] args) { ServiceRunner <MainService> .Run(config => { config.SetServiceInfo(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => new MainService()); serviceConfig.OnStart((service, extraParams) => { service.Start(); }); serviceConfig.OnStop(service => { service.Stop(); }); serviceConfig.OnError(Console.WriteLine); serviceConfig.UseAutofac(); serviceConfig.InitJob(); }); }); }
static void Main(string[] args) { if (!Console.IsOutputRedirected) { Console.Title = YandexMusicBotService.Title; } ServiceRunner <YandexMusicBotService> .Run(config => { config.SetName(YandexMusicBotService.Name); config.SetDisplayName(YandexMusicBotService.Title); config.SetDescription(YandexMusicBotService.Description); var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new YandexMusicBotService()); }); serviceConfig.OnStart((service, extraParams) => { service.Start(); }); serviceConfig.OnStop(service => { service.Stop(); }); serviceConfig.OnError(e => { Log.Error($"Service {name} errored with exception: {e.Message}\n{e.StackTrace}"); }); }); }); }
private ServiceRunner CreateServiceRuner(ServicePackage package) { var runer = new ServiceRunner(package); runer.Load(); return(runer); }
/// <summary> /// The main entry point for the application. /// </summary> public static void Main() { Log.Logger = new ShopLogConfiguration().CreateLogger(); ServiceRunner <ShopNode> .Run(config => { var name = config.GetDefaultName(); config.SetName("Shop node"); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, c) => ShopNode.CreateDefault()); serviceConfig.OnStart((service, extraArguments) => { Console.WriteLine("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { Console.WriteLine("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message); }); }); }); Console.WriteLine("Press any key and enter to exit"); Console.ReadLine(); }
public static void Main(string[] args) { var fileName = Path.Combine(System.AppContext.BaseDirectory, "log.txt"); ServiceRunner <ExampleService> .Run(config => { var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new ExampleService(controller)); }); serviceConfig.OnStart((service, extraParams) => { Console.WriteLine("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { Console.WriteLine("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { File.AppendAllText(fileName, $"Exception: {e.ToString()}\n"); Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message); }); }); }); }
public void Start() { ServiceRunner <IMicroService> .Run(config => { config.SetName(_config.Name); config.SetDescription(_config.Description); config.SetDisplayName(_config.DisplayName); config.Service(service => { service.ServiceFactory((args, controller) => _services.GetRequiredService <IMicroService>()); service.OnStart((svc, args) => { _log.LogInformation("Starting service"); svc.Start(); }); service.OnStop(svc => { _log.LogInformation("Stopping service"); svc.Stop(); }); service.OnError(exception => { _log.LogCritical(exception, "Service failed"); }); }); }); }
static void Main(string[] args) { var serviceProvider = DependenciesRegistry.Configure(); var powerShellWorker = ActivatorUtilities.CreateInstance <PowerShellWorker>(serviceProvider); ServiceRunner <Service> .Run(config => SetServiceConfigurations(config, powerShellWorker)); }
public void StartService() { var startInfo = ServiceRunner.StartService <ITestService>("TestService", new TestService()); _service = startInfo.Item1; _client = startInfo.Item2; }
public void Correctly_handles_when_service_agent_aggregator_throws_exception() { ApplicationException exception = new ApplicationException(); MockRepository mocks = new MockRepository(); IApplicationSettings settings = mocks.CreateMock <IApplicationSettings>(); IServiceAgentAggregator aggregator = mocks.CreateMock <IServiceAgentAggregator>(); IServiceRunner runner = new ServiceRunner(aggregator, settings); using (mocks.Record()) { aggregator.ExecuteServiceAgentCycle(); LastCall.Throw(exception); } using (mocks.Playback()) { runner.Start(); Thread.Sleep(500); runner.Stop(); } mocks.VerifyAll(); }
static void Main(string[] args) { DI.SetupServices(); ServiceRunner <TheConsumerService> .Run(config => { var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new TheConsumerService(controller)); }); serviceConfig.OnStart((service, extraParams) => { Console.WriteLine("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { Console.WriteLine("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message); }); }); }); Console.WriteLine("Hello World!"); }
private static void Main() { var container = RegisterDependencies(); var serviceRunner = new ServiceRunner(); serviceRunner.Run(() => container.Resolve <ChatService>()); }
public void When_the_cycle_completes_we_should_get_an_event() { _startFired = DateTime.MinValue; _completedFired = DateTime.MinValue; MockRepository mocks = new MockRepository(); IServiceAgentAggregator aggregator = mocks.CreateMock <IServiceAgentAggregator>(); ServiceRunner runner = new ServiceRunner(aggregator, null); using (mocks.Record()) { aggregator.ExecuteServiceAgentCycle(); LastCall.On(aggregator).Do(new Action(delegate { Thread.Sleep(50); })); } using (mocks.Playback()) { runner.CycleStarted += runner_CycleStarted; runner.CycleCompleted += runner_CycleCompleted; runner.RunOneCycle(); Assert.IsTrue(_completedFired > _startFired); } mocks.VerifyAll(); }
public static void Main(string[] args) { ServiceRunner <CPLPredictionGameService> .Run(config => { string fileName = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "log.txt"); config.SetDisplayName(PredictionGameServiceConstant.ServiceName); config.SetName(PredictionGameServiceConstant.ServiceName); config.SetDescription(PredictionGameServiceConstant.ServiceDescription); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new CPLPredictionGameService()); }); serviceConfig.OnStart((service, extraParams) => { service.Start(); }); serviceConfig.OnStop(service => { service.Stop(); }); serviceConfig.OnError(e => { Utils.FileAppendThreadSafe(fileName, string.Format("Exception: {0}{1}{2}", e.StackTrace.ToString(), DateTime.Now, Environment.NewLine)); }); }); }); }
public static void Main(string[] args) { ServiceRunner <ExampleServiceTimer> .Run(config => { var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments) => { return(new ExampleServiceTimer()); }); serviceConfig.OnStart((service, extraParams) => { Console.WriteLine("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { Console.WriteLine("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { Console.WriteLine("Service {0} errored with exception : {1}", name, e.Message); }); }); }); }
static void Main(string[] args) { ServiceRunner <PersistenceService> .Run(config => { config.SetName(PersistenceService.Name); config.SetDisplayName(PersistenceService.Title); config.SetDescription(PersistenceService.Description); var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, service) => { return(new PersistenceService()); }); serviceConfig.OnStart((service, extraParams) => { service.Start(); }); serviceConfig.OnStop(service => { service.Stop(); }); serviceConfig.OnError(e => { Log.Error($"Service {name} errored with exception : {e.Message}"); }); }); }); }
public static void Main(string[] args) { #if !DEBUG var configuration = new ConfigurationBuilder() .SetBasePath(System.AppContext.BaseDirectory) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); #else var configuration = new ConfigurationBuilder() .SetBasePath(System.AppContext.BaseDirectory) .AddJsonFile("appsettings.Development.json", optional: false, reloadOnChange: true) .Build(); #endif var svcProvider = new ServiceCollection() .AddLogging(builder => { builder .SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace) .AddProvider(new LogFileProvider()); // Implemented vanilla LogFile provider but is easily swapped for Nlog or SeriLog (et al.) providers }) .AddOptions() .AddLogging(o => o.AddConsole()) .BuildServiceProvider(); var _logger = svcProvider.GetRequiredService <ILoggerFactory>().CreateLogger <Program>(); ServiceRunner <ExampleService> .Run(config => { var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new ExampleService(controller, svcProvider.GetRequiredService <ILoggerFactory>().CreateLogger <ExampleService>())); }); serviceConfig.OnStart((service, extraParams) => { _logger.LogTrace("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { _logger.LogTrace("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnError(e => { _logger.LogError(e, string.Format("Service {0} errored with exception", name)); }); }); }); }
public void Run() { LoadConfiguration(); InitializeBroker(); InitializeContainer(); using (var scope = _container.BeginLifetimeScope()) { ServiceRunner <TService> .Run(config => { config.SetName(_serviceFullName); var name = config.GetDefaultName(); config.Service(serviceConfig => { var myService = scope.Resolve <TService>(); myService.Container = _container; serviceConfig.ServiceFactory((arguments, controller) => myService); serviceConfig.OnStart((service, extraArguments) => { Console.WriteLine($"Service {name} started"); service.Start(); }); serviceConfig.OnStop(async service => { Console.WriteLine($"Service {name} stopped"); Shutdown(); service.Stop(); }); serviceConfig.OnInstall(service => { Console.WriteLine($"Service {name} installed"); }); serviceConfig.OnUnInstall(service => { Console.WriteLine($"Service {name} uninstalled"); }); serviceConfig.OnPause(service => { Console.WriteLine($"Service {name} paused"); }); serviceConfig.OnContinue(service => { Console.WriteLine($"Service {name} continued"); }); serviceConfig.OnError(e => { Console.WriteLine($"Service {name} errored with exception : {e.Message}"); }); }); }); } }
/// <summary> /// Analysis Service Launch Method /// </summary> public static void Main() { var logger = new LoggerFactory() .AddNLog() .CreateLogger <Program>(); var configBuilder = new ConfigurationBuilder(); var baseDirectory = AppContext.BaseDirectory; var configuration = configBuilder .SetBasePath(baseDirectory) .AddJsonFile("appsettings.Shared.json", true) .Build(); var servicesSettings = configuration .GetSection(nameof(ServicesSettings)) .Validate <ServicesSettings>(logger) .Get <ServicesSettings>(); var statUnitAnalysisRules = configuration .GetSection(nameof(StatUnitAnalysisRules)) .Get <StatUnitAnalysisRules>(); var dbMandatoryFields = configuration .GetSection(nameof(DbMandatoryFields)) .Get <DbMandatoryFields>(); var validationSettings = configuration .GetSection(nameof(ValidationSettings)) .Validate <ISettings>(logger) .Get <ValidationSettings>(); var dbContextHelper = new DbContextHelper(); var ctx = dbContextHelper.CreateDbContext(new string[] { }); const string serviceName = "nscreg.AnalysisService"; ServiceRunner <JobService> .Run(config => { config.SetName(serviceName); config.SetDisplayName(serviceName); config.SetDescription(serviceName); config.Service(svcConfig => { svcConfig.ServiceFactory((extraArguments, controller) => new JobService( logger, new AnalysisJob( ctx, statUnitAnalysisRules, dbMandatoryFields, servicesSettings.StatUnitAnalysisServiceDequeueInterval, validationSettings, logger ))); svcConfig.OnStart((svc, extraArguments) => svc.Start()); svcConfig.OnStop(svc => svc.Stop()); svcConfig.OnError(e => { logger.LogError("Service errored with exception : {0}", e.Message); }); }); }); }
static int Main(string[] args) { var svcRunner = new ServiceRunner(); var returnCode = svcRunner.Run(new DummyStartup(), args); return(returnCode); }
public static void Main(string[] args) { Configure(); var serviceProvider = Services.BuildServiceProvider(); ServiceRunner sr = serviceProvider.GetService <ServiceRunner>(); Console.WriteLine("Gotta go fast!"); sr.StartMonitoringService(); }
protected override async Task <int> Run(CommandLineApplication command) { var profilePath = GetOption(DeployWithProfileDirectoryOptionNames.Directory).Value(); System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "UsingProfileDirAtPath") + profilePath); var option = GetOption(DeployWithProfileDirectoryOptionNames.Monitor); bool run = option.HasValue(); int.TryParse(option.Value(), out int waitTime); try { if (!Directory.Exists(profilePath)) { System.Console.WriteLine(languageProvider.GetString(LanguageSection.UiStrings, "PathDoesntExist")); return(-1); } if (run) { ServiceRunner <DeployWithProfileDirectory> .Run(config => { var name = config.GetDefaultName(); config.SetName("OctoPlus.Service"); config.SetDisplayName("OctoPlus.Service"); config.SetDescription(""); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguements, controller) => { return(this); }); serviceConfig.OnStart((service, extraParams) => { System.Console.WriteLine("Service {0} started", name); service.Start(); RunProfiles(profilePath, run, waitTime).Start(); }); }); }); } else { await RunProfiles(profilePath, run, waitTime); } } catch (Exception e) { System.Console.WriteLine(String.Format(languageProvider.GetString(LanguageSection.UiStrings, "UnexpectedError"), e.Message)); } return(0); }
public static void Main() { log4net.Config.XmlConfigurator.Configure(); ServiceRunner.Run <NotificationServiceControl>( ConfigureService, cfg => { cfg.SetServiceName("AccessControl.Service.Notifications"); cfg.SetDescription("Processes access control notifications"); }); }
public static void Main(string[] args) { #if !DEBUG Configuration = new ConfigurationBuilder() .SetBasePath(PlatformServices.Default.Application.ApplicationBasePath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); #else Configuration = new ConfigurationBuilder() .SetBasePath(PlatformServices.Default.Application.ApplicationBasePath) .AddJsonFile("appsettings.Development.json", optional: false, reloadOnChange: true) .Build(); #endif ConfigureServices(); ServiceRunner <ExampleService> .Run(config => { var vuConnector = serviceProvider.GetRequiredService <IVirtualUserConnector>(); var kxClient = serviceProvider.GetRequiredService <KxClient>(); var repository = serviceProvider.GetRequiredService <IBaseMongoRepository>(); var documentTypeConfig = serviceProvider.GetRequiredService <IOptions <DocumentTypeConfiguration> >(); var scheduler = serviceProvider.GetRequiredService <IOptions <ProcessDocumentConfiguration> >();//ServiceScheduler>(); var name = config.GetDefaultName(); config.Service(serviceConfig => { serviceConfig.ServiceFactory((extraArguments, controller) => { return(new ExampleService(log, kxClient, serviceProvider.GetRequiredService <IFolderWatcher>(), documentTypeConfig, vuConnector, repository, scheduler)); }); serviceConfig.OnStart((service, extraParams) => { log.Information("Service {0} started", name); service.Start(); }); serviceConfig.OnStop(service => { log.Information("Service {0} stopped", name); service.Stop(); }); serviceConfig.OnShutdown(service => { log.Information("Service {0} shutdown", name); }); serviceConfig.OnError(e => { log.Error("Service {0} errored with exception : {1}", name, e.Message); }); }); }); }
public static int Main(string[] args) { var sr = new ServiceRunner<CorposService>(); return sr.main(args); }