/// <summary>
        /// Copy the contents of the source settings into this settings
        /// </summary>
        /// <param name="sourceSettings"></param>
        public void CopyFrom(SettingsPersisterHelper sourceSettings, bool recursive, bool overWrite)
        {
            // copy root-level values (to work with types generically we need references
            // to the underlying settings persister objects)
            ISettingsPersister source      = sourceSettings.SettingsPersister;
            ISettingsPersister destination = SettingsPersister;

            foreach (string name in source.GetNames())
            {
                if (overWrite || destination.Get(name) == null)
                {
                    destination.Set(name, source.Get(name));
                }
            }

            // if this is recursive then copy all of the sub-settings
            if (recursive)
            {
                foreach (string subSetting in sourceSettings.GetSubSettingNames())
                {
                    using (SettingsPersisterHelper
                           sourceSubSetting = sourceSettings.GetSubSettings(subSetting),
                           destinationSubSetting = this.GetSubSettings(subSetting))
                    {
                        destinationSubSetting.CopyFrom(sourceSubSetting, recursive, overWrite);
                    }
                }
            }
        }
        /// <summary>
        /// Copy the contents of the source settings into this settings
        /// </summary>
        /// <param name="sourceSettings"></param>
        public void CopyFrom(SettingsPersisterHelper sourceSettings, bool recursive, bool overWrite)
        {
            // copy root-level values (to work with types generically we need references
            // to the underlying settings persister objects)
            ISettingsPersister source = sourceSettings.SettingsPersister;
            ISettingsPersister destination = SettingsPersister;
            foreach (string name in source.GetNames())
                if (overWrite || destination.Get(name) == null)
                    destination.Set(name, source.Get(name));

            // if this is recursive then copy all of the sub-settings
            if (recursive)
            {
                foreach (string subSetting in sourceSettings.GetSubSettingNames())
                {
                    using (SettingsPersisterHelper
                                sourceSubSetting = sourceSettings.GetSubSettings(subSetting),
                                destinationSubSetting = this.GetSubSettings(subSetting))
                    {
                        destinationSubSetting.CopyFrom(sourceSubSetting, recursive, overWrite);
                    }
                }
            }
        }
示例#3
0
 public void Dispose()
 {
     if (_settings != null)
     {
         _settings.Dispose();
         _settings = null;
     }
 }
示例#4
0
 public BlogFileUploadSettings(SettingsPersisterHelper settings)
 {
     _settings = settings;
 }
