예제 #1
0
        public async Task Update(ISqlTransactionHandler transactionHandler, DomainData domainData)
        {
            if (domainData.Manager.GetState(domainData) == DataState.Updated)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, domainData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bla].[UpdateDomain]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "id", DbType.Guid, DataUtil.GetParameterValue(domainData.DomainGuid));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "name", DbType.String, DataUtil.GetParameterValue(domainData.Name));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "deleted", DbType.Boolean, DataUtil.GetParameterValue(domainData.Deleted));

                    await command.ExecuteNonQueryAsync();

                    domainData.UpdateTimestamp = (DateTime)timestamp.Value;
                }
            }
        }
예제 #2
0
        public async Task Create(ISqlTransactionHandler transactionHandler, MetricData metricData)
        {
            if (metricData.Manager.GetState(metricData) == DataState.New)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, metricData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bll].[CreateMetric]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter id = DataUtil.CreateParameter(_providerFactory, "id", DbType.Int64);
                    id.Direction = ParameterDirection.Output;
                    command.Parameters.Add(id);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "domainId", DbType.Guid, DataUtil.GetParameterValue(metricData.DomainId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "eventCode", DbType.AnsiString, DataUtil.GetParameterValue(metricData.EventCode));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "magnitude", DbType.Double, DataUtil.GetParameterValue(metricData.Magnitude));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "data", DbType.String, DataUtil.GetParameterValue(metricData.Data));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "timestamp", DbType.DateTime2, DataUtil.GetParameterValue(metricData.CreateTimestamp));

                    await command.ExecuteNonQueryAsync();

                    metricData.MetricId = (long)id.Value;
                }
            }
        }
예제 #3
0
        public async Task Create(ISqlTransactionHandler transactionHandler, ClientData clientData)
        {
            if (clientData.Manager.GetState(clientData) == DataState.New)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, clientData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bla].[CreateClient]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter guid = DataUtil.CreateParameter(_providerFactory, "id", DbType.Guid);
                    guid.Direction = ParameterDirection.Output;
                    command.Parameters.Add(guid);

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "accountId", DbType.Guid, DataUtil.GetParameterValue(clientData.AccountId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "name", DbType.String, DataUtil.GetParameterValue(clientData.Name));

                    await command.ExecuteNonQueryAsync();

                    clientData.ClientId        = (Guid)guid.Value;
                    clientData.CreateTimestamp = (DateTime)timestamp.Value;
                    clientData.UpdateTimestamp = (DateTime)timestamp.Value;
                }
            }
        }
예제 #4
0
        public async Task Update(ISqlTransactionHandler transactionHandler, UserData userData)
        {
            if (userData.Manager.GetState(userData) == DataState.Updated)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, userData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bla].[UpdateUser]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "guid", DbType.Guid, userData.UserGuid);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "emailAddressGuid", DbType.Guid, userData.EmailAddressGuid);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "roles", DbType.Int16, userData.Roles);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "name", DbType.AnsiString, userData.Name);

                    await command.ExecuteNonQueryAsync();

                    userData.UpdateTimestamp = (DateTime)timestamp.Value;
                }
            }
        }
예제 #5
0
        public async Task Create(ISqlTransactionHandler transactionHandler, ExceptionData exceptionData)
        {
            if (exceptionData.Manager.GetState(exceptionData) == DataState.New)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, exceptionData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bll].[CreateException]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter id = DataUtil.CreateParameter(_providerFactory, "id", DbType.Int64);
                    id.Direction = ParameterDirection.Output;
                    command.Parameters.Add(id);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "domainId", DbType.Guid, DataUtil.GetParameterValue(exceptionData.DomainId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "parentExceptionId", DbType.Int64, DataUtil.GetParameterValue(exceptionData.ParentExceptionId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "message", DbType.String, DataUtil.GetParameterValue(exceptionData.Message));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "typeName", DbType.String, DataUtil.GetParameterValue(exceptionData.TypeName));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "source", DbType.String, DataUtil.GetParameterValue(exceptionData.Source));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "appDomain", DbType.String, DataUtil.GetParameterValue(exceptionData.AppDomain));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "targetSite", DbType.String, DataUtil.GetParameterValue(exceptionData.TargetSite));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "stackTrace", DbType.String, DataUtil.GetParameterValue(exceptionData.StackTrace));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "data", DbType.String, DataUtil.GetParameterValue(exceptionData.Data));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "timestamp", DbType.DateTime2, DataUtil.GetParameterValue(exceptionData.CreateTimestamp));

                    await command.ExecuteNonQueryAsync();

                    exceptionData.ExceptionId = (long)id.Value;
                }
            }
        }
예제 #6
0
        public async Task Update(ISqlTransactionHandler transactionHandler, ItemData itemData)
        {
            if (itemData.Manager.GetState(itemData) == DataState.Updated)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, itemData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[blc].[UpdateItem]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "id", DbType.Guid, DataUtil.GetParameterValue(itemData.ItemId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "code", DbType.AnsiString, DataUtil.GetParameterValue(itemData.Code));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "data", DbType.AnsiString, DataUtil.GetParameterValue(itemData.Data));

                    await command.ExecuteNonQueryAsync();

                    itemData.UpdateTimestamp = (DateTime)timestamp.Value;
                }
            }
        }
