public ConnectionProviderTests()
        {
            db1 = A.Fake <IDbConnection>();
            db2 = A.Fake <IDbConnection>();

            provider = new PostgreSqlConnectionProvider();
        }
 void DoReconnect()
 {
     DoDispose(false);
     _connection      = PostgreSqlConnectionProvider.CreateConnection(_connectionString);
     ConnectionStatic = _connection;
     _innerDataStore  = new PostgreSqlConnectionProviderCI(_connection, _autoCreateOption);
 }
Esempio n. 3
0
        public async Task MigrationRunner_PicksUpNonCompletedStepsFromPreviousMigrations()
        {
            await DropMigrationInfoTable();
            await PrepareCounterTable(new List <Counter> {
                new Counter {
                    Id = 999, CounterValue = 12
                }
            });

            var db = GetDb();

            var services = new ServiceCollection();

            var provider = new PostgreSqlConnectionProvider();

            provider.Add("yolo", db, true);

            var contextFactory = new PostgreSqlMigrationContextFactory(provider);

            await PostgreSqlSchemaCreator.CreateSchemaIfNotExists(contextFactory.GetContext());


            var runner = new MigrationRunner(
                new LoggerFactory().CreateLogger <MigrationRunner>(),
                new ServiceProviderRapidContainerAdapter(services.BuildServiceProvider()),
                new MigrationEnvironment("staging"),
                A.Fake <IDistributedAppLockProvider>(),
                contextFactory,
                new ReflectionMigrationFinder(new List <Assembly> {
                typeof(MigrationTests).GetAssembly()
            }),
                new PostgreSqlMigrationStorage()
                );

            await InsertMigrationInfo(new MigrationInfo
            {
                Id             = "1",
                Name           = "Migration01",
                StepsCompleted = new List <string> {
                    "Add at column"
                }
            });

            await runner.UpgradeAsync();

            // assert all migrations are marked as complete
            var migrationInfos = await GetAllMigrationInfo();

            Assert.Contains(migrationInfos, x => x.Name == nameof(Migration01) && x.MigrationCompleted);
            Assert.Contains(migrationInfos, x => x.Name == nameof(Migration02) && x.MigrationCompleted);

            // check the state of the db
            var counter999 = await db.QuerySingleAsync <Counter>("select * from __Counter where Id = 999");

            Assert.Equal("sample default value", counter999.Description);
            await DropCounterTable();
        }
        public void WithoutCredentials()
        {
            var connectionString = "Host=myServerName;Port=5432;Database=myDataBase;Username=xxxx;Password=xxxx";
            var options          = new ConnectionProviderOptions
            {
                ConnectionString = connectionString,
                Username         = "",
                Password         = ""
            };
            var mock = new Mock <IOptions <ConnectionProviderOptions> >();

            mock.Setup(x => x.Value).Returns(options);
            var connectionProvider = new PostgreSqlConnectionProvider(mock.Object, _encryptionHelper);

            var connection = connectionProvider.Create();

            // connection string should be unchanged
            Assert.Equal(connection.ConnectionString, connectionString);
        }
        public void WithEncryptedCredentials()
        {
            var connectionString = "Host=myServerName;Port=5432;Database=myDataBase;Username=xxxx;Password=xxxx";
            var options          = new ConnectionProviderOptions
            {
                ConnectionString = connectionString,
                Username         = "******",
                Password         = "******"
            };
            var mock = new Mock <IOptions <ConnectionProviderOptions> >();

            mock.Setup(x => x.Value).Returns(options);
            var connectionProvider = new PostgreSqlConnectionProvider(mock.Object, _encryptionHelper);

            var connection = connectionProvider.Create();
            var expected   = "Host=myServerName;Port=5432;Database=myDataBase;Username=testUsername;Password=testPassword";

            // connection string should have username/password substituded in
            Assert.Equal(connection.ConnectionString, expected);
        }
Esempio n. 6
0
        //[System.Diagnostics.Conditional("XPO")]
        public static void XPOStart()
        {
            try
            {
                //string conString = PostgreSqlConnectionProvider.GetConnectionString("192.168.2.19", 5432, "whm", "whm123", "WHM");
                string conString = PostgreSqlConnectionProvider.GetConnectionString("192.168.1.84", 5432, "postgres", "1", "ors_test");
                DevExpress.Xpo.Metadata.XPDictionary dictionary = new DevExpress.Xpo.Metadata.ReflectionDictionary();
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(conString, AutoCreateOption.DatabaseAndSchema);
                DevExpress.Xpo.XpoDefault.Session = new DevExpress.Xpo.Session(XpoDefault.DataLayer);
                DevExpress.Xpo.Session.DefaultSession.UpdateSchema();
                //DevExpress.Xpo.Helpers.SessionStateStack.SuppressCrossThreadFailuresDetection = true;
                //DevExpress.Xpo.Session.DefaultSession.UpdateSchema();

                //IDataStore store = XpoDefault.GetConnectionProvider(conn, AutoCreateOption.SchemaAlreadyExists);
                //var layer = new ThreadSafeDataLayer(dictionary, store);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                System.Windows.Forms.Application.Exit();
            }
        }
