public DbConnection CreateConnection() { DbProviderFactory factory = null; if (this._dbProvider.ProviderName.ToLower().Contains("oracle")) { factory = new OracleClientFactory(); } else { factory = DataUtils.GetDbProviderFactory(this._dbProvider.ProviderName); } DbConnection connection = factory.CreateConnection(); if (connection != null) { connection.ConnectionString = this._connectionString; return(connection); } else { return(null); } }
public static void Main(string[] args) { //update tb_medidor_ene set DT_HR_INSERCAO = :par0,DT_HR_INSTANTE // = :par1,vl_eneat_rec_cp = :par2 WHERE (((cd_medidor = :par3) And // (DT_HR_INSTANTE = :par4)) And((vl_eneat_rec_cp = :par5) Or //(vl_eneat_rec_cp is NULL))) var factory = new OracleClientFactory(); var client = SharpFactory.Default.CreateDataClient(factory, "Data Source=//localhost:1521/XE;User Id=W2E_PIM;Password=W2E_PIM;"); var data = DateTime.Today.AddMinutes(5); var colunas = new[] { "DT_HR_INSERCAO", "DT_HR_INSTANTE", "vl_eneat_rec_cp" }; var valores = new object[] { DateTime.Now, data, 10 }; var filter = GetFilter(1, data); filter = GetFilterValor(filter, 10); var count = client.Update .Table("tb_medidor_ene") .SetColumns(colunas) .ToValues(valores) .Where(filter); Console.WriteLine("Done"); }
/// <summary> /// 获取指定数据库类型的DbProviderFactory /// </summary> /// <param name="providerType"></param> /// <returns></returns> public static DbProviderFactory GetDbProviderFactory(DbProviderType providerType) { DbProviderFactory Ada = null; switch (providerType) { case DbProviderType.SQLite: { // Ada = new SQLiteFactory(); break; } case DbProviderType.Oracle: { Ada = new OracleClientFactory(); break; } default: { Ada = ProviderFactory.ImportDbProviderFactory(providerType); break; } } return(Ada); }
public void TestThatCreateDataQueryerThrowsArgumentNullExceptionIfDataManipulatorsIsNull() { var oracleClientFactory = new OracleClientFactory(); Assert.That(oracleClientFactory, Is.Not.Null); Assert.Throws <ArgumentNullException>(() => oracleClientFactory.CreateDataQueryer(null)); }
public void TestThatCreateDataQueryerCreatesDataQueryerForOracle() { var oracleClientFactory = new OracleClientFactory(); Assert.That(oracleClientFactory, Is.Not.Null); using (var dataQueryer = oracleClientFactory.CreateDataQueryer(MockRepository.GenerateMock <IDataManipulators>())) { Assert.That(dataQueryer, Is.Not.Null); dataQueryer.Dispose(); } }
public void TestThatCrateCreatesOracleClient() { var oracleClientFactory = new OracleClientFactory(); Assert.That(oracleClientFactory, Is.Not.Null); using (var oracleClient = oracleClientFactory.Create()) { Assert.That(oracleClient, Is.Not.Null); oracleClient.Dispose(); } }
/// <summary> /// 生成Connection对象 /// </summary> private OracleConnection CreateConnection(string connectString, string providerName) { OracleConnection connection = null; connection = new OracleClientFactory().CreateConnection() as OracleConnection; connection.ConnectionString = connectString; this.ConnectionString = connectString; this.Connection = connection; return(this.Connection); }
public ReportGenerator() { var node = new Uri("http://localhost:9200"); var settings = new ConnectionSettings(node) .DefaultMappingFor <CustomerLogin>(m => m.IndexName("customer_login")) .DefaultMappingFor <CustomerLogin>(m => m.IdProperty(p => p.Id)); _elasticClient = new ElasticClient(settings); var f = new OracleClientFactory(); _dbConnection = f.CreateConnection(); _dbConnection.ConnectionString = "User Id=c##khiem;Password=123456;Data Source=localhost:1521/orcl;Pooling=true"; }
/// <summary> /// 通过配置文件中的ProviderName来自动生成Connection对象 /// </summary> /// <param name="databaseName">在appsetting中配置的数据库连接对象名称</param> /// <returns></returns> public IDbConnection CreateConnection(string databaseName) { bool encrypt = TwinkleContext.Config.GetValue <bool>($"ConnectionStrings:{databaseName}:Encrypt"); string connectString = TwinkleContext.Config.GetValue <string>($"ConnectionStrings:{databaseName}:ConnectString"); //如果连接字符串被加密了 需要解密 if (encrypt) { connectString = DataCipher.RSADecrypt(connectString); } string providerName = TwinkleContext.Config.GetValue <string>($"ConnectionStrings:{databaseName}:ProviderName"); IDbConnection connection = null; switch (providerName) { case "System.Data.SqlClient": connection = SqlClientFactory.Instance.CreateConnection(); break; case "Oracle.ManagedDataAccess.Client": connection = new OracleClientFactory().CreateConnection(); break; case "MySql.Data.MySqlClient": connection = new MySqlClientFactory().CreateConnection(); break; default: throw new DataException("There is no suitable Provider for creating IDbConnection"); } connection.ConnectionString = connectString; this.Connection = connection; return(connection); }
static DataTable GetDataSources() { OracleClientFactory factory=new OracleClientFactory(); if (factory.CanCreateDataSourceEnumerator) { DbDataSourceEnumerator dsenum = factory.CreateDataSourceEnumerator(); DataTable dt1 = dsenum.GetDataSources(); dt1.Columns.Remove("Protocol"); dt1.Columns.Remove("Port"); dt1.Columns.Add("Selected",System.Type.GetType("System.Boolean")).SetOrdinal(0); dt1.Columns.Add("User",System.Type.GetType("System.String")); dt1.Columns.Add("Password",System.Type.GetType("System.String")); dt1.Columns.Add("RealPassword",System.Type.GetType("System.String")); dt1.Columns.Add("Result",System.Type.GetType("System.String")); foreach(DataRow row in dt1.Rows) { row["Selected"]=false; row["User"]=row["Password"]=row["RealPassword"]=row["Result"]=""; } return dt1; } else return null; }
public static void X() { var factory = new OracleClientFactory(); //factory.GetType().Namespace; }
public void TestThatConstructorInitializeOracleClientFactory() { var oracleClientFactory = new OracleClientFactory(); Assert.That(oracleClientFactory, Is.Not.Null); }
public void TestThatDataRepositoryGetsDataFromOracle() { var containerMock = MockRepository.GenerateMock <IContainer>(); var informationLoggerMock = MockRepository.GenerateMock <IInformationLogger>(); informationLoggerMock.Expect(m => m.LogInformation(Arg <string> .Is.NotNull)) .WhenCalled(e => Debug.WriteLine(e.Arguments[0])) .Repeat.Any(); var metadataRepository = new OldToNewMetadataRepository(RepositoryTestHelper.GetSourcePathForOracleTest(), new ConfigurationValues()); Assert.That(metadataRepository, Is.Not.Null); ICollection <IDataManipulator> dataMainpulatorCollection; using (var windsorContainer = new WindsorContainer()) { windsorContainer.Register(Component.For <IContainer>().Instance(containerMock).LifeStyle.Transient); windsorContainer.Register(Component.For <IInformationLogger>().Instance(informationLoggerMock).LifeStyle.Transient); windsorContainer.Register(Component.For <IMetadataRepository>().Instance(metadataRepository).LifeStyle.Transient); var dataManipulatorsConfigurationProvider = new DataManipulatorsConfigurationProvider(); dataManipulatorsConfigurationProvider.AddConfiguration(windsorContainer); dataMainpulatorCollection = windsorContainer.ResolveAll <IDataManipulator>(); windsorContainer.Dispose(); } containerMock.Expect(m => m.ResolveAll <IDataManipulator>()) .Return(dataMainpulatorCollection.ToArray()) .Repeat.Any(); var oracleClientFactory = new OracleClientFactory(); Assert.That(oracleClientFactory, Is.Not.Null); var dataManipulators = new DataManipulators(containerMock); Assert.That(dataManipulators, Is.Not.Null); Assert.That(dataManipulators, Is.Not.Empty); var dataRepository = new OracleDataRepository(oracleClientFactory, dataManipulators); Assert.That(dataRepository, Is.Not.Null); containerMock.Expect(m => m.Resolve <IDataRepository>()) .Return(dataRepository) .Repeat.Any(); var startTime = DateTime.MinValue; var numberOfRecords = 0; dataRepository.OnHandleData += (s, e) => { Assert.That(s, Is.Not.Null); Assert.That(e, Is.Not.Null); Assert.That(e.Table, Is.Not.Null); Assert.That(e.Data, Is.Not.Null); numberOfRecords += e.Data.Count(); if (e.EndOfData) { // ReSharper disable AccessToModifiedClosure Debug.WriteLine("{0} has been selected for the table named {1} in {2}", numberOfRecords, e.Table.NameTarget, new TimeSpan(DateTime.Now.Ticks - startTime.Ticks)); // ReSharper restore AccessToModifiedClosure numberOfRecords = 0; } }; var dataSource = metadataRepository.DataSourceGet(); Assert.That(dataSource, Is.Not.Null); Assert.That(dataSource.Tables, Is.Not.Null); Assert.That(dataSource.Tables, Is.Not.Empty); foreach (var table in dataSource.Tables) { startTime = DateTime.Now; dataRepository.DataGetFromTable(table); } }