Exemple #1
0
        /// <summary>
        /// Validates specified configuration. Will throw if data is invalid.
        /// </summary>
        /// <param name="config">Configuration data to validate</param>
        public void ValidateConfiguration(CompanionCubeConfig config)
        {
            // validate the config
            if (config == null || config.Version == null || config.Discord == null || /*config.PostgreSQL == null ||*/ config.Lavalink == null || config.YouTube == null)
            {
                throw new ArgumentNullException(nameof(config), "Configuration data, or one of its parts, is null.");
            }

            // validate config version
            if (config.Version.Configuration != this.ConfigVersion)
            {
                throw new InvalidDataException("Configuration data version mismatch.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Saves the specified configuration to specified file. The file will be overwritten.
        /// </summary>
        /// <param name="config">Configuration data to save.</param>
        /// <param name="file">File to save the data to.</param>
        /// <returns></returns>
        public async Task SaveConfigurationAsync(CompanionCubeConfig config, FileInfo file)
        {
            // validate the config first
            //this.ValidateConfiguration(config);

            // serialize the config
            var json = JsonConvert.SerializeObject(config, Formatting.Indented);

            // write the config to a file
            using (var fs = file.Create())
                using (var sr = new StreamWriter(fs, CompanionCubeUtilities.UTF8))
                {
                    await sr.WriteLineAsync(json).ConfigureAwait(false);

                    await sr.FlushAsync().ConfigureAwait(false);
                }
        }