public void AddNamedConnectionPositive() { var settings = MonahrqConfiguration.SettingsGroup.MonahrqSettings(); Assert.AreEqual(0, settings.NamedConnections.Count); var expected = new NamedConnectionElement(); var builder = new System.Data.OleDb.OleDbConnectionStringBuilder(); builder.Provider = "foobar"; expected.ConnectionString = builder.ConnectionString; expected.Name = "SomeName"; expected.SelectFrom = "Some Table"; expected.ControllerType = typeof(object).AssemblyQualifiedName; settings.NamedConnections.Add(expected); MonahrqConfiguration.Save(settings); var newSettings = MonahrqConfiguration.SettingsGroup.MonahrqSettings(); Assert.AreEqual(1, newSettings.NamedConnections.Count); var target = newSettings.NamedConnections[expected.Name]; Assert.AreEqual(expected.Name, target.Name); Assert.AreEqual(expected.ControllerType, target.ControllerType); Assert.AreEqual(expected.SelectFrom, target.SelectFrom); Assert.AreEqual(expected.ConnectionString, target.ConnectionString); }
public void Reset(IDataProviderController provider) { Builder = provider.GetExportAttribute().CreateConnectionStringBuilder(); Configuration = new NamedConnectionElement() { ControllerType = provider.GetType().AssemblyQualifiedName }; }
/// <summary> /// Initializes a new instance of the <see cref="NamedConnectionModel"/> class. /// </summary> /// <param name="element">The element.</param> public NamedConnectionModel(NamedConnectionElement element) { Configuration = element; LazyProviderExport = new Lazy <IDataProviderControllerExportAttribute>(() => { return(Configuration.GetExportAttribute()); }); }
public void SaveConnection(NamedConnectionElement element) { var settings = Monahrq.Infrastructure.Configuration.MonahrqConfiguration.SettingsGroup.MonahrqSettings(); var current = settings.NamedConnections[element.Name]; if (current != null) { settings.NamedConnections.Remove(current); } settings.NamedConnections.Add(element); Monahrq.Infrastructure.Configuration.MonahrqConfiguration.Save(settings); Events.GetEvent <SavedEvent>().Publish(element); }
public void TestConnection(NamedConnectionElement p) { var prov = Activator.CreateInstance(Type.GetType(p.ControllerType)) as IDataProviderController; var conn = prov.ProviderFactory.CreateConnection(); conn.ConnectionString = p.ConnectionString; conn.Open(); if (!string.IsNullOrEmpty(p.SelectFrom)) { var cmd = conn.CreateCommand(); cmd.CommandText = string.Format("Select * from [{0}]", p.SelectFrom); cmd.ExecuteReader(); } }
public static IDataProviderControllerExportAttribute GetExportAttribute(this NamedConnectionElement element) { try { if (string.IsNullOrEmpty(element.ControllerType)) { return(null); } var provType = element.GetDataProviderType(); return(element.GetDataProviderType().GetCustomAttributes(typeof(IDataProviderControllerExportAttribute), true) .FirstOrDefault() as IDataProviderControllerExportAttribute); } catch { return(null); } }
/// <summary> /// Initializes a new instance of the <see cref="DeletingConnectionEventArgs"/> class. /// </summary> /// <param name="connection">The connection.</param> public DeletingConnectionEventArgs(NamedConnectionElement connection) { Connection = connection; }
public void SaveConnection(NamedConnectionElement element) { }
public static DbConnectionStringBuilder CreateConnectionStringBuilder(this NamedConnectionElement element) { return(element.GetExportAttribute().CreateConnectionStringBuilder()); }
public static IDataProviderController GetDataProviderController(this NamedConnectionElement element) { return(Activator.CreateInstance(element.GetDataProviderType()) as IDataProviderController); }
public static Type GetDataProviderType(this NamedConnectionElement element) { return(Type.GetType(element.ControllerType)); }