예제 #1
0
        public bool CommitSettings()
        {
            lock (ProfileManager.dataLock)
            {
                if (ProfileManager.backupCount == 0)
                {
                    return(false);
                }

                if (ProfileManager.backupCount > 1)
                {
                    ProfileManager.backupCount--;
                    return(false);
                }

                ProfileManager.backupSettings = null;
                ProfileManager.backupCount    = 0;
                RemarkerService service = this.Service;
                if (service == null)
                {
                    return(false);
                }

                service.OnSettingsChanged();
                return(true);
            }
        }
예제 #2
0
        public void SaveSettingsToStorage(RemarkerService service)
        {
            Contract.Requires(service != null);

            lock (ProfileManager.dataLock)
            {
                if (ProfileManager.backupSettings != null)
                {
                    return;
                }
            }

            RegistryKey key = null;

            try
            {
                key = service.Package.UserRegistryRoot.CreateSubKey(ProfileManager.SUBKEY_NAME);
                Debug.Assert(key != null, "key != null");
                key.SetValue("Version", service.Version);

                foreach (var valueName in service.ValueNames)
                {
                    service.Save(key, valueName);
                }
            }
            finally
            {
                if (key != null)
                {
                    key.Close();
                }
            }
        }
예제 #3
0
        public bool RollBackSettings()
        {
            lock (ProfileManager.dataLock)
            {
                if (ProfileManager.backupCount == 0)
                {
                    return(false);
                }

                if (ProfileManager.backupSettings == null)
                {
                    ProfileManager.backupCount--;
                    return(false);
                }

                RemarkerService service = this.Service;
                foreach (var backupSetting in ProfileManager.backupSettings)
                {
                    // Restore the original setting
                    service.Load(backupSetting.Value, backupSetting.Key);
                }

                return(true);
            }
        }
예제 #4
0
        public void ResetSettings(RemarkerService service)
        {
            Contract.Requires(service != null);

            service.Package.UserRegistryRoot.DeleteSubKey(ProfileManager.SUBKEY_NAME, false);
            this.LoadSettingsFromStorage(this.Service);
        }
예제 #5
0
        public void SaveSettingsToXml(IVsSettingsWriter writer)
        {
            RemarkerService service = this.Service;

            var stringBuilder = new StringBuilder();

            foreach (var valueName in service.ValueNames)
            {
                stringBuilder.Append(valueName);
                stringBuilder.Append(";");
                service.Save(writer, valueName);
            }

            writer.WriteSettingLong("Version", service.Version);
            writer.WriteSettingString("ValueKeys", stringBuilder.ToString());
        }
예제 #6
0
        public void LoadSettingsFromXml(IVsSettingsReader reader)
        {
            string valueKeysString;

            reader.ReadSettingString("ValueKeys", out valueKeysString);
            RemarkerService service = this.Service;

            foreach (var valueKey in valueKeysString.Split(';').Where(
                         valueKey => !string.IsNullOrWhiteSpace(valueKey)))
            {
                try
                {
                    service.Load(reader, valueKey);
                }
                catch (Exception)
                {
                }
            }
        }
예제 #7
0
        public bool ProtectSettings()
        {
            lock (ProfileManager.dataLock)
            {
                if (ProfileManager.backupSettings != null)
                {
                    ProfileManager.backupCount++;
                    return(false);
                }

                RemarkerService service = this.Service;

                ProfileManager.backupSettings = new Dictionary <string, string>();
                foreach (var valueName in service.ValueNames)
                {
                    ProfileManager.backupSettings.Add(valueName, service.ReadValue(valueName));
                }
                ProfileManager.backupCount = 1;
                return(true);
            }
        }
예제 #8
0
        public void LoadSettingsFromStorage(RemarkerService service)
        {
            Contract.Requires(service != null);

            lock (ProfileManager.dataLock)
            {
                if (ProfileManager.backupSettings != null)
                {
                    return;
                }
            }

            RegistryKey key = null;

            try
            {
                key = service.Package.UserRegistryRoot.OpenSubKey(ProfileManager.SUBKEY_NAME);

                foreach (var valueName in service.ValueNames)
                {
                    service.Load(key, valueName);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(string.Format("Remarker::LoadSettingsFromStorage: {0}",
                                              ex));
            }
            finally
            {
                if (key != null)
                {
                    key.Close();
                }
            }
        }