Beispiel #1
0
        private static void Main()
        {
            LogEntry.New().Info().Message($"*** {InstanceName} v{InstanceVersion} started ***").Log(Logger);

            try
            {
                var cronService = new CronService();
                RobotJob.Scheduler = cronService.Scheduler;

                cronService.Scheduler.ScheduleJob <RobotScheduleUpdater>(
                    name: nameof(RobotScheduleUpdater),
                    cronExpression: Configuration.Load <Program, Global>().RobotConfigUpdaterSchedule,
                    startImmediately: false
                    );

                ServiceStarter.Start(cronService);
            }
            catch (Exception ex)
            {
                LogEntry.New().Error().Exception(ex).Message("Error starting service.").Log(Logger);
            }

            if (Environment.UserInteractive)
            {
                Console.ReadKey();
            }
        }
Beispiel #2
0
        protected override IContainer Configure(ContainerBuilder builder)
        {
            ISensorWatcher watcher = new SensorWatcher();

            ServiceStarter.Start(watcher.WatchProc, "SensorProcess");
            builder.RegisterType <ValuesController>().InstancePerRequest();
            builder.RegisterType <Computer>().As <IComputer>();
            builder.RegisterInstance(watcher).As <ISensorWatcher>();
            return(builder.Build());
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            try
            {
                var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (!File.Exists(Path.Combine(directory, "service.json")))
                {
                    log.Error("Configuration file service.json not found");
                    return;
                }

                MonitoringConfig config = JsonConvert.DeserializeObject <MonitoringConfig>(File.ReadAllText(Path.Combine(directory, "service.json")));
                if (!config.Validate())
                {
                    log.Error("Invalid configuration");
                    return;
                }

                NetworkScanner scanner = new NetworkScanner(TaskPoolScheduler.Default);
                log.Info("Starting {0} version utility...", Assembly.GetExecutingAssembly().GetName().Version);
                foreach (var address in scanner.GetLocalIPAddress())
                {
                    log.Info("Starting on local IP: [{0}]", address);
                }

                List <Command> commandsList = new List <Command>();
                commandsList.Add(new MonitorCommand(config));
                commandsList.Add(new DownloadCommand(config));
                var commands = commandsList.ToDictionary(item => item.Name, item => item, StringComparer.OrdinalIgnoreCase);

                if (args.Length == 0 ||
                    !commands.TryGetValue(args[0], out var command))
                {
                    log.Info("Starting as service");
                    ServiceStarter serviceStarter = new ServiceStarter();
                    serviceStarter.StartService(config);
                    return;
                }

                command.ParseArguments(args.Skip(1));
                command.Execute();
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
        protected override IContainer Configure(ContainerBuilder builder)
        {
            builder.RegisterType <DataContext>()
            .As <IDataContext>().As <IReadOnlyDataContext>();


            builder.RegisterType <DataReceiver>().As <IDataReceiver>();
            builder.RegisterType <DataProvider>().As <IDataProvider>();
            builder.RegisterType <HierarchyWriter>().As <IHierarchyWriter>();
            builder.RegisterType <MetricWriter>().As <IMetricWriter>();
            builder.RegisterType <SessionWriter>().AsSelf();
            builder.RegisterType <AgentController>().InstancePerRequest();
            builder.RegisterType <MetricsController>().InstancePerRequest();
            var config = builder.Build();
            var writer = config.Resolve <SessionWriter>();

            ServiceStarter.Start(writer.WriteSession, "WriteDB");
            return(config);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <VkAuthSettings>(Configuration.GetSection("VkAuthSettings"));
            services.Configure <VkSettings>(Configuration.GetSection("VkSettings"));
            services.Configure <EndpointSettings>(Configuration.GetSection("EndpointSettings"));
            services.Configure <VkConsumeSettings>(Configuration.GetSection("VkConsumeSettings"));
            services.Configure <TwitterConsumeSettings>(Configuration.GetSection("TwitterConsumeSettings"));

            services.AddMvc(options =>
            {
                options.CacheProfiles.Add("Default",
                                          new CacheProfile
                {
                    Duration = 60
                });
            });
            services.AddMediatR(typeof(EfQueryHandler));
            var connectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;

            services.AddEntityFrameworkSqlServer()
            .AddDbContext <SqlApplicationDbContext>(options => options.UseSqlServer(connectionString));

            IDbSeeder dbSeeder = new DbSeeder();

            dbSeeder.Seed(connectionString);

            services.AddSingleton <IConfiguration>(Configuration);
            services.AddScoped(sp => mapperConfiguration.CreateMapper());
            mapperConfiguration.AssertConfigurationIsValid();

            services.AddCors(options => options.AddPolicy("CorsPolicy",
                                                          builder => builder.AllowAnyOrigin()
                                                          .AllowAnyMethod()
                                                          .AllowAnyHeader()
                                                          .AllowCredentials()));

            var container = new AutofacModulesConfigurator().Configure(services);
            var starter   = new ServiceStarter(container);

            starter.Start();
            return(container.Resolve <IServiceProvider>());
        }
Beispiel #6
0
 private void Awake()
 {
     if (instance != null)
     {
         Destroy(this);
         return;
     }
     else
     {
         instance = this;
         if (instanceExisted)
         {
             ServiceBucket.ResetAllServices();
         }
         else
         {
             instanceExisted = true;
         }
     }
     setAllServices();
 }
Beispiel #7
0
 private void OnDestroy()
 {
     instance = null;
 }
Beispiel #8
0
 public static Task Main()
 {
     return(ServiceStarter.Start <MyService>());
 }
Beispiel #9
0
 private static void Main(string[] args)
 {
     ServiceStarter.StartApplication <Service1>(args);
 }