Esempio n. 1
0
        public static DbConnection connect(sqlservers server, string database = null)
        {
            var con = new DbConnectionFactory(server, ConnectionStringFactory.CreateConnectionString(server, database)).Create();

            con.Open();
            return(con);
        }
Esempio n. 2
0
        public async Task It_should_alert_ADO_NET_SQL_queries_with_syntax_error()
        {
            // Given
            var logger            = new TestLogger();
            var profiler          = new LongRunningQueryProfiler(logger, threshold: 100.Milliseconds());
            var connectionFactory = new DbConnectionFactory(ConnectionString, profiler);
            var con = await connectionFactory.Open();

            // When
            var cmd = con.CreateCommand();

            cmd.CommandTimeout = 1;
            cmd.CommandText    = "WAITFOR DELAY '00:00:00.200'; EXECUTE sp_executesql N'BOO!';";
            try
            {
                await cmd.ExecuteNonQueryAsync();
            }
            catch (SqlException ex)
            {
                // Ignore it
            }

            // Then
            Assert.That(logger.Warnings.Any(e => e.sql == cmd.CommandText), Is.True);
        }
Esempio n. 3
0
 protected void WithDb(Action <IDbConnection> operation)
 {
     using (var db = DbConnectionFactory.Open())
     {
         Logic.Init(db, GetSession(), Request, AppSettings);
         operation(db);
     }
 }
        private AdoNetMessageQueueProvider CreateQueueProvider()
        {
            Func <IDbConnection> dbFactory = () => DbConnectionFactory.Open(true);
            var serializer = new MessagingSerializer(typeof(AdoNetMessageDto));
            var provider   = new AdoNetMessageQueueProvider(dbFactory, serializer);

            return(provider);
        }
Esempio n. 5
0
 protected object WithDb(Func <IDbConnection, object> operation)
 {
     using (var db = DbConnectionFactory.Open())
     {
         Logic.Init(db, GetSession(), Request, AppSettings);
         return(operation(db));
     }
 }
