/// <summary>
        /// Loads the options from a TOML file in the directory specified in the <see cref="FilePath"/> property.
        /// If the <see cref="FilePath"/> property is null or empty will default to "/USER/Pellucid/pellucid.console-options[id].toml",
        /// where the "01" is the application number, padded to 2 places on a processor and the RoomId on a server.
        /// <para>If it exists, this file is automatically loaded when the application first starts.</para>
        /// </summary>
        /// <returns>An <see cref="Options"/> object.</returns>
        private static Options Load()
        {
            ValidateFilePath();

            if (File.Exists(FilePath))
            {
                try
                {
                    var options = MinimalTomlParser.DeserializeFromDisk <Options>(FilePath);
                    CrestronEnvironment.ProgramStatusEventHandler -= options.HandleAutoLoad;

                    if (options.AutoSave)
                    {
                        CrestronEnvironment.ProgramStatusEventHandler += options.HandleAutoLoad;
                    }

                    return(options);
                }
                catch (Exception ex)
                {
                    Logger.LogWarning("Options", "Exception while loading Evands.Pellucid options from disk. Using the defaults instead.\n{0}", ex.ToString());
                    return(new Options().WithDefaults());
                }
            }
            else
            {
                return(new Options().WithDefaults());
            }
        }
        /// <summary>
        /// Saves the options to a TOML file to the location specified by the <see cref="FilePath"/> property.
        /// <para>This file is automatically saved when the program is shutting down if the <see cref="AutoSave"/> property is true.</para>
        /// </summary>
        public void Save()
        {
            ValidateFilePath();

            try
            {
                MinimalTomlParser.SerializeToDisk(this, FilePath);
            }
            catch (Exception ex)
            {
                ErrorLog.Exception("Pellucid.Options", ex);
                Debug.WriteException(this, ex, "Exception while saving Pellucid.Options to disk.");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the options from a TOML file in the application directory.
        /// <para>If it exists, this file is automatically loaded when the application first starts.</para>
        /// </summary>
        /// <returns>An <see cref="Options"/> object.</returns>
        private static Options Load()
        {
            var path = Path.Combine(InitialParametersClass.ProgramDirectory.ToString(), "pellucid.console-options.toml");

            if (File.Exists(path))
            {
                try
                {
                    var options = MinimalTomlParser.DeserializeFromDisk <Options>(path);
                    return(options);
                }
                catch (Exception ex)
                {
                    ConsoleBase.WriteLine("Exception while loading Evands.Pellucid options from disk. Using the defaults instead.\n{0}", ex.ToString());
                    return(new Options().WithDefaults());
                }
            }
            else
            {
                return(new Options().WithDefaults());
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the options from a TOML file in the directory specified in the <see cref="FilePath"/> property.
        /// <para>If it exists, this file is automatically loaded when the application first starts.</para>
        /// </summary>
        /// <returns>An <see cref="Options"/> object.</returns>
        private static Options Load()
        {
#if !TEST
            if (File.Exists(FilePath))
            {
                try
                {
                    var options = MinimalTomlParser.DeserializeFromDisk <Options>(FilePath);
                    return(options);
                }
                catch (Exception ex)
                {
                    Logger.LogWarning("Options", "Exception while loading Evands.Pellucid options from disk. Using the defaults instead.\n{0}", ex.ToString());
                    return(new Options().WithDefaults());
                }
            }
            else
            {
                return(new Options().WithDefaults());
            }
#else
            return(new Options().WithDefaults());
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves the options to a TOML file in the application directory.
        /// <para>This file is automatically saved when the program is shutting down.</para>
        /// </summary>
        public void Save()
        {
            var path = Path.Combine(InitialParametersClass.ProgramDirectory.ToString(), "pellucid.console-options.toml");

            MinimalTomlParser.SerializeToDisk(this, path);
        }