예제 #1
0
        /// <summary>
        /// Load the configuration from a .bot file.
        /// </summary>
        /// <param name="file">Path to bot file. </param>
        /// <param name="secret">Secret to use to decrypt the file on disk. </param>
        /// <returns><see cref="MrConfigurationManager"/>.</returns>
        public static MrConfigurationManager Load(string file, string secret = null)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new ArgumentNullException(nameof(file));
            }

            return(MrConfigurationManager.LoadAsync(file, secret).GetAwaiter().GetResult());
        }
예제 #2
0
        /// <summary>
        /// Load the bot configuration by looking in a folder and loading the first .bot file in the folder.
        /// </summary>
        /// <param name="folder">Folder to look for bot files. </param>
        /// <param name="secret">Secret to use to encrypt keys. </param>
        /// <returns><see cref="Task"/> of <see cref="MrConfigurationManager"/>.</returns>
        public static async Task <MrConfigurationManager> LoadFromFolderAsync(string folder, string secret = null)
        {
            if (string.IsNullOrEmpty(folder))
            {
                throw new ArgumentNullException(nameof(folder));
            }

            var file = Directory.GetFiles(folder, "*.bot", SearchOption.TopDirectoryOnly).FirstOrDefault();

            if (file != null)
            {
                return(await MrConfigurationManager.LoadAsync(file, secret).ConfigureAwait(false));
            }

            throw new FileNotFoundException($"Error: no bot file found in {folder}. Choose a different location or use msbot init to create a.bot file.");
        }