Example #1
0
        static void Main()
        {
            HostFactory.Run(x =>
            {
                x.SetServiceName("RSB.Modules.MailSender");
                x.SetDisplayName("RSB.Modules.MailSender");
                x.SetDescription("This is mail sender service communicating by RSB.");

                x.StartAutomatically();

                x.UseNLog();

                x.Service <MailSenderService>(service =>
                {
                    service.ConstructUsing(srv => InitializeMailSenderService());

                    service.WhenStarted(srv => srv.Start());
                    service.WhenStopped(srv => srv.Stop());
                });
            });
        }
        static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.File("devopslog.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();

            HostFactory.Run(hostConfig =>
            {
                hostConfig.Service <SafeguardDevOpsService>(service =>
                {
                    service.ConstructUsing(c => new SafeguardDevOpsService());
                    service.WhenStarted(s => s.Start());
                    service.WhenStopped(s => s.Stop());
                });
                hostConfig.UseSerilog();
                hostConfig.StartAutomaticallyDelayed();
                hostConfig.SetDisplayName("SafeguardDevOpsService");
                hostConfig.SetServiceName("SafeguardDevOpsService");
                hostConfig.SetDescription("Safeguard for Privileged Passwords DevOps integration service.");
            });
        }
Example #3
0
        private static int Main(string[] args)
        {
            return((int)HostFactory.Run(x =>
            {
                var container = new ContainerBuilder().GetContainer(new[] { typeof(CategoryService) });

                x.UseSerilog();
                x.UseAutofacContainer(container);
                x.Service(() => container.Resolve <CategoryService>());

                x.UseAssemblyInfoForServiceInfo();
                x.RunAsLocalSystem();
                x.StartAutomatically();

                x.EnableServiceRecovery(r => r.RestartService(1));

                x.SetServiceName("Category");
                x.SetDisplayName("Category Service");
                x.SetDescription("Magazine Website - Category Service.");
            }));
        }
Example #4
0
        static void Main(string[] args)
        {
            FileInfo fi = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "Web.config");

            XmlConfigurator.ConfigureAndWatch(fi);
            LogHelper.SetConfig(fi);
            HostFactory.Run(config =>
            {
                config.Service <QuartzHelper>(setting =>
                {
                    setting.ConstructUsing(name => new QuartzHelper());
                    setting.WhenStarted(tc => tc.start());
                    setting.WhenStopped(tc => tc.StopSchedule());
                });
                config.RunAsLocalSystem();

                config.SetDescription("Quartz初使用");
                config.SetDisplayName("QuartzService");
                config.SetServiceName("QuartzService");
            });
        }
Example #5
0
        static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <MyHostingService>(s =>
                {
                    s.ConstructUsing(name => new MyHostingService());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetServiceName("MyHostRestApi");
                x.SetDisplayName("My testing REST API host");
                x.SetDescription("bla bla");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Example #6
0
        internal static void Configure()
        {
            var repository = LogManager.GetRepository(Assembly.GetCallingAssembly());
            var file       = new FileInfo(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath);

            XmlConfigurator.Configure(repository, file);
            HostFactory.Run(configure =>
            {
                configure.Service <CruzAzulService>(service =>
                {
                    service.ConstructUsing(s => new CruzAzulService());
                    service.WhenStarted(s => s.Start());
                    service.WhenStopped(s => s.Stop());
                });
                //Setup Account that window service use to run.
                configure.RunAsLocalSystem();
                configure.SetServiceName("CruzAzul");
                configure.SetDisplayName("CruzAzul");
                configure.SetDescription("Serviço de integração");
            });
        }
Example #7
0
        static int Main(string[] args)
        {
            // Loads the config from our App.config
            XmlConfigurator.Configure();

            // Topshelf to use Log4Net
            Log4NetLogWriterFactory.Use();

            // MassTransit to use Log4Net
            Log4NetLogger.Use();

            // Ioc Helper method for Autofac
            var container = IocConfig.RegisterDependencies();

            return((int)HostFactory.Run(cfg =>
            {
                cfg.Service(s => container.Resolve <MyService>());

                cfg.RunAsLocalSystem();
            }));
        }
Example #8
0
        public static void Main(string[] args)
        {
            HanldeGlobalExceptions();

            var rc = HostFactory.Run(x =>
            {
                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);
                x.RunAsLocalSystem();

                x.Service(factory => { return(QuartzServer.Server); });
            });
            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());
            var msg      = string.Format(
                "------------------------------- FinCore Exited with code: (%d) --------------------------------",
                exitCode);

            Log.Info(msg);
            Environment.ExitCode = exitCode;
        }
