Inheritance: System.Configuration.ConfigurationSection
示例#1
0
        public MainForm()
        {
            InitializeComponent();

            var container = new UnityContainer();
            container.RegisterInstance(container);
            ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container));

            string exePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), HostMetadata.ServerServiceExe);
            serviceManager = new ServiceManager(HostMetadata.ServerServiceName, exePath);

            configuration = new ConfigurationManager(HostMetadata.ServerApp, Environment.SpecialFolder.CommonApplicationData);
            container.RegisterInstance(configuration);

            var commonApplicationData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
            logger.Info(commonApplicationData);

            templateServiceSettings = configuration.GetSection<TemplateServiceSettings>(TemplateServiceSettings.SectionKey);
            container.RegisterInstance(templateServiceSettings);

            settings = configuration.GetSection<ServerSettings>(ServerSettings.SectionKey);
            container.RegisterInstance(settings);

            editDatabaseSettingsControl.Settings = settings.Database;
            languageControl.Initialize<Language>();
            languageControl.Select<Language>(settings.Language);
            licenseTypeControl.Initialize<ProductLicenceType>();
        }
示例#2
0
        protected override void OnStart(string[] args)
        {
            logger.Info("Starting service...");

            try
            {
                container = new UnityContainer();
                container.RegisterInstance(container);
                ServiceLocator.SetLocatorProvider(() => new UnityServiceLocator(container));

                configuration = new ConfigurationManager(HostMetadata.ServerApp, SpecialFolder.CommonApplicationData);
                container.RegisterInstance(configuration);

                settings = configuration.GetSection<ServerSettings>(ServerSettings.SectionKey);
                container.RegisterInstance(settings);

                templateServiceSettings = configuration.GetSection<TemplateServiceSettings>(TemplateServiceSettings.SectionKey);
                container.RegisterInstance(templateServiceSettings);

                var culture = settings.Language.GetCulture();
                Thread.CurrentThread.CurrentCulture = culture;
                CultureInfo.DefaultThreadCurrentCulture = culture;

                server = new ServerInstance(settings);
                server.Start();

                logger.Info("Service started");
            }
            catch (Exception e)
            {
                logger.Error(e);
                throw;
            }
        }