Ejemplo n.º 1
0
        private SettingObject ReadSettingObject(Union <Exception, string> fileTextOrException)
        {
            SettingCopy workingCopy = TemplateSettings.CreateWorkingCopy();

            fileTextOrException.Match(
                whenOption1: exception => exception.Trace(),
                whenOption2: fileText => workingCopy.TryLoadFromText(fileText));

            return(workingCopy.Commit());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="SettingsFile"/> given a valid file path.
        /// The <see cref="LiveTextFile.FileUpdated"/> event is not raised until
        /// the current synchronization context is captured explicitly.
        /// </summary>
        /// <param name="absoluteFilePath">
        /// The absolute file path from which to load the settings file.
        /// If the file does not exist, if access rights are insufficient,
        /// or if the settings file is corrupt, an empty <see cref="SettingsFile"/>
        /// object is returned.
        /// </param>
        /// <param name="workingCopy">
        /// The <see cref="SettingCopy"/> in which the values are stored.
        /// </param>
        /// <returns>
        /// The created <see cref="SettingsFile"/>.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="absoluteFilePath"/> is empty, contains only whitespace, or contains invalid characters
        /// (see also <seealso cref="Path.GetInvalidPathChars"/>), or is in an invalid format,
        /// or is a relative path and its absolute path could not be resolved.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="absoluteFilePath"/> and/or <paramref name="workingCopy"/> are null.
        /// </exception>
        /// <exception cref="IOException">
        /// <paramref name="absoluteFilePath"/> is longer than its maximum length (this is OS specific).
        /// </exception>
        /// <exception cref="System.Security.SecurityException">
        /// The caller does not have sufficient permissions to read the file.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <paramref name="absoluteFilePath"/> is in an invalid format.
        /// </exception>
        public static SettingsFile Create(string absoluteFilePath, SettingCopy workingCopy)
        {
            if (workingCopy == null)
            {
                throw new ArgumentNullException(nameof(workingCopy));
            }

            var settingsFile = new SettingsFile(absoluteFilePath, workingCopy.Commit());

            settingsFile.Settings = settingsFile.ReadSettingObject(settingsFile.LoadedText);
            return(settingsFile);
        }
Ejemplo n.º 3
0
            protected internal override bool ShouldSave(IReadOnlyList <SettingCopy> updates, out string textToSave)
            {
                SettingCopy latestUpdate = updates[updates.Count - 1];

                if (!latestUpdate.EqualTo(RemoteSettings))
                {
                    RemoteSettings = latestUpdate.Commit();
                    textToSave     = CompactSettingWriter.ConvertToJson(RemoteSettings.Map);
                    return(true);
                }

                textToSave = default;
                return(false);
            }