예제 #7
0
        public async Task Create(ISqlTransactionHandler transactionHandler, UserInvitationData userInvitationData)
        {
            if (userInvitationData.Manager.GetState(userInvitationData) == DataState.New)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, userInvitationData);
                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bla].[CreateUserInvitation]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter guid = DataUtil.CreateParameter(_providerFactory, "id", DbType.Guid);
                    guid.Direction = ParameterDirection.Output;
                    command.Parameters.Add(guid);

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "accountGuid", DbType.Guid, userInvitationData.AccountId);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "emailAddressGuid", DbType.Guid, userInvitationData.EmailAddressId);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "status", DbType.Int16, userInvitationData.Status);
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "expirationTimestamp", DbType.DateTime2, userInvitationData.ExpirationTimestamp);

                    await command.ExecuteNonQueryAsync();
                    userInvitationData.UserInvitationId = (Guid)guid.Value;
                    userInvitationData.CreateTimestamp = (DateTime)timestamp.Value;
                    userInvitationData.UpdateTimestamp = (DateTime)timestamp.Value;
                }
            }
        }
예제 #8
0
        public async Task Create(ISqlTransactionHandler transactionHandler, EmailAddressData emailAddressData)
        {
            if (emailAddressData.Manager.GetState(emailAddressData) == DataState.New)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, emailAddressData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bla].[CreateEmailAddress]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter guid = DataUtil.CreateParameter(_providerFactory, "guid", DbType.Guid);
                    guid.Direction = ParameterDirection.Output;
                    command.Parameters.Add(guid);

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "address", DbType.String, emailAddressData.Address);

                    await command.ExecuteNonQueryAsync();

                    emailAddressData.EmailAddressGuid = (Guid)guid.Value;
                    emailAddressData.CreateTimestamp  = (DateTime)timestamp.Value;
                }
            }
        }
예제 #9
0
        public async Task Update(ISqlTransactionHandler transactionHandler, PurgeWorkerData purgeWorkerData)
        {
            if (purgeWorkerData.Manager.GetState(purgeWorkerData) == DataState.Updated)
            {
                await _providerFactory.EstablishTransaction(transactionHandler, purgeWorkerData);

                using (DbCommand command = transactionHandler.Connection.CreateCommand())
                {
                    command.CommandText = "[bll].[UpdatePurgeWorker]";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Transaction = transactionHandler.Transaction.InnerTransaction;

                    IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                    timestamp.Direction = ParameterDirection.Output;
                    command.Parameters.Add(timestamp);

                    DataUtil.AddParameter(_providerFactory, command.Parameters, "purgeWorkerId", DbType.Guid, DataUtil.GetParameterValue(purgeWorkerData.PurgeWorkerId));
                    DataUtil.AddParameter(_providerFactory, command.Parameters, "status", DbType.Int16, DataUtil.GetParameterValue(purgeWorkerData.Status));

                    await command.ExecuteNonQueryAsync();

                    purgeWorkerData.UpdateTimestamp = DateTime.SpecifyKind((DateTime)timestamp.Value, DateTimeKind.Utc);
                }
            }
        }
예제 #10
0
        public async Task DeleteByCode(ISqlTransactionHandler transactionHandler, Guid domainId, string code)
        {
            await _providerFactory.EstablishTransaction(transactionHandler);

            using (DbCommand command = transactionHandler.Connection.CreateCommand())
            {
                command.CommandText = "[blc].[DeleteItemByCode]";
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = transactionHandler.Transaction.InnerTransaction;

                DataUtil.AddParameter(_providerFactory, command.Parameters, "domainId", DbType.Guid, DataUtil.GetParameterValue(domainId));
                DataUtil.AddParameter(_providerFactory, command.Parameters, "code", DbType.AnsiString, DataUtil.GetParameterValue(code));

                await command.ExecuteNonQueryAsync();
            }
        }
예제 #11
0
        public async Task RemoveUser(ISqlTransactionHandler transactionHandler, Guid userGuid, Guid accountGuid)
        {
            await _providerFactory.EstablishTransaction(transactionHandler);

            using (DbCommand command = transactionHandler.Connection.CreateCommand())
            {
                command.CommandText = "[bla].[UpdateAccountRemoveUser]";
                command.CommandType = CommandType.StoredProcedure;
                command.Transaction = transactionHandler.Transaction.InnerTransaction;

                IDataParameter timestamp = DataUtil.CreateParameter(_providerFactory, "timestamp", DbType.DateTime2);
                timestamp.Direction = ParameterDirection.Output;
                command.Parameters.Add(timestamp);

                DataUtil.AddParameter(_providerFactory, command.Parameters, "accountGuid", DbType.Guid, DataUtil.GetParameterValue(accountGuid));
                DataUtil.AddParameter(_providerFactory, command.Parameters, "userGuid", DbType.Guid, DataUtil.GetParameterValue(userGuid));

                await command.ExecuteNonQueryAsync();
            }
        }
예제 #12
0
        public void AddParameterTest()
        {
            Mock <IDataParameter> dataParameter = new Mock <IDataParameter>();

            dataParameter.SetupAllProperties();
            Mock <IDbProviderFactory> providerFactory = new Mock <IDbProviderFactory>();

            providerFactory.Setup <IDataParameter>(f => f.CreateParameter()).Returns(dataParameter.Object);
            List <IDataParameter> parameters = new List <IDataParameter>();
            string name   = "tacoTown";
            DbType dbType = DbType.Int32;
            int    value  = 7227;

            DataUtil.AddParameter(providerFactory.Object, parameters, name, dbType, value);
            providerFactory.Verify <IDataParameter>(f => f.CreateParameter(), Times.Once);
            Assert.AreEqual(1, parameters.Count);
            Assert.AreEqual("tacoTown", parameters[0].ParameterName);
            Assert.AreEqual(dbType, parameters[0].DbType);
            Assert.AreEqual(value, parameters[0].Value);
        }