Example #1
0
        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);
        }
Example #2
0
 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());
     });
 }
Example #4
0
        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();
            }
        }
Example #6
0
 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;
 }
Example #8
0
 public void SaveConnection(NamedConnectionElement element)
 {
 }
Example #9
0
 public static DbConnectionStringBuilder CreateConnectionStringBuilder(this NamedConnectionElement element)
 {
     return(element.GetExportAttribute().CreateConnectionStringBuilder());
 }
Example #10
0
 public static IDataProviderController GetDataProviderController(this NamedConnectionElement element)
 {
     return(Activator.CreateInstance(element.GetDataProviderType()) as IDataProviderController);
 }
Example #11
0
 public static Type GetDataProviderType(this NamedConnectionElement element)
 {
     return(Type.GetType(element.ControllerType));
 }