using System; namespace StardewModdingAPI.Web.Framework.ConfigModels { /// The config settings for mod compatibility list. internal class MongoDbConfig { /********* ** Accessors *********/ /// The MongoDB hostname. public string Host { get; set; } /// The MongoDB username (if any). public string Username { get; set; } /// The MongoDB password (if any). public string Password { get; set; } /// The database name. public string Database { get; set; } /********* ** Public method *********/ /// Get the MongoDB connection string. public string GetConnectionString() { bool isLocal = this.Host == "localhost"; bool hasLogin = !string.IsNullOrWhiteSpace(this.Username) && !string.IsNullOrWhiteSpace(this.Password); return $"mongodb{(isLocal ? "" : "+srv")}://" + (hasLogin ? $"{Uri.EscapeDataString(this.Username)}:{Uri.EscapeDataString(this.Password)}@" : "") + $"{this.Host}/{this.Database}?retryWrites=true&w=majority"; } } }