Beispiel #1
0
        /// <summary>
        /// Extracts the configuration data from the supplied dictionary
        /// </summary>
        /// <param name="parameters">A dictionary object containing the startup parameters</param>
        /// <returns>A Configuration object containing the parsed configuration values</returns>
        private Configuration ParseConfigurationData(IDictionary<string, string> parameters)
        {
            string[] values;
            Configuration configuration = new Configuration();

            // Extensions
            if (parameters.ContainsKey(PARAMETER_EXTENSIONS_PATH))
            {
                values = parameters[PARAMETER_EXTENSIONS_PATH].Split(PARAMETER_DELIMITER);

                foreach (string str in values)
                {
                    configuration.Extensions.Add(new Extension
                        {
                            Path = str
                        });
                }
            }

            // External resources
            if (parameters.ContainsKey(PARAMETER_EXTERNAL_RESOURCES_PATH))
            {
                string value = parameters[PARAMETER_EXTERNAL_RESOURCES_PATH].Replace(";", ","); // Replace semicolons with commas to make it proper JSON

                configuration.ExternalResources = JsonConvert.DeserializeObject<Collection<ExternalResource>>(value);
            }

            // Graph Label
            if (parameters.ContainsKey(PARAMETER_GRAPH_LABEL))
            {
                string value = parameters[PARAMETER_GRAPH_LABEL].Replace(";", ","); // Replace semicolons with commas to make it proper JSON

                configuration.GraphLabel = JsonConvert.DeserializeObject<GraphLabel>(value);
            }

            // Application Mode
            if (parameters.ContainsKey(PARAMETER_APPLICATION_MODE))
            {
                configuration.ApplicationMode = (ApplicationMode)Enum.Parse(typeof(ApplicationMode), parameters[PARAMETER_APPLICATION_MODE], true);
            }
            else
            {
                configuration.ApplicationMode = ApplicationMode.Evaluation;
            }

            // Live
            if (parameters.ContainsKey(PARAMETER_LIVE))
            {
                if (configuration.LivePreferences == null)
                {
                    configuration.LivePreferences = new Live();
                }

                configuration.LivePreferences.AutoStart = Boolean.Parse(parameters[PARAMETER_LIVE]);
            }

            // LoggerProvider
            if (parameters.ContainsKey(PARAMETER_LOGGER_LEVEL) && parameters.ContainsKey(PARAMETER_LOGGER_PROVIDER))
            {
                configuration.LoggerProvider = new LoggerProvider
                {
                    Level = (LoggerLevel)Enum.Parse(typeof(LoggerLevel), parameters[PARAMETER_LOGGER_LEVEL], true),
                    Provider = parameters[PARAMETER_PREFERENCES_PROVIDER]
                };
            }

            // PreferencesProvider
            if (parameters.ContainsKey(PARAMETER_PREFERENCES_PROVIDER))
            {
                configuration.PreferencesProvider = new PreferencesProvider
                {
                    Provider = parameters[PARAMETER_PREFERENCES_PROVIDER]
                };
            }

            // IsToolbarHidden
            if (parameters.ContainsKey(PARAMETER_GRAPH_ISTOOLBARHIDDEN))
            {
                configuration.IsToolbarHidden = bool.Parse(parameters[PARAMETER_GRAPH_ISTOOLBARHIDDEN]);
            }
            else
                configuration.IsToolbarHidden = false;

            // IsToolPanelHidden
            if (parameters.ContainsKey(PARAMETER_GRAPH_ISTOOLPANELHIDDEN))
            {
                configuration.IsToolPanelHidden = bool.Parse(parameters[PARAMETER_GRAPH_ISTOOLPANELHIDDEN]);
            }
            else
                configuration.IsToolPanelHidden = false;

            return configuration;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes the configuration manager
        /// </summary>
        /// <param name="parameters">A dictionary of key/value pairs representing configuration
        /// settings for the application</param>
        public void Initialize(IDictionary<string, string> parameters)
        {
            Configuration internalConfig = ParseConfigurationData();
            Configuration markupConfig;

            //_logger.WriteLogEntry(LogLevel.INFO, "Storing configuration parameters", null, null);

            // Copy the provided initParams to our internal dictionary
            if (parameters.Count > 0)
            {
                markupConfig = ParseConfigurationData(parameters);
            }
            else
            {
                markupConfig = null;
            }

            // Merge the configuration values
            _configuration = MergeProperties(typeof(Configuration), internalConfig, markupConfig) as Configuration;
        }