Example #9
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            HostFactory.Run(x =>
            {
                x.Service <SpringServiceHost>(s =>
                {
                    s.ConstructUsing(name => new SpringServiceHost());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("LogicTracker WebService Consumer Host");
                x.SetDisplayName("Lt WebService Consumer");
                x.SetServiceName("Lt.App.WebServiceConsumer");
                x.DependsOnMsmq();
                x.DependsOnEventLog();
            });
        }
Example #10
0
        static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.Service <WechatNotification>((s) =>
                {
                    s.ConstructUsing(name => new WechatNotification());
                    s.WhenStarted((t) => t.Start());
                    s.WhenStopped((t) => t.Stop());
                });

                x.RunAsLocalSystem();

                //服务的描述
                x.SetDescription("WechatNotification");
                //服务的显示名称
                x.SetDisplayName("打卡小助手");
                //服务名称
                x.SetServiceName("打卡小助手");
            });
        }
Example #11
0
        static void Main(string[] args)
        {
            //https://github.com/Topshelf/Topshelf/issues/473
            //issue:服务没有及时响应启动或者控制请求
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            Directory.SetCurrentDirectory(path);
            //issue结束


            HostFactory.Run(x => {
                x.Service <ServiceRunner>();

                //x.RunAsLocalSystem();
                x.SetDescription("windows服务");
                x.SetDisplayName("windows服务");
                x.SetServiceName("windows服务");

                x.StartAutomatically();
            });
        }
Example #12
0
        static void Main()
        {
            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            XmlConfigurator.ConfigureAndWatch(new FileInfo(Log4NetConfig));
            HostLogger.UseLogger(new Log4NetLogWriterFactory.Log4NetLoggerConfigurator(Log4NetConfig));

            HostFactory.Run(x =>
            {
                x.Service <Service>(s =>
                {
                    s.ConstructUsing(() => new Service());
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                });

                x.RunAsLocalSystem();
                x.SetDescription("Bookstore service.");
                x.SetServiceName("BookstoreService");
                x.SetDisplayName("Bookstore Service");
            });
        }
Example #13
0
        /// <summary>
        /// This program creates a service that can be installed in the system, which handles
        /// every request sent via RabbitMQ with petitions to access the database.
        /// </summary>
        static void Main()
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <DatabaseListener>(s =>
                {
                    s.ConstructUsing(name => new DatabaseListener(new DBAccess()));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Meter database listener");
                x.SetDisplayName("Meter database listener");
                x.SetServiceName("MDL");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Example #14
0
        static void Main()
        {
            _logger = LogManager.GetLogger(typeof(Program));

            XmlConfigurator.Configure(new FileInfo("..\\..\\App.config"));

            HostFactory.Run(x =>
            {
                x.Service <BattleEngine>(s =>
                {
                    s.ConstructUsing(name => new BattleEngine(new Uri(ConfigSettings.ReadSetting("ServerUrl"))));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();
                x.StartManually();
                x.SetDescription("RobotsAtWar");
                x.SetDisplayName("RobotsAtWar");
                x.SetServiceName("RobotsAtWar");
            });
        }
Example #15
0
        public static void Main()
        {
            var rc = HostFactory.Run(x =>                                  //1
            {
                x.Service <TownCrier>(s =>                                 //2
                {
                    s.ConstructUsing(name => new TownCrier());             //3
                    s.WhenStarted(tc => tc.Start());                       //4
                    s.WhenStopped(tc => tc.Stop());                        //5
                });
                x.RunAsLocalSystem();                                      //6

                x.SetDescription("Sample Topshelf Host");                  //7
                x.SetDisplayName("Stuff");                                 //8
                x.SetServiceName("Stuff");                                 //9
            });                                                            //10

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());  //11

            Environment.ExitCode = exitCode;
        }
Example #16
0
 static void Main(string[] args)
 {
     HostFactory.Run(hc =>
     {
         hc.Service <SchedulerServiceWrapper>(sc =>
         {
             sc.ConstructUsing(() =>
             {
                 _bootstrapper = new AppBootstrapper();
                 _bootstrapper.Run();
                 return(_bootstrapper.Container.Resolve <SchedulerServiceWrapper>());
             });
             sc.WhenStarted(s => s.Start());
             sc.WhenStopped(s => s.Stop());
         });
         hc.SetServiceName("SchedulerServiceDemo");
         hc.SetDisplayName("SchedulerService Demo");
         hc.SetDescription("Demo of a distributed system comprised of a scheduler and many generic workers");
         hc.RunAsNetworkService();
     });
 }
Example #17
0
        static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.Service <SayService>(s =>
                {
                    s.ConstructUsing(settings => new SayService());
                    s.WhenStarted(tr => tr.Start());
                    s.WhenStopped(tr => tr.Stop());
                });

                x.RunAsLocalSystem();

                x.SetDescription("定时报告时间01");
                x.SetDisplayName("时间报告器01");
                x.SetServiceName("TimeReporter01");
            });

            Console.WriteLine("ok");
            Console.ReadKey();
        }
