コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsEntryValue"/> class.
 /// </summary>
 /// <param name="profile">The profile this <see cref="SettingsEntryValue"/>belongs to.</param>
 /// <param name="name">The name associated to this <see cref="SettingsEntryValue"/>.</param>
 /// <param name="value">The value to associate to this <see cref="SettingsEntryValue"/>.</param>
 internal SettingsEntryValue(SettingsProfile profile, UFile name, object value)
     : base(profile, name)
 {
     Value        = value;
     ShouldNotify = true;
 }
コード例 #2
0
 static SettingsService()
 {
     ProfileList.Add(DefaultProfile);
     currentProfile = DefaultProfile;
     Logger         = new LoggerResult();
 }
コード例 #3
0
        /// <summary>
        /// Loads a settings profile from the given file.
        /// </summary>
        /// <param name="filePath">The path of the file from which to load settings.</param>
        /// <param name="setAsCurrent">If <c>true</c>, the loaded profile will also be set as <see cref="CurrentProfile"/>.</param>
        /// <param name="parent">The profile to use as parent for the loaded profile. If <c>null</c>, a default profile will be used.</param>
        /// <returns><c>true</c> if settings were correctly loaded, <c>false</c> otherwise.</returns>
        public static SettingsProfile LoadSettingsProfile(UFile filePath, bool setAsCurrent, SettingsProfile parent = null)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            if (!File.Exists(filePath))
            {
                Logger.Error("Settings file [{0}] was not found", filePath);
                return(null);
            }

            SettingsProfile profile;

            try
            {
                SettingsFile settingsFile;
                using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    settingsFile = (SettingsFile)YamlSerializer.Deserialize(stream);
                }
                profile = new SettingsProfile(parent ?? DefaultProfile)
                {
                    FilePath = filePath
                };

                foreach (var settings in settingsFile.Settings)
                {
                    SettingsKey key;
                    var         value = settings.Value;
                    if (SettingsKeys.TryGetValue(settings.Key, out key))
                    {
                        value = key.ConvertValue(value);
                    }
                    profile.SetValue(settings.Key, value);
                }
            }
            catch (Exception e)
            {
                Logger.Error("Error while loading settings file [{0}]: {1}", e, filePath, Extensions.StringExtensions.FormatExceptionForReport(e));
                return(null);
            }

            ProfileList.Add(profile);
            if (setAsCurrent)
            {
                CurrentProfile = profile;
            }

            var handler = SettingsFileLoaded;

            if (handler != null)
            {
                SettingsFileLoaded(null, new SettingsFileLoadedEventArgs(filePath));
            }
            return(profile);
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangesValidatedEventArgs"/> class.
 /// </summary>
 /// <param name="profile">The profile in which changes have been validated.</param>
 public ChangesValidatedEventArgs(SettingsProfile profile)
 {
     Profile = profile;
 }
コード例 #5
0
 /// <summary>
 /// Sets the value of this settings key in the given profile.
 /// </summary>
 /// <param name="value">The new value to set.</param>
 /// <param name="profile">The profile in which to set the value. If <c>null</c>, it will look in the <see cref="SettingsService.CurrentProfile"/>.</param>
 public void SetValue(T value, SettingsProfile profile = null)
 {
     profile = profile ?? SettingsService.CurrentProfile;
     profile.SetValue(Name, value);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SettingsProfile"/> class.
 /// </summary>
 /// <param name="parentProfile">The parent profile.</param>
 internal SettingsProfile(SettingsProfile parentProfile)
 {
     this.parentProfile = parentProfile;
 }