/// <summary>
        /// Initializes a new instance of the <see cref="PluginConfigurationRepository"/> class with a provided
        /// configuration object of type <see cref="PluginConfigurationData"/>.
        /// </summary>
        /// <param name="config">The plugin configuration object.</param>
        public PluginConfigurationRepository(PluginConfigurationData config)
        {
            string folder = string.Format("{0}\\Windows Live Writer", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

            _configurationFilePath = string.Format(@"{0}\{1}", folder, ConfigFile);
            if (Directory.Exists(folder) == false)
            {
                Directory.CreateDirectory(folder);
            }
            _config = config;
        }
        /// <summary>
        /// Loads the plugin configuration data from user's configuration file.
        /// </summary>
        /// <remarks>
        /// The configuration file is located at <code>%AppData%\Windows Live Writer\WindowsLiveWriter.SourceCode.config</code>.
        /// </remarks>
        public void LoadPluginConfigurationData()
        {
            if (File.Exists(_configurationFilePath) == false)
            {
                _config = new PluginConfigurationData();
            }

            XmlSerializer serializer = null;
            FileStream    stream     = null;

            try
            {
                serializer = new XmlSerializer(typeof(PluginConfigurationData));
                stream     = new FileStream(_configurationFilePath, FileMode.Open);

                _config = (PluginConfigurationData)serializer.Deserialize(stream);
                stream.Close();
                stream = null;
            }
            #region ExceptionHandling
            catch (Exception ex)
            {
                if (
                    (ex is DirectoryNotFoundException) ||
                    (ex is PathTooLongException) ||
                    (ex is FileNotFoundException) ||
                    (ex is IOException) ||
                    (ex is SecurityException) ||
                    (ex is NotSupportedException) ||
                    (ex is ArgumentOutOfRangeException)
                    )
                {
                    string error = string.Format("Can't load configuration from '{0}' file.\n\nDetails: {1}", _configurationFilePath, ex.Message);
                    MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    throw;
                }
            }
            #endregion //ExceptionHandling
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionsForm"/> class.
        /// </summary>
        /// <param name="config">The config.</param>
        public OptionsForm(PluginConfigurationData config)
        {
            InitializeComponent();
            PluginConfigurationData = config;

            checkServerDefaults.Checked    = PluginConfigurationData.UseServerDefaults;
            checkBoxAutoLinks.Checked      = PluginConfigurationData.AutoLinks;
            checkBoxCollapse.Checked       = PluginConfigurationData.Collapse;
            checkBoxGutter.Checked         = PluginConfigurationData.Gutter;
            checkBoxHtmlScript.Checked     = PluginConfigurationData.HtmlScript;
            checkBoxLight.Checked          = PluginConfigurationData.Light;
            checkBoxRuler.Checked          = PluginConfigurationData.Ruler;
            checkBoxSmartTabs.Checked      = PluginConfigurationData.SmartTabs;
            checkBoxToolbar.Checked        = PluginConfigurationData.Toolbar;
            checkLoadFromClipboard.Checked = PluginConfigurationData.LoadFromClipboard;
            numericTabSize.Value           = PluginConfigurationData.TabSize;
            textBoxClassName.Text          = (PluginConfigurationData.ClassName ?? string.Empty);
            labelFamily.Text = PluginConfigurationData.CodeFontFamily;
            labelSize.Text   = PluginConfigurationData.CodeFontSize.ToString();
            this.UpdateCodeFont();
        }
        private void UpdateConfig(PluginConfigurationData config, string variable, string value)
        {
            switch (variable)
            {
            case "brush":
                config.Brush = GetString(value);
                break;

            case "auto-links":
                config.AutoLinks = GetBoolean(value, config.AutoLinks);
                break;

            case "class-name":
                config.ClassName = GetString(value);
                break;

            case "collapse":
                config.Collapse = GetBoolean(value, config.Collapse);
                break;

            case "first-line":
                config.FirstLine = GetInt(value, config.FirstLine);
                break;

            case "gutter":
                config.Gutter = GetBoolean(value, config.Gutter);
                break;

            case "highlight":
                int from = value.IndexOf("[");
                int to   = value.LastIndexOf("]");
                if ((0 <= from) && (from < to))
                {
                    config.Highlight = GetString(value.Substring(from + 1, to - from - 1));
                }
                break;

            case "html-script":
                config.HtmlScript = GetBoolean(value, config.HtmlScript);
                break;

            case "light":
                config.Light = GetBoolean(value, config.Light);
                break;

            case "ruler":
                config.Ruler = GetBoolean(value, config.Ruler);
                break;

            case "smart-tabs":
                config.SmartTabs = GetBoolean(value, config.SmartTabs);
                break;

            case "tab-size":
                config.TabSize = GetInt(value, config.TabSize);
                break;

            case "toolbar":
                config.Toolbar = GetBoolean(value, config.Toolbar);
                break;

            default:
                break;
            }
        }