Exemplo n.º 1
0
        /// <summary>
        /// The get environment.
        /// </summary>
        /// <param name="executionParam">
        /// The execution param.
        /// </param>
        /// <param name="globalContext">
        /// The global context.
        /// </param>
        /// <returns>
        /// The <see cref="MonitorEnvironment"/>.
        /// </returns>
        private MonitorEnvironment GetEnvironment(ExecutionParam executionParam, WinFormGlobalContext globalContext)
        {
            var pluginResolver = new AssemblyPluginResolver(this.Logger);
            pluginResolver.LoadPlugins();
            var configStore = new FileConfigStore(AppUtil.GetLocalDataPath(this.ENV_CONFIG_FILENAME), pluginResolver, this.Logger);

            MonitorEnvironment env = configStore.LoadEnv();

            if (env == null || env.ArchiveManager == null || env.FareDatabase == null || env.FareDataProvider == null)
            {
                env = new MonitorEnvironment(configStore, pluginResolver, new BackgroundServiceManager(this.Logger), this.Logger);
                globalContext.AddServices(env);
                using (var configDialog = new EnvConfiguratorDialog(env, executionParam))
                {
                    if (configDialog.ShowDialog() == DialogResult.OK)
                    {
                        env = configDialog.ResultEnvironment;
                    }
                    else
                    {
                        env.Close();
                        env = null;
                    }
                }
            }

            return env;
        }
Exemplo n.º 2
0
        /// <summary>
        /// The set environment.
        /// </summary>
        /// <param name="env">
        /// The env.
        /// </param>
        internal void SetEnvironment(MonitorEnvironment env)
        {
            this._err = null;
            if (env != null)
            {
                this._logger.Debug("Closing global environment...");
                env.Close();
            }

            this._logger.Info("Setting new global environment...");
            this.AddServices(env); // Add needed services to this environment instance
            this._env = env;

            if (this._env != null)
            {
                this._logger.Debug("Initializing global environment...");
                var result = this._env.Initialize();
                if (!result.Succeeded)
                {
                    this._err = result.ErrorMessage;
                    this._logger.Warn("Error initializing environment: " + this._err);
                }
            }
        }