Example #18
0
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main()
        {
            // change from service account's dir to more logical one
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            HostFactory.Run(x =>
            {
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.Service(factory =>
                {
                    QuartzServer server = QuartzServerFactory.CreateServer();
                    server.Initialize();
                    return(server);
                });
            });
        }
Example #19
0
        static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <Service>(s =>
                {
                    s.ConstructUsing(name => new Service());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("SimpleRemote Configuration Host");
                x.SetDisplayName("SimpleConfig");
                x.SetServiceName("SimpleConfig");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
        public void Start()
        {
            _serviceProvider = _services.BuildServiceProvider();

            HostFactory.Run(windowsService =>
            {
                windowsService.Service <IntervalRunner>(s =>
                {
                    s.ConstructUsing(service => _serviceProvider.GetRequiredService <IntervalRunner>());
                    s.WhenStarted(service => service.Start());
                    s.WhenStopped(service => service.Stop());
                });

                windowsService.RunAsLocalSystem();
                windowsService.StartAutomatically();

                windowsService.SetDescription(_serviceName);
                windowsService.SetDisplayName(_serviceName);
                windowsService.SetServiceName(_serviceName);
            });
        }
Example #21
0
 static void Main(string[] args)
 {
     if (args.Length > 0)
     {
         Console.SetOut(Debugger.Out);
         HostFactory.Run(c =>
         {
             c.Service <ServerControl>();
             c.RunAsLocalSystem();
             c.SetServiceName("GuardDog");
             c.SetDisplayName("看门狗");
             c.SetDescription("服务与进程看门狗");
         });
     }
     else
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         Application.Run(new MainForm());
     }
 }
Example #22
0
        static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <CowTipper>(s =>
                {
                    s.ConstructUsing(name => new CowTipper(2000));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Lets Kill Cows.");
                x.SetDisplayName("Cow Tipper");
                x.SetServiceName("CowTipper");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Example #23
0
        public static void Main()
        {
            var log = new LoggerConfiguration().WriteTo.Console().CreateLogger();

            Log.Logger = log;

            HostFactory.Run(x =>
            {
                x.Service <NancySelfHost>(s =>
                {
                    s.ConstructUsing(name => new NancySelfHost());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });

                x.RunAsLocalSystem();
                x.SetDescription("net.projects.test");
                x.SetDisplayName("net.projects.test Service");
                x.SetServiceName("NetProjectsTest");
            });
        }
Example #24
0
        public static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <InvoiceProcessingService>(svc =>
                {
                    svc.ConstructUsing(name => new InvoiceProcessingService());
                    svc.WhenStarted(s => s.Start());
                    svc.WhenStopped(s => s.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("Invoice Processing Service");
                x.SetDisplayName("InvoiceProcessingService");
                x.SetServiceName("InvoiceProcessingService");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Example #25
0
 static void Main(string[] args)
 {
     HostFactory.Run(hc =>
     {
         hc.Service <WorkerServiceWrapper>(sc =>
         {
             sc.ConstructUsing(() =>
             {
                 _bootstrapper = new AppBootstrapper();
                 _bootstrapper.Run();
                 return(_bootstrapper.Container.Resolve <WorkerServiceWrapper>());
             });
             sc.WhenStarted(s => s.Start());
             sc.WhenStopped(s => s.Stop());
         });
         hc.SetServiceName("Demo_WorkerService");
         hc.SetDisplayName("WorkerService Demo");
         hc.SetDescription("Demo Worker service");
         hc.RunAsNetworkService();
     });
 }
Example #26
0
        static void Main(string[] args)
        {
            _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
            _log.Info("Incremental Data Extractor Main.");

            HostFactory.Run(configurator =>
            {
                configurator.Service <IncrementalExtractionService>(settings =>
                {
                    settings.ConstructUsing(s => new IncrementalExtractionService());
                    settings.WhenStarted(s => s.Start());
                    settings.WhenStopped(s => s.Stop());
                });

                configurator.RunAsLocalSystem();
                configurator.SetServiceName("IncrementalDataExtractor");
                configurator.SetDisplayName("Incremental Data Extractor");
                configurator.SetDescription("Retrieve data from Metasys API on a set time interval.");
                configurator.StartAutomatically();
            });
        }
        static void Main(string[] args)
        {
            string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            string tempDirectory    = Path.Combine(currentDirectory, "temp");
            string inputDirectory   = Path.Combine(currentDirectory, "in");

            HostFactory.Run(
                hostConfig =>
            {
                hostConfig.Service <ImageProcessingService>(
                    s =>
                {
                    s.ConstructUsing(() => new ImageProcessingService(inputDirectory, tempDirectory));
                    s.WhenStarted(serv => serv.Start());
                    s.WhenStopped(serv => serv.Stop());
                });
                hostConfig.SetServiceName("Image Processing Service");
                hostConfig.StartAutomaticallyDelayed();
                hostConfig.RunAsLocalService();
            });
        }
        static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.Service <ArduinoInfos>(s =>
                {
                    s.ConstructUsing(name => new ArduinoInfos());
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();

                x.SetDescription("É um serviço que pega dados do Arduino e os salva em um banco de dados.");
                x.SetDisplayName("Coletor de dados do Arduino");
                x.SetServiceName("ColetorArduino");
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());

            Environment.ExitCode = exitCode;
        }
Example #29
0
        static void Main(string[] args)
        {
            var rc = HostFactory.Run(x =>
            {
                x.SetServiceName("TestHttpService");
                x.SetDisplayName("TestHttpService");
                x.SetDescription("TestHttpService");
                x.Service <HttpService>();
                x.StartAutomatically();
                x.RunAsLocalSystem();
                x.UseNLog();
                x.EnableShutdown();
                x.OnException((ex) =>
                {
                    Console.WriteLine(ex.Message);
                });
            });
            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode()); //11

            Environment.ExitCode = exitCode;
        }
Example #30
0
        static void Main(string[] args)
        {
            HostFactory.Run(c =>
            {
                // Topshelf.Ninject (Optional) - Initiates Ninject and consumes Modules
                c.UseNinject(new SampleModule());
                // Topshelf.Quartz.Ninject (Optional) - Construct IJob instance with Ninject
                c.UseQuartzNinject();

                c.ScheduleQuartzJobAsService(q =>
                                             q.WithJob(() =>
                                                       JobBuilder.Create <SampleJob>().Build())
                                             .AddTrigger(() =>
                                                         TriggerBuilder.Create()
                                                         .WithSimpleSchedule(builder => builder
                                                                             .WithIntervalInSeconds(5)
                                                                             .RepeatForever())
                                                         .Build())
                                             );
            });
        }