Esempio n. 6
0
 public void UsingDbConnectionFactory(Action <IDbConnection> action)
 {
     using (var factory = new DbConnectionFactory(connectionString, PostgreSqlProvider.Instance))
     {
         using (var conn = factory.Open())
         {
             action(conn);
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Select用の実行機能を提供します。
 /// </summary>
 /// <typeparam name="T">結果保存用の型</typeparam>
 /// <param name="connectionName">コネクションストリング</param>
 /// <param name="query">クエリ</param>
 /// <param name="param">パラメータ</param>
 /// <returns>実行結果</returns>
 public static IEnumerable <T> Query <T>(string connectionName, string query, object param = null)
 {
     OutputLog(connectionName, query, param);
     using (var cn = new DbConnectionFactory(connectionName).Create())
     {
         cn.Open();
         var result = cn.Query <T>(query, param);
         return(result);
     }
 }
Esempio n. 8
0
 // GET: Installation/Home
 public ActionResult Index()
 {
     try
     {
         DbConnectionFactory.Open(true);
     }
     catch
     {
         ViewBag.Ready = false;
     }
     return(View());
 }
Esempio n. 9
0
        public virtual List <Transaction> GetBySubscriptionIds(List <long> subscriptionIds)
        {
            if (subscriptionIds == null || subscriptionIds.Count < 1)
            {
                throw new ArgumentException("GetBySubscriptionIds: subscriptionIds is null");
            }

            using (var dbConnection = DbConnectionFactory.Open())
            {
                return(dbConnection.Select <Transaction>(t => Sql.In(t.SubscriptionId, subscriptionIds)).ToList());
            }
        }
Esempio n. 10
0
        public virtual List <Transaction> GetByGatewayTransactionIds(List <string> gatewayTransactionIds)
        {
            if (gatewayTransactionIds == null || gatewayTransactionIds.Count < 1)
            {
                throw new ArgumentException("GetByGatewayTransactionIds: gatewayTransactionIds is null");
            }

            using (var dbConnection = DbConnectionFactory.Open())
            {
                return(dbConnection.Select <Transaction>(t => Sql.In(t.GatewayTransactionId, gatewayTransactionIds)).ToList());
            }
        }
Esempio n. 11
0
        public virtual List <Transaction> GetByNotificationStatusIds(List <long> notificationStatusIds)
        {
            if (notificationStatusIds == null || notificationStatusIds.Count < 1)
            {
                throw new ArgumentException("GetByNotificationStatusIds: notificationStatusIds is null");
            }

            using (var dbConnection = DbConnectionFactory.Open())
            {
                return(dbConnection.Select <Transaction>(t => Sql.In(t.TransactionNotificationStatusId, notificationStatusIds)).ToList());
            }
        }
Esempio n. 12
0
 public static ConnectionResultSet TestConnection(sqlservers server, string database = null)
 {
     try
     {
         using (var con = new DbConnectionFactory(server, ConnectionStringFactory.CreateConnectionString(server, database)).Create())
         {
             con.Open();
         }
     }
     catch (Exception ex)
     {
         return(new ConnectionResultSet(ex));
     }
     return(new ConnectionResultSet());
 }
Esempio n. 13
0
        public async Task It_should_not_alert_ADO_NET_SQL_queries()
        {
            // Given
            var logger            = new TestLogger();
            var profiler          = new LongRunningQueryProfiler(logger, threshold: 1000.Milliseconds());
            var connectionFactory = new DbConnectionFactory(ConnectionString, profiler);
            var con = await connectionFactory.Open();

            // When
            var cmd = con.CreateCommand();

            cmd.CommandText = "SELECT '123' as 'Test'";
            using (var dtr = await cmd.ExecuteReaderAsync())
                while (await dtr.ReadAsync())
                {
                }

            // Then
            Assert.That(logger.Warnings, Is.Empty);
        }
Esempio n. 14
0
 public static int Execute(string connectionName, string update, object param = null)
 {
     OutputLog(connectionName, update, param);
     using (var cn = new DbConnectionFactory(connectionName).Create())
     {
         int result = 0;
         cn.Open();
         using (var tr = cn.BeginTransaction())
         {
             try
             {
                 result = cn.Execute(update, param, tr);
                 tr.Commit();
             }
             catch
             {
                 tr.Rollback();
             }
         }
         return(result);
     }
 }
Esempio n. 15
0
        public virtual List <Transaction> GetBySubscriptionOwnerIds(List <long> subscriptionOwnerIds)
        {
            if (subscriptionOwnerIds == null || subscriptionOwnerIds.Count < 1)
            {
                throw new ArgumentException("GetBySubscriptionOwnerIds: subscriptionOwnerIds is null");
            }

            using (var dbConnection = DbConnectionFactory.Open())
            {
                var merchantIds = string.Format("{0}", subscriptionOwnerIds[0]);

                for (var i = 1; i < subscriptionOwnerIds.Count; i++)
                {
                    merchantIds = string.Format("{0}, {1}", merchantIds, subscriptionOwnerIds[i]);
                }

                var sqlQuery = string.Format("select [Transaction].* from [Transaction] " +
                                             "join Subscription on Subscription.Id = [Transaction].SubscriptionId " +
                                             "join SubscriptionOwner on SubscriptionOwner.Id = Subscription.SubscriptionOwnerId " +
                                             "where SubscriptionOwner.Id in ({0})", merchantIds);

                return(dbConnection.Select <Transaction>(sqlQuery).ToList <Transaction>());
            }
        }
 private IDbConnection CreateConnection(IServiceLocator arg)
 {
     return(DbConnectionFactory.Open(true));
 }
        private IAdoNetUnitOfWork CreateUnitOfWork(IServiceLocator arg)
        {
            var con = DbConnectionFactory.Open(true);

            return(new OurUnitOfWork(con, true));
        }
Esempio n. 18
0
        public override void ValidateInsertData(Transaction data)
        {
            if (data == null)
            {
                throw new ArgumentException("Transaction must not be null");
            }

            if (data.SubscriptionId <= default(long))
            {
                throw new ArgumentException("Transaction: SubscriptionId must not be null");
            }

            if (string.IsNullOrEmpty(data.GatewayTransactionId))
            {
                throw new ArgumentException("Transaction: GatewayTransactionId must not be null");
            }

            if (data.TransactionTypeId <= default(long))
            {
                throw new ArgumentException("Transaction: TransactionTypeId  must not be null");
            }

            if (data.TransactionStatusId <= default(long))
            {
                throw new ArgumentException("Transaction: TransactionStatusId must not be null");
            }

            if (data.CurrencyId <= default(long))
            {
                throw new ArgumentException(string.Format("Transaction: {0} is an invalid amount for a Credit Transaction", data.Amount));
            }

            if (string.IsNullOrEmpty(data.GatewayResponse))
            {
                throw new ArgumentException("Transaction: GatewayResponse must not be null");
            }

            if (data.TransactionNotificationStatusId <= default(long))
            {
                throw new ArgumentException("Transaction: TransactionNotificationStatusId must not be null");
            }

            // Now we track down any foreign key constraints
            using (var dbConnection = DbConnectionFactory.Open())
            {
                var transactionType = dbConnection.SingleById <TransactionType>(data.TransactionTypeId);
                if (transactionType == null || transactionType.Id != data.TransactionTypeId)
                {
                    throw new ArgumentException(string.Format("transaction.TransactionTypeId={0} does not exist in DB", data.TransactionTypeId));
                }

                var transactionStatusType = dbConnection.SingleById <TransactionStatusType>(data.TransactionStatusId);
                if (transactionStatusType == null || transactionStatusType.Id != data.TransactionStatusId)
                {
                    throw new ArgumentException(string.Format("transaction.TransactionStatusId={0} does not exist in DB", data.TransactionStatusId));
                }

                var currencyType = dbConnection.SingleById <CurrencyType>(data.CurrencyId);
                if (currencyType == null || currencyType.Id != data.CurrencyId)
                {
                    throw new ArgumentException(string.Format("transaction.CurrencyId){0} does not exist in DB", data.CurrencyId));
                }

                var transactionNotificationType = dbConnection.SingleById <TransactionNotificationStatusType>(data.TransactionNotificationStatusId);
                if (transactionNotificationType == null || transactionNotificationType.Id != data.TransactionNotificationStatusId)
                {
                    throw new ArgumentException(string.Format("transaction.TransactionNotificationStatusId){0} does not exist in DB", data.TransactionNotificationStatusId));
                }
            }
        }
        private IAdoNetUnitOfWork CreateUnitOfWork(IServiceLocator arg)
        {
            var con = DbConnectionFactory.Open(true);

            return(new AdoNetUnitOfWork(con, true, IsolationLevel.RepeatableRead));
        }
Esempio n. 20
0
 public Startup()
 {
     _serviceRunner     = new ServiceRunner();
     ConfigurationStore = new DatabaseStore(() => DbConnectionFactory.Open(true));
 }