Esempio n. 7
0
        public void import(String filename)
        {
//            CsvEngine engine = new CsvEngine(new CsvOptions("ImportPartyRecord", ';',6));
//            engine.Options.IgnoreFirstLines = 1;
//            Npgsql.NpgsqlConnection con = new Npgsql.NpgsqlConnection("Server=npomash;User Id=pg_adm;Password='******';Database=ermdev;Encoding=UNICODE;");
//            IXpoDataStoreProvider dsp = new ConnectionDataStoreProvider(con);

//            IDbConnection con = PostgreSqlConnectionProvider.CreateConnection("Server=npomash;User Id=pg_adm;Password='******';Database=ermdev;Encoding=UNICODE;");
            IDbConnection con = PostgreSqlConnectionProvider.CreateConnection("Server=alt-dev;User Id=pg_adm;Password='******';Database=ermprod;Encoding=UNICODE;");
//
            IDataLayer   data_layer   = XpoDefault.GetDataLayer(con, AutoCreateOption.None);
            IObjectLayer object_layer = new SimpleObjectLayer(data_layer);
            Int32        count        = 0;

//            ObjectSpaceProvider osp = new ObjectSpaceProvider(dsp);
            //
//            XafApplication application = new ImportApplication();
//            ModuleBase testModule = new ModuleBase();
//            testModule.AdditionalExportedTypes.Add(typeof(crmCParty));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCBusinessman));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCPhysicalParty));
//            testModule.AdditionalExportedTypes.Add(typeof(crmCLegalPerson));
//            application.Modules.Add(testModule);
//            application.Setup("ImportApplication", osp);
//            using (IObjectSpace os = application.CreateObjectSpace()) {
            using (UnitOfWork uow_base = new UnitOfWork(object_layer)) {
                DataTable tbl = (new CsvEngine("ImportPartyRecord", ';', 6)).ReadFileAsDT(filename);
                foreach (DataRow row in tbl.Rows)
                {
                    using (UnitOfWork uow = uow_base.BeginNestedUnitOfWork()) {
                        ImportPartyRecord rec = new ImportPartyRecord();
                        rec.Type = ((String)row.ItemArray[0]).Trim();
                        rec.Code = ((String)row.ItemArray[1]).Trim();
                        rec.INN  = ((String)row.ItemArray[2]).Trim();
                        rec.KPP  = ((String)row.ItemArray[3]).Trim();
                        rec.Name = ((String)row.ItemArray[4]).Trim();
                        rec.Addr = ((String)row.ItemArray[5]).Trim();
                        System.Console.WriteLine(rec.Type + "@" + rec.Code + "@" + rec.INN + "@" + rec.KPP + "@" + rec.Name + "@" + rec.Addr);
                        XPQuery <crmCParty> q_party = new XPQuery <crmCParty>(uow, true);
                        crmCParty           party   = q_party.FirstOrDefault(obj => obj.Code == rec.Code);
                        if (party != null)
                        {
                            continue;
                        }
                        switch (rec.Type)
                        {
                        case "ИП":
                            crmCBusinessman bm = new crmCBusinessman(uow);
                            bm.Code = rec.Code;
                            bm.Name = rec.Name;
                            bm.INN  = rec.INN;
                            bm.AddressLegal.AddressHandmake = rec.Addr;
                            bm.AddressFact.AddressHandmake  = rec.Addr;
                            break;

                        case "ФЛ":
                            crmCPhysicalParty phl = new crmCPhysicalParty(uow);
                            phl.Code = rec.Code;
                            phl.Name = rec.Name;
                            phl.INN  = rec.INN;
                            phl.AddressLegal.AddressHandmake = rec.Addr;
                            phl.AddressFact.AddressHandmake  = rec.Addr;
                            break;

                        default:
                            crmCLegalPerson lp = new crmCLegalPerson(uow);
                            lp.Code = rec.Code;
                            lp.Name = rec.Name;
                            lp.INN  = rec.INN;
                            lp.KPP  = rec.KPP;
                            lp.AddressLegal.AddressHandmake = rec.Addr;
                            lp.AddressFact.AddressHandmake  = rec.Addr;
                            break;
                        }
                        uow.CommitChanges();
                        count++;
                    }
                }
                uow_base.CommitChanges();
                System.Console.WriteLine("All count: " + count);
            }
        }
Esempio n. 8
0
 void DoReconnect()
 {
     DoDispose(false);
     Connection     = PostgreSqlConnectionProvider.CreateConnection(ConnectionString);
     InnerDataStore = new PostgreSqlConnectionProvider(Connection, AutoCreateOption);
 }
Esempio n. 9
0
        /// <summary>
        /// Подключение к БД.
        /// </summary>
        private void Connect()
        {
            switch (DataBaseType)
            {
            case SQLType.Access:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.Access2007:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        AccessConnectionProvider.GetConnectionStringACE(DataBase, ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);

                    //string connctionString = string.Format(@"Data Source={0};Initial Catalog=test;Persist Security Info=True;User ID=sa;Password=qwe+ASDFG", Server);
                    //XpoDefault.DataLayer = XpoDefault.GetDataLayer(connctionString, AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlConnectionProvider.GetConnectionString(Server, DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MSSqlCE:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        MSSqlCEConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.MySQL:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    MySqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                    AutoCreateOption);
                break;

            case SQLType.Oracle:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        OracleConnectionProvider.GetConnectionString(Server, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.Firebird:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        FirebirdConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PostgreSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PostgreSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.SQLite:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        SQLiteConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.VistaDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        VistaDBConnectionProvider.GetConnectionString(DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.PervasiveSql:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        PervasiveSqlConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            case SQLType.DB2:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, User, Password),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        DB2ConnectionProvider.GetConnectionString(Server, DataBase, "", ""),
                        AutoCreateOption);
                }
                break;

            case SQLType.NexusDB:
                if (PasswordNeed)
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, User, Password, DataBase),
                        AutoCreateOption);
                }
                else
                {
                    XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                        NexusDBConnectionProvider.GetConnectionString(Server, "", "", DataBase),
                        AutoCreateOption);
                }
                break;

            default:
                XpoDefault.DataLayer = XpoDefault.GetDataLayer(
                    AccessConnectionProvider.GetConnectionString(DataBase),
                    AutoCreateOption.DatabaseAndSchema);
                break;
            }
        }