public void Start()
        {
            var config               = CfgUtils.LookupDefaultConfigs();
            var serviceOptions       = new ServiceOptions();
            var exchangeSection      = config.GetSection("Exchange");
            var serviceOptionSection = exchangeSection.GetSection("Service");

            serviceOptionSection?.Bind(serviceOptions);

            CfgUtils.SetupIoC(config);

            ImportDataService <HostControl> .Configuration = config;
            //RedmineImportWorker.Configuration = Configuration;

            //инициализация сервиса
            switch (serviceOptions.Type)
            {
            case "ProcessService":
                HostFactory.Run(x =>
                {
                    x.Service <ProcessDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();             //Запускать под учетной записью System
                    x.StartManually();                //Запуск вручную
                    //x.UseNLog();
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription($"{serviceOptions.Name} - {serviceOptions.Description} ");
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;

            case "ExportService":
                HostFactory.Run(x =>
                {
                    x.Service <ExportDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();            //Запускать под учетной записью System
                    x.StartManually();               //Запуск вручную
                    // x.UseNLog();
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription($"{serviceOptions.Name} - {serviceOptions.Description} ");
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;

            case "ImportService":
                HostFactory.Run(x =>
                {
                    x.Service <ImportDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();            //Запускать под учетной записью System
                    x.StartManually();               //Запуск вручную
                    // x.UseNLog();
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription($"{serviceOptions.Name} - {serviceOptions.Description} ");
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;
            }
        }
        public virtual void Init()
        {
#if NET452
            Assembly assembly = Assembly.GetCallingAssembly();

            AppDomainManager manager            = new AppDomainManager();
            FieldInfo        entryAssemblyfield = manager.GetType().GetField("m_entryAssembly", BindingFlags.Instance | BindingFlags.NonPublic);
            entryAssemblyfield.SetValue(manager, assembly);

            AppDomain domain             = AppDomain.CurrentDomain;
            FieldInfo domainManagerField = domain.GetType().GetField("_domainManager", BindingFlags.Instance | BindingFlags.NonPublic);
            domainManagerField.SetValue(domain, manager);
#endif
            var config               = CfgUtils.LookupDefaultConfigs();
            var serviceOptions       = new ServiceOptions();
            var exchangeSection      = config.GetSection("Exchange");
            var serviceOptionSection = exchangeSection.GetSection("Service");
            serviceOptionSection?.Bind(serviceOptions);

            CfgUtils.SetupIoC(config);
            ProcessDataService <Task> .Configuration = config;
            ImportDataService <Task> .Configuration  = config;
            ExportDataService <Task> .Configuration  = config;
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("AutofacCfg.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("lookupAssemblies.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("exchangeCfg.json", optional: true, reloadOnChange: true);

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
            // Configuration = CfgUtils.LookupDefaultConfigs();
            var serviceOptions       = new ServiceOptions();
            var exchangeSection      = Configuration.GetSection("Exchange");
            var serviceOptionSection = exchangeSection.GetSection("Service");

            serviceOptionSection?.Bind(serviceOptions);
            //var registrantSection = exchangeSection.GetSection("Registrant");
            //var registrantOptions = new RegistrantOptions();

            //if (registrantSection != null)
            //    registrantSection.Bind(registrantOptions);
            //else
            //    registrantOptions.InitDefault();

            //var ioCBuilder = new ContainerBuilder();
            //ioCBuilder.RegisterModule(new ModuleRegistrant(Configuration, registrantOptions));
            //IoCHelper.Container = ioCBuilder.Build();
            CfgUtils.SetupIoC(Configuration);

            ProcessDataService <HostControl> .Configuration = Configuration;
            //инициализация сервиса
            switch (serviceOptions.Type)
            {
            case "ProcessService":
                HostFactory.Run(x =>
                {
                    x.Service <ProcessDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();             //Запускать под учетной записью System
                    x.StartManually();                //Запуск вручную
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription(string.Format("{0} - {1} ", serviceOptions.Name, serviceOptions.Description));
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;

            case "ExportService":
                HostFactory.Run(x =>
                {
                    x.Service <ExportDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();            //Запускать под учетной записью System
                    x.StartManually();               //Запуск вручную
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription(string.Format("{0} - {1} ", serviceOptions.Name, serviceOptions.Description));
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;

            case "ImportService":
                HostFactory.Run(x =>
                {
                    x.Service <ImportDataService>(); //Как описание использовать ConverterService
                    x.RunAsLocalSystem();            //Запускать под учетной записью System
                    x.StartManually();               //Запуск вручную
                    x.SetServiceName(serviceOptions.Name);
                    x.SetDescription(string.Format("{0} - {1} ", serviceOptions.Name, serviceOptions.Description));
                    x.SetDisplayName(serviceOptions.Name);
                });
                break;
            }
        }