using System.Linq; using xCommons.Extensions; using xDataService.Configuration; using xDataService.Constants; namespace xDataService.Extensions { public static class XDataServiceConfigurationExtensions { /// /// Extract Provider enum from Provider Type ... /// /// /// public static XDbProviders ToDbProvider (this string source) { // if (source.IsNullOrEmpty ()) { return XDbProviders.None; } // source = source.ToNormalString (); // var result = source == ProviderType.MySQL.ToNormalString () ? XDbProviders.MySQL : source == ProviderType.SQLite.ToNormalString () ? XDbProviders.SQLite : source == ProviderType.SQLServer.ToNormalString () ? XDbProviders.SQLServer : source == ProviderType.MongoDB.ToNormalString () ? XDbProviders.MongoDB : XDbProviders.None; // return result; } /// /// Retrieve Mongo URI from ConnectionString /// /// /// public static string GetMongoDbURI (this XDataServiceConfiguration source) { // var parts = source.GetConnectionParts (); var result = parts .Where (p => p.Trim ().StartsWith ("Uri=")) .FirstOrDefault (); result = result.Replace ("Uri=", "").Trim (); // return result; } /// /// Retrieve Mongo Database Name from Connaction string /// /// /// public static string GetMongoDbDatabase (this XDataServiceConfiguration source) { // var parts = source.GetConnectionParts (); var result = parts .Where (p => p.Trim ().StartsWith ("Database=")) .FirstOrDefault (); result = result.Replace ("Database=", "").Trim (); // return result; } // #region Private ... private static string[] GetConnectionParts (this XDataServiceConfiguration source) { // var result = source.ConnectionString.Split (';'); // return result; } #endregion } }