コード例 #1
0
ファイル: Manager.cs プロジェクト: wuchang/scada-v6
        /// <summary>
        /// Starts the service.
        /// </summary>
        public bool StartService()
        {
#if DEBUG
            System.Diagnostics.Debugger.Launch();
#endif

            string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            AppDirs.Init(exeDir);

            LogFile logFile = new LogFile(LogFormat.Full, Path.Combine(AppDirs.LogDir, CommUtils.LogFileName))
            {
                Capacity = int.MaxValue
            };

            log = logFile;
            log.WriteBreak();

            if (!Locale.LoadCulture(Path.Combine(exeDir, "..", "Config", InstanceConfig.DefaultFileName),
                                    out string errMsg))
            {
                log.WriteError(errMsg);
            }

            log.WriteAction(Locale.IsRussian ?
                            "Коммуникатор {0} запущен" :
                            "Communicator {0} started", CommUtils.AppVersion);

            if (AppDirs.CheckExistence(out errMsg))
            {
                LocalizeApp(AppDirs.LangDir);
                string     configFileName = Path.Combine(AppDirs.ConfigDir, CommConfig.DefaultFileName);
                CommConfig config         = new CommConfig();
                coreLogic = new CoreLogic(config, AppDirs, log);

                if (config.Load(configFileName, out errMsg) &&
                    coreLogic.StartProcessing())
                {
                    logFile.Capacity = config.GeneralOptions.MaxLogSize;
                    return(true);
                }
                else if (!string.IsNullOrEmpty(errMsg))
                {
                    log.WriteError(errMsg);
                }
            }
            else
            {
                log.WriteError(errMsg);
            }

            log.WriteError(CommonPhrases.ExecutionImpossible);
            return(false);
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: RapidScada/scada-v6
        /// <summary>
        /// Starts the service.
        /// </summary>
        public bool StartService()
        {
#if DEBUG
            System.Diagnostics.Debugger.Launch();
#endif

            // load instance configuration
            AppDirs.Init(Assembly.GetExecutingAssembly());
            InstanceConfig instanceConfig = new InstanceConfig();
            Locale.SetCultureToEnglish();

            if (instanceConfig.Load(InstanceConfig.GetConfigFileName(AppDirs.InstanceDir), out string errMsg))
            {
                Locale.SetCulture(instanceConfig.Culture);
                AppDirs.UpdateLogDir(instanceConfig.LogDir);
            }
            else
            {
                Console.WriteLine(errMsg);
                Locale.SetCultureToDefault();
            }

            // initialize log
            LogFile logFile = new LogFile(LogFormat.Full, Path.Combine(AppDirs.LogDir, CommUtils.LogFileName))
            {
                Capacity = int.MaxValue
            };

            log = logFile;
            log.WriteBreak();

            // prepare to start service
            log.WriteAction(Locale.IsRussian ?
                            "Коммуникатор {0} запущен" :
                            "Communicator {0} started", EngineUtils.AppVersion);

            storageWrapper = new StorageWrapper(new StorageContext
            {
                App     = ServiceApp.Comm,
                AppDirs = AppDirs,
                Log     = log
            }, instanceConfig);

            CommConfig appConfig = new CommConfig();

            if (AppDirs.CheckExistence(out errMsg) &&
                LocalizeApp() &&
                storageWrapper.InitStorage() &&
                appConfig.Load(storageWrapper.Storage, CommConfig.DefaultFileName, out errMsg))
            {
                // start service
                logFile.CapacityMB = appConfig.GeneralOptions.MaxLogSize;
                coreLogic          = new CoreLogic(appConfig, AppDirs, storageWrapper.Storage, log);

                if (coreLogic.StartProcessing())
                {
                    return(true);
                }
            }
            else if (!string.IsNullOrEmpty(errMsg))
            {
                log.WriteError(errMsg);
            }

            log.WriteError(CommonPhrases.ExecutionImpossible);
            return(false);
        }