82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System.Linq;
|
|
using xCommons.Extensions;
|
|
using xDataService.Configuration;
|
|
using xDataService.Constants;
|
|
|
|
namespace xDataService.Extensions {
|
|
public static class XDataServiceConfigurationExtensions {
|
|
/// <summary>
|
|
/// Extract Provider enum from Provider Type ...
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Mongo URI from ConnectionString
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static string GetMongoDbURI (this XDataBaseConfiguration source) {
|
|
//
|
|
var parts = source.GetConnectionParts ();
|
|
var result = parts
|
|
.Where (p => p.Trim ().StartsWith ("Uri="))
|
|
.FirstOrDefault ();
|
|
result = result.Replace ("Uri=", "").Trim ();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve Mongo Database Name from Connaction string
|
|
/// </summary>
|
|
/// <param name="source"></param>
|
|
/// <returns></returns>
|
|
public static string GetMongoDbDatabase (this XDataBaseConfiguration 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 XDataBaseConfiguration source) {
|
|
//
|
|
var result = source.ConnectionString.Split (';');
|
|
|
|
//
|
|
return result;
|
|
}
|
|
#endregion
|
|
}
|
|
} |