示例#5
0
        public void Dispose()
        {
            if (_blogCredentials != null)
            {
                _blogCredentials.Dispose();
                _blogCredentials = null;
            }

            if (_fileUploadSettings != null)
            {
                _fileUploadSettings.Dispose();
                _fileUploadSettings = null;
            }

            if (_atomPublishingProtocolSettings != null)
            {
                _atomPublishingProtocolSettings.Dispose();
                _atomPublishingProtocolSettings = null;
            }

            if (_settings != null)
            {
                _settings.Dispose();
                _settings = null;
            }

            // This block is unsafe because it's easy for a persister
            // to be disposed while it's still being used on another
            // thread.

            // if (_keywordPersister.ContainsKey(KeywordPath))
            // {
            //    _keywordPersister[KeywordPath].Dispose();
            //    _keywordPersister.Remove(KeywordPath);
            // }

            GC.SuppressFinalize(this);
        }
 private void AddPluginsFromKey(ArrayList pluginPaths, SettingsPersisterHelper settingsKey)
 {
     foreach (string name in settingsKey.GetNames())
     {
         string assemblyPath = settingsKey.GetString(name, String.Empty);
         if (!pluginPaths.Contains(assemblyPath))
             pluginPaths.Add(assemblyPath);
     }
 }
        private void LoadPluginsFromRegistryPaths(PluginLoader pluginLoader, bool showErrors)
        {
            try
            {
                // build list of assemblies
                ArrayList assemblyPaths = new ArrayList();

                // HKCU
                using (SettingsPersisterHelper userSettingsKey = ApplicationEnvironment.UserSettingsRoot.GetSubSettings(PLUGIN_ASSEMBLIES))
                    AddPluginsFromKey(assemblyPaths, userSettingsKey);

                if (_pluginsKey != PLUGIN_LEGACY_KEY)
                    using (RegistryKey legacyKey = Registry.CurrentUser.OpenSubKey(PLUGIN_LEGACY_KEY))
                        if (legacyKey != null) // Don't create the key if it doesn't already exist
                            using (SettingsPersisterHelper legacyUserSettingsKey = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, PLUGIN_LEGACY_KEY)))
                                AddPluginsFromKey(assemblyPaths, legacyUserSettingsKey);

                // HKLM (this may not work for limited users and/or on vista)

                try
                {
                    if (ApplicationEnvironment.MachineSettingsRoot.HasSubSettings(PLUGIN_ASSEMBLIES))
                        using (SettingsPersisterHelper machineSettingsKey = ApplicationEnvironment.MachineSettingsRoot.GetSubSettings(PLUGIN_ASSEMBLIES))
                            AddPluginsFromKey(assemblyPaths, machineSettingsKey);

                    if (_pluginsKey != PLUGIN_LEGACY_KEY)
                        using (RegistryKey legacyKey = Registry.LocalMachine.OpenSubKey(PLUGIN_LEGACY_KEY))
                            if (legacyKey != null) // Don't create the key if it doesn't already exist
                                using (SettingsPersisterHelper legacyUserSettingsKey = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.LocalMachine, PLUGIN_LEGACY_KEY)))
                                    AddPluginsFromKey(assemblyPaths, legacyUserSettingsKey);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error occurred while attempting to read HKLM for PluginAssemblies: " + ex.ToString());
                }

                // load them
                foreach (string assemblyPath in assemblyPaths)
                    pluginLoader.LoadPluginsFromAssemblyPath(assemblyPath, showErrors);
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception loading plugins from registry paths: " + ex.ToString());
            }
        }
        private static void MaybeMigrateSettings()
        {
            try
            {
                int applicationSettingsVer = 1;
                SettingsPersisterHelper userSettings = ApplicationEnvironment.UserSettingsRoot;
                int currentSettingsVer = userSettings.GetInt32(SETTINGS_VERSION, 0);
                if (currentSettingsVer == 0)
                {
                    userSettings.SetInt32(SETTINGS_VERSION, applicationSettingsVer);
                    Trace.WriteLine("Migrating user settings...");

                    string legacyKeyName = @"Software\Open Live Writer";
                    SettingsPersisterHelper legacySettings = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, legacyKeyName));
                    ApplicationEnvironment.UserSettingsRoot.CopyFrom(legacySettings, true, false); // Don't overwrite existing settings

                    Registry.CurrentUser.DeleteSubKeyTree(legacyKeyName);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Error while attempting to migrate settings.", ex.ToString());
            }
        }
        public void CopyFrom(TemporaryBlogSettings sourceSettings)
        {
            // simple members
            _id = sourceSettings._id;
            _switchToWeblog = sourceSettings._switchToWeblog;
            _isNewWeblog = sourceSettings._isNewWeblog;
            _savePassword = sourceSettings._savePassword;
            _isSpacesBlog = sourceSettings._isSpacesBlog;
            _isSharePointBlog = sourceSettings._isSharePointBlog;
            _hostBlogId = sourceSettings._hostBlogId;
            _blogName = sourceSettings._blogName;
            _homePageUrl = sourceSettings._homePageUrl;
            _manifestDownloadInfo = sourceSettings._manifestDownloadInfo;
            _providerId = sourceSettings._providerId;
            _serviceName = sourceSettings._serviceName;
            _clientType = sourceSettings._clientType;
            _postApiUrl = sourceSettings._postApiUrl;
            _lastPublishFailed = sourceSettings._lastPublishFailed;
            _fileUploadSupport = sourceSettings._fileUploadSupport;
            _instrumentationOptIn = sourceSettings._instrumentationOptIn;

            if (sourceSettings._availableImageEndpoints == null)
            {
                _availableImageEndpoints = null;
            }
            else
            {
                // Good thing BlogInfo is immutable!
                _availableImageEndpoints = (BlogInfo[])sourceSettings._availableImageEndpoints.Clone();
            }

            // credentials
            BlogCredentialsHelper.Copy(sourceSettings._credentials, _credentials);

            // template files
            _templateFiles = new BlogEditingTemplateFile[sourceSettings._templateFiles.Length];
            for (int i = 0; i < sourceSettings._templateFiles.Length; i++)
            {
                BlogEditingTemplateFile sourceFile = sourceSettings._templateFiles[i];
                _templateFiles[i] = new BlogEditingTemplateFile(sourceFile.TemplateType, sourceFile.TemplateFile);
            }

            // option overrides
            if (sourceSettings._optionOverrides != null)
            {
                _optionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._optionOverrides)
                    _optionOverrides.Add(entry.Key, entry.Value);
            }

            // user option overrides
            if (sourceSettings._userOptionOverrides != null)
            {
                _userOptionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._userOptionOverrides)
                    _userOptionOverrides.Add(entry.Key, entry.Value);
            }

            // homepage overrides
            if (sourceSettings._homepageOptionOverrides != null)
            {
                _homepageOptionOverrides.Clear();
                foreach (DictionaryEntry entry in sourceSettings._homepageOptionOverrides)
                    _homepageOptionOverrides.Add(entry.Key, entry.Value);
            }

            // categories
            if (sourceSettings._categories != null)
            {
                _categories = new BlogPostCategory[sourceSettings._categories.Length];
                for (int i = 0; i < sourceSettings._categories.Length; i++)
                {
                    BlogPostCategory sourceCategory = sourceSettings._categories[i];
                    _categories[i] = sourceCategory.Clone() as BlogPostCategory;
                }
            }
            else
            {
                _categories = null;
            }

            if (sourceSettings._keywords != null)
            {
                _keywords = new BlogPostKeyword[sourceSettings._keywords.Length];
                for (int i = 0; i < sourceSettings._keywords.Length; i++)
                {
                    BlogPostKeyword sourceKeyword = sourceSettings._keywords[i];
                    _keywords[i] = sourceKeyword.Clone() as BlogPostKeyword;
                }
            }
            else
            {
                _keywords = null;
            }

            // authors and pages
            _authors = sourceSettings._authors.Clone() as AuthorInfo[];
            _pages = sourceSettings._pages.Clone() as PageInfo[];

            // buttons
            if (sourceSettings._buttonDescriptions != null)
            {
                _buttonDescriptions = new BlogProviderButtonDescription[sourceSettings._buttonDescriptions.Length];
                for (int i = 0; i < sourceSettings._buttonDescriptions.Length; i++)
                    _buttonDescriptions[i] = sourceSettings._buttonDescriptions[i].Clone() as BlogProviderButtonDescription;
            }
            else
            {
                _buttonDescriptions = null;
            }

            // favicon
            _favIcon = sourceSettings._favIcon;

            // images
            _image = sourceSettings._image;
            _watermarkImage = sourceSettings._watermarkImage;

            // host blogs
            _hostBlogs = new BlogInfo[sourceSettings._hostBlogs.Length];
            for (int i = 0; i < sourceSettings._hostBlogs.Length; i++)
            {
                BlogInfo sourceBlog = sourceSettings._hostBlogs[i];
                _hostBlogs[i] = new BlogInfo(sourceBlog.Id, sourceBlog.Name, sourceBlog.HomepageUrl);
            }

            // file upload settings
            _fileUploadSettings = sourceSettings._fileUploadSettings.Clone() as TemporaryFileUploadSettings;

            _pluginSettings = new SettingsPersisterHelper(new MemorySettingsPersister());
            _pluginSettings.CopyFrom(sourceSettings._pluginSettings, true, true);
        }
 public static void SaveFrameButtonDescriptionToSettings(IBlogProviderButtonDescription button, SettingsPersisterHelper settingsKey)
 {
     settingsKey.SetString(ID, button.Id);
     settingsKey.SetString(IMAGE_URL, button.ImageUrl);
     settingsKey.SetByteArray(IMAGE, ImageHelper.GetBitmapBytes(button.Image, new Size(24, 24)));
     settingsKey.SetString(DESCRIPTION, button.Description);
     settingsKey.SetString(CLICK_URL, button.ClickUrl);
     settingsKey.SetString(CONTENT_URL, button.ContentUrl);
     settingsKey.SetSize(CONTENT_DISPLAY_SIZE, button.ContentDisplaySize);
     settingsKey.SetString(NOTIFICATION_URL, button.NotificationUrl);
 }
        public BlogProviderButtonDescriptionFromSettings(SettingsPersisterHelper settingsKey)
        {
            // id
            string id = settingsKey.GetString(ID, String.Empty);

            // image (required)
            string imageUrl = settingsKey.GetString(IMAGE_URL, String.Empty);
            byte[] imageData = settingsKey.GetByteArray(IMAGE, null);
            Bitmap image = null;
            if (imageData != null)
            {
                try
                {
                    image = new Bitmap(new MemoryStream(imageData));
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                }
            }

            // tool-tip text
            string description = settingsKey.GetString(DESCRIPTION, String.Empty);

            // click-url
            string clickUrl = settingsKey.GetString(CLICK_URL, String.Empty);

            // has content
            string contentUrl = settingsKey.GetString(CONTENT_URL, String.Empty);
            Size contentDisplaySize = settingsKey.GetSize(CONTENT_DISPLAY_SIZE, Size.Empty);

            // has notification image
            string notificationUrl = settingsKey.GetString(NOTIFICATION_URL, String.Empty);

            // initialize
            Init(id, imageUrl, image, description, clickUrl, contentUrl, contentDisplaySize, notificationUrl);
        }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the Preferences class (optionally enable change monitoring)
        /// </summary>
        /// <param name="subKey">sub-key name</param>
        /// <param name="monitorChanges">specifies whether the creator intendes to monitor
        /// this prefs object for changes by calling the CheckForChanges method</param>
        public Preferences(string subKey, bool monitorChanges)
        {
            //	Instantiate the settings persister helper object.
            settingsPersisterHelper = ApplicationEnvironment.PreferencesSettingsRoot.GetSubSettings(subKey);

            //	Load preferences
            LoadPreferences();

            //	Monitor changes, if requested.
            if (monitorChanges)
                ConfigureChangeMonitoring(subKey);
        }
        static WebProxySettings()
        {
            _settingsKey = ApplicationEnvironment.PreferencesSettingsRoot.GetSubSettings("WebProxy");
            if (ApplicationDiagnostics.ProxySettingsOverride != null)
            {
                Match m = Regex.Match(ApplicationDiagnostics.ProxySettingsOverride,
                            @"^ ( (?<username>[^@:]+) : (?<password>[^@:]+) @)? (?<host>[^@:]+) (:(?<port>\d*))? $",
                            RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
                if (m.Success)
                {
                    string username = m.Groups["username"].Value;
                    string password = m.Groups["password"].Value;
                    string host = m.Groups["host"].Value;
                    string port = m.Groups["port"].Value;

                    _readSettingsKey = new SettingsPersisterHelper(new MemorySettingsPersister());

                    _readSettingsKey.SetBoolean("Enabled", true);

                    if (!string.IsNullOrEmpty(username))
                        _readSettingsKey.SetString("Username", username);
                    if (!string.IsNullOrEmpty(password))
                        _readSettingsKey.SetEncryptedString("Password", password);

                    _readSettingsKey.SetString("Hostname", host);

                    if (!string.IsNullOrEmpty(port))
                        _readSettingsKey.SetInt32("Port", int.Parse(port, CultureInfo.InvariantCulture));
                }
            }

            if (_readSettingsKey == null)
                _readSettingsKey = _settingsKey;
        }
        public static void Initialize(Assembly rootAssembly, string installationDirectory, string settingsRootKeyName, string productName)
        {
            // initialize name and version based on assembly metadata
            string rootAssemblyPath = rootAssembly.Location;
            FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(rootAssemblyPath);
            _companyName = fileVersionInfo.CompanyName;
            _productName = productName;
            _productVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", fileVersionInfo.ProductMajorPart, fileVersionInfo.ProductMinorPart, fileVersionInfo.ProductBuildPart, fileVersionInfo.ProductPrivatePart);
            _appVersion = new Version(_productVersion);

            Debug.Assert(_appVersion.Build < UInt16.MaxValue &&
                         _appVersion.Revision < UInt16.MaxValue &&
                         _appVersion.Major < UInt16.MaxValue &&
                         _appVersion.Minor < UInt16.MaxValue, "Invalid ApplicationVersion: " + _appVersion);

            // set installation directory and executable name
            _installationDirectory = installationDirectory;
            _mainExecutableName = Path.GetFileName(rootAssemblyPath);

            // initialize icon/user-agent, etc.
            _userAgent = FormatUserAgentString(ProductName, true);
            _productIcon = ResourceHelper.LoadAssemblyResourceIcon("Images.ApplicationIcon.ico");
            _productIconSmall = ResourceHelper.LoadAssemblyResourceIcon("Images.ApplicationIcon.ico", 16, 16);

            // initialize IsHighContrastWhite and IsHighContrastBlack
            InitializeIsHighContrastBlackWhite();

            _settingsRootKeyName = settingsRootKeyName;
            string dataPath;

            // see if we're running in portable mode
#if PORTABLE
            dataPath = Path.Combine(_installationDirectory, "UserData");
            if (Directory.Exists(dataPath))
            {
                _portable = true;
                // initialize application data directories
                _applicationDataDirectory = Path.Combine(dataPath, "AppData\\Roaming");
                _localApplicationDataDirectory = Path.Combine(dataPath, "AppData\\Local");

                // initialize settings
                _userSettingsRoot = new SettingsPersisterHelper(XmlFileSettingsPersister.Open(Path.Combine(dataPath, "UserSettings.xml")));
                _machineSettingsRoot = new SettingsPersisterHelper(XmlFileSettingsPersister.Open(Path.Combine(dataPath, "MachineSettings.xml")));
                _preferencesSettingsRoot = _userSettingsRoot.GetSubSettings(ApplicationConstants.PREFERENCES_SUB_KEY);
            }
            else
#endif
            {
                _portable = false;
                // initialize application data directories.
                _applicationDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), AppDataFolderName);
                _localApplicationDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataFolderName);

                // initialize settings
                _userSettingsRoot = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.CurrentUser, SettingsRootKeyName));
                _machineSettingsRoot = new SettingsPersisterHelper(new RegistrySettingsPersister(Registry.LocalMachine, SettingsRootKeyName));
                _preferencesSettingsRoot = _userSettingsRoot.GetSubSettings(ApplicationConstants.PREFERENCES_SUB_KEY);

                dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }

            _myWeblogPostsFolder = _userSettingsRoot.GetString("PostsDirectory", null);
            if (string.IsNullOrEmpty(_myWeblogPostsFolder))
            {
                if ((_productName == DefaultProductName) && (string.IsNullOrEmpty(dataPath)))
                {
                    throw new DirectoryException(MessageId.PersonalDirectoryFail);
                }
                else
                {
                    _myWeblogPostsFolder = Path.Combine(dataPath, "My Weblog Posts");
                }
            }

            // initialize diagnostics
            InitializeLogFilePath();
            _applicationDiagnostics = new ApplicationDiagnostics(LogFilePath, rootAssembly.GetName().Name);

            if (!Directory.Exists(_applicationDataDirectory))
                Directory.CreateDirectory(_applicationDataDirectory);
            if (!Directory.Exists(_localApplicationDataDirectory))
                Directory.CreateDirectory(_localApplicationDataDirectory);
        }
示例#15
0
 public BlogCredentials(SettingsPersisterHelper settingsRoot, ICredentialsDomain domain)
 {
     _settingsRoot = settingsRoot;
     _domain = domain;
 }
示例#16
0
 public BlogPublishingPluginSettings(SettingsPersisterHelper settings)
 {
     _settings = settings;
 }
 public VideoServiceSettings(string serviceId, SettingsPersisterHelper parentPersister)
 {
     _settings = parentPersister.GetSubSettings(serviceId);
 }
 public PluginSettingsAdaptor(SettingsPersisterHelper settingsHelper)
 {
     SettingsHelper = settingsHelper;
 }