Esempio n. 1
0
        /// <summary>
        /// Handles a Destination Order entering the error state.
        /// </summary>
        private static void SetErrorAction(Object[] key, params Object[] parameters)
        {
            // A middle tier context is also required for a transacted update.
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was
            // created.  This is not an error condition.  If there is no Working Order to update, then the operation is just terminated prematurely.
            WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key);

            if (workingOrderRow == null)
            {
                return;
            }
            workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(workingOrderRow);
            if (workingOrderRow.RowState == DataRowState.Detached)
            {
                return;
            }

            // The Working Order reflects an 'Error' Status if any of its Destination Orders have an error.
            if (workingOrderRow.StatusId != StatusMap.FromCode(Status.Error))
            {
                UpdateWorkingOrderStatus(workingOrderRow, Status.Error);
            }
        }
        /// <summary>
        /// Create a new DebtHolder
        /// </summary>
        /// <returns></returns>
        public override Guid Create(Security record)
        {
            DataModel dataModel  = new DataModel();
            Guid      securityId = Guid.NewGuid();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            VolumeCategoryRow volumeCategoryRow = DataModel.VolumeCategory.VolumeCategoryKey.Find(record.VolumeCategoryId);

            volumeCategoryRow.AcquireReaderLock(dataModelTransaction);

            ////Create a entry in security
            dataModel.CreateSecurity(
                record.AverageDailyVolume,
                record.CountryId.GetValueOrDefault(),
                record.Logo,
                record.MarketCapitalization,
                record.MinimumQuantity,
                record.PriceFactor,
                record.QuantityFactor,
                securityId,
                record.Symbol,
                record.TenantId,
                volumeCategoryRow.VolumeCategoryId);

            return(securityId);
        }
Esempio n. 3
0
        /// <summary>
        /// Changes the state of the Working Order to reflect a partially filled status.
        /// </summary>
        private static void OnPartialAction(Object[] key, params Object[] parameters)
        {
            // A middle tier context is also required for a transacted update.
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was
            // created.  This is not an error condition.  If there is no Working Order to update, then the operation is just terminated prematurely.
            WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key);

            if (workingOrderRow == null)
            {
                return;
            }
            workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(workingOrderRow);
            if (workingOrderRow.RowState == DataRowState.Detached)
            {
                return;
            }

            // The error status on a Working Order cannot be cleared with a partial fill.  Otherwise, a partial fill on any of the Destination Orders is
            // reflected in the status of the parent Working Order.
            if (workingOrderRow.StatusId != StatusMap.FromCode(Status.Error))
            {
                if (workingOrderRow.StatusId != StatusMap.FromCode(Status.PartiallyFilled))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.PartiallyFilled);
                }
            }
        }
        /// <summary>
        /// Update a match
        /// </summary>
        /// <returns></returns>
        public override void Update(Records.Match record)
        {
            DataModel dataModel = new DataModel();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
            Guid blotter = record.BlotterId.GetValueOrDefault();

            if (blotter == Guid.Empty || !TradingSupport.HasAccess(dataModelTransaction, blotter, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the selected blotter");
            }

            if (record.RowId == null || DataModel.Match.MatchKey.Find(record.RowId) == null)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Match", new object[] { record.RowId }));
            }

            dataModel.UpdateMatch(
                record.BlotterId,
                record.ContraMatchId,
                record.ContraOrderId,
                record.HeatIndex,
                record.HeatIndexDetails,
                record.MatchedTime,
                null, new object[] { record.RowId },
                record.RowVersion,
                record.StatusCodeId,
                record.WorkingOrderId);
        }
Esempio n. 5
0
        /// <summary>
        /// Determine whether a name is unique within a parent entity.
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="parentEntityRow"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Boolean IsNameUnique(DataModelTransaction transaction, EntityRow parentEntityRow, String name)
        {
            Boolean isNameUnique = true;

            foreach (EntityTreeRow entityTree in parentEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                EntityRow entityRow;
                String    oldName;

                entityTree.AcquireReaderLock(transaction);
                entityRow = entityTree.EntityRowByFK_Entity_EntityTree_ChildId;
                entityTree.ReleaseLock(transaction.TransactionId);

                entityRow.AcquireReaderLock(transaction);
                oldName      = entityRow.Name;
                isNameUnique = !entityRow.Name.Equals(name);
                entityRow.ReleaseLock(transaction.TransactionId);

                if (!isNameUnique)
                {
                    break;
                }
            }

            return(isNameUnique);
        }
Esempio n. 6
0
        /// <summary>
        /// Update Negotiation record
        /// </summary>
        /// <param name="record"></param>
        public override void Update(FluidTrade.Guardian.Records.Negotiation record)
        {
            DataModel dataModel = new DataModel();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
            Guid blotter = record.BlotterId.GetValueOrDefault();

            if (blotter == Guid.Empty || !TradingSupport.HasAccess(dataModelTransaction, blotter, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the selected blotter");
            }

            if (record.RowId == null || DataModel.Negotiation.NegotiationKey.Find(record.RowId) == null)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Negotiation", new object[] { record.RowId }));
            }

            dataModel.UpdateNegotiation(
                record.BlotterId,
                record.ExecutionId,
                record.IsRead,
                record.MatchId,
                null,
                new object[] { record.RowId },
                record.Quantity,
                record.RowVersion,
                record.StatusCodeId);
        }
Esempio n. 7
0
        /// <summary>
        /// Changes the state of the Working Order to reflect a filledly filled state.
        /// </summary>
        private static void OnFilledAction(Object[] key, params Object[] parameters)
        {
            // A middle tier context is also required for a transacted update.
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was
            // created.  This is not an error condition.  If there is no Working Order to update, then the operation is just terminated prematurely.
            WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key);

            if (workingOrderRow == null)
            {
                return;
            }
            workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(workingOrderRow);
            if (workingOrderRow.RowState == DataRowState.Detached)
            {
                return;
            }

            // The error status on a Working Order cannot be cleared with a fill.
            if (workingOrderRow.StatusId != StatusMap.FromCode(Status.Error))
            {
                // The Working Order is 'Filled' when the quantity executed is the same as the quantity ordered.
                Decimal quantityOrdered  = WorkingOrder.GetSourceOrderQuantity(dataModelTransaction, workingOrderRow);
                Decimal quantityExecuted = WorkingOrder.GetExecutionQuantity(dataModelTransaction, workingOrderRow);
                if (quantityOrdered == quantityExecuted)
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.Filled);
                }
            }
        }
        /// <summary>
        /// Create a new Math record
        /// </summary>
        /// <returns></returns>
        public override Guid Create(Records.Match record)
        {
            DataModel dataModel = new DataModel();
            Guid      matchId   = Guid.NewGuid();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
            Guid blotter = record.BlotterId.GetValueOrDefault();

            if (blotter == Guid.Empty || !TradingSupport.HasAccess(dataModelTransaction, blotter, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the selected blotter");
            }

            ////Create a match
            dataModel.CreateMatch(
                record.BlotterId.GetValueOrDefault(),
                record.ContraMatchId.GetValueOrDefault(),
                record.ContraOrderId.GetValueOrDefault(),
                record.HeatIndex,
                record.HeatIndexDetails,
                DateTime.UtcNow,
                matchId,
                record.StatusCodeId.GetValueOrDefault(),
                record.WorkingOrderId.GetValueOrDefault());

            return(matchId);
        }
Esempio n. 9
0
        /// <summary>
        /// Create Negotiation record
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public override Guid Create(FluidTrade.Guardian.Records.Negotiation record)
        {
            DataModel dataModel     = new DataModel();
            Guid      negotiationId = Guid.NewGuid();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
            Guid blotter = record.BlotterId.GetValueOrDefault();

            if (blotter == Guid.Empty || !TradingSupport.HasAccess(dataModelTransaction, blotter, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the selected blotter");
            }

            ////Create a negotiation
            dataModel.CreateNegotiation(
                blotter,
                record.ExecutionId.GetValueOrDefault(),
                record.IsRead,
                record.MatchId.GetValueOrDefault(),
                negotiationId,
                record.Quantity,
                record.StatusCodeId.GetValueOrDefault());

            return(negotiationId);
        }
Esempio n. 10
0
        /// <summary>
        /// Determine whether this debt class has a parent of the same type.
        /// </summary>
        /// <param name="transaction">The curren transaction.</param>
        /// <param name="entityRow">The entity row of the debt class.</param>
        /// <returns></returns>
        public Boolean HasParent(DataModelTransaction transaction, EntityRow entityRow)
        {
            Boolean has = false;

            EntityTreeRow[] entityTreeRows;
            Guid            typeId;

            entityRow.AcquireReaderLock(transaction);
            typeId         = entityRow.TypeId;
            entityTreeRows = entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ChildId();
            entityRow.ReleaseLock(transaction.TransactionId);

            foreach (EntityTreeRow entityTreeRow in entityTreeRows)
            {
                EntityRow parentRow;

                entityTreeRow.AcquireReaderLock(transaction);
                parentRow = entityTreeRow.EntityRowByFK_Entity_EntityTree_ParentId;
                entityTreeRow.ReleaseLock(transaction.TransactionId);

                parentRow.AcquireReaderLock(transaction);
                has = parentRow.TypeId == typeId;
                parentRow.ReleaseLock(transaction.TransactionId);

                if (has)
                {
                    break;
                }
            }

            return(has);
        }
Esempio n. 11
0
        /// <summary>
        ///
        /// </summary>
        public void OutputLocksToLog()
        {
            EventLog.Information("LOGGING LOCKS  tickCount:{0}", Environment.TickCount);
            List <string> transactionList = DataModelTransaction.GetTransactionStacks();

            if (transactionList != null)
            {
                foreach (string txnStack in transactionList)
                {
                    EventLog.Information("<<<<**>>>>Txn Stack\r\n{0}\r\n", txnStack);
                }
            }
            DataModel.DataLock.EnterReadLock();
            try
            {
                System.Data.DataSet ds = DataModel.Match.DataSet;
                foreach (System.Data.DataTable table in ds.Tables)
                {
                    foreach (DataRowBase row in table.Rows)
                    {
                        string tmp = row.GetCurrentLockStacks(true);
                        if (tmp != null)
                        {
                            EventLog.Information("<<<<**>>>>{0}\r\n{1}\r\n", row.Table.TableName, tmp);
                        }
                    }
                }
            }
            finally
            {
                DataModel.DataLock.ExitReadLock();
            }
        }
        /// <summary>
        /// See if the ChildId is a ParentId to stop circular reference.
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="parent"></param>
        /// <param name="childId"></param>
        /// <returns></returns>
        private bool IsParentEntity(DataModelTransaction transaction, EntityRow parent, Guid childId)
        {
            parent.AcquireReaderLock(transaction.TransactionId, DataModel.LockTimeout);
            try
            {
                //Make sure we are not adding a child element that is also a parent.
                foreach (EntityTreeRow entityRow in parent.GetEntityTreeRowsByFK_Entity_EntityTree_ChildId())
                {
                    entityRow.AcquireWriterLock(transaction.TransactionId, DataModel.LockTimeout);
                    try
                    {
                        if (entityRow.ParentId == childId)
                        {
                            return(true);
                        }

                        if (IsParentEntity(transaction, entityRow.EntityRowByFK_Entity_EntityTree_ParentId, childId) == true)
                        {
                            return(true);
                        }
                    }
                    finally
                    {
                        entityRow.ReleaseLock(transaction.TransactionId);
                    }
                }
            }
            finally
            {
                parent.ReleaseReaderLock(transaction.TransactionId);
            }
            return(false);
        }
Esempio n. 13
0
        /// <summary>
        /// Create a new Consumer Trust
        /// </summary>
        /// <returns></returns>
        public override Guid Create(ConsumerDebt record)
        {
            DataModel dataModel = new DataModel();
            Guid      entityId  = Guid.NewGuid();

            // Since DebtHolder object requires entries in Blotter, DebtClass and DebtHolder,
            //a transaction is required to lock the records and change the data model.

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            ////Create a entry in credit card
            dataModel.CreateConsumerDebt(
                record.CollectionDate,
                entityId,
                record.ConsumerId.GetValueOrDefault(),
                record.CreditCardId.GetValueOrDefault(),
                record.DateOfDelinquency,
                record.DebtRuleId,
                record.ExternalId0,
                record.Representative,
                record.Tag,
                record.TenantId,
                record.VendorCode);


            return(entityId);
        }
Esempio n. 14
0
        /// <summary>
        /// Create a new DebtNegotiator
        /// </summary>
        /// <returns></returns>
        public override Guid Create(DebtNegotiator record)
        {
            DataModel            dataModel            = new DataModel();
            Guid                 entityId             = Guid.Empty;
            TypeRow              typeRow              = null;
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            if (record.TypeId != null && record.TypeId != Guid.Empty)
            {
                typeRow = DataModel.Type.TypeKey.Find(record.TypeId.Value);
            }
            else
            {
                typeRow = DataModel.Type.TypeKeyExternalId0.Find("DEBT NEGOTIATOR");
            }

            if (typeRow != null)
            {
                DebtClassPersistence debtClassPersistence = new DebtClassPersistence();
                typeRow.AcquireReaderLock(dataModelTransaction);
                record.TypeId = typeRow.TypeId;
                typeRow.ReleaseLock(dataModelTransaction.TransactionId);

                entityId = debtClassPersistence.Create(record);

                dataModel.CreateDebtNegotiator(entityId);
            }

            return(entityId);
        }
Esempio n. 15
0
        /// <summary>
        /// Update Credit Card
        /// </summary>
        /// <returns></returns>
        public override void Update(CreditCard record)
        {
            DataModel            dataModel   = new DataModel();
            DataModelTransaction transaction = DataModelTransaction.Current;
            Guid blotterId = this.FindContainingBlotter(transaction, record.RowId);

            if (record.RowId == null || DataModel.CreditCard.CreditCardKey.Find(record.RowId) == null)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Credit Card", new object[] { record.RowId }));
            }
            if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, blotterId, AccessRight.Write))
            {
                throw new SecurityAccessDeniedException("The current user does not write permission to the selected blotter");
            }

            dataModel.UpdateCreditCard(
                record.AccountBalance,
                record.AccountNumber,
                record.ConsumerId,
                null,
                new object[] { record.RowId },
                record.DebtHolder,
                record.DebtRuleId,
                null,
                record.AccountNumber,
                record.OriginalAccountNumber,
                record.RowVersion,
                null);
        }
Esempio n. 16
0
        /// <summary>
        /// Create a new Credit card
        /// </summary>
        /// <returns></returns>
        public override Guid Create(CreditCard record)
        {
            DataModel            dataModel   = new DataModel();
            DataModelTransaction transaction = DataModelTransaction.Current;
            Guid blotterId = this.FindContainingBlotter(transaction, record.ConsumerId.GetValueOrDefault());
            Guid tenantId  = PersistenceHelper.GetTenantForEntity(
                transaction,
                blotterId);

            if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, blotterId, AccessRight.Write))
            {
                throw new SecurityAccessDeniedException("The current user does not write permission to the selected blotter");
            }

            Guid ccId = Guid.NewGuid();

            ////Create a entry in credit card
            dataModel.CreateCreditCard(
                record.AccountBalance,
                record.AccountNumber,
                record.ConsumerId.GetValueOrDefault(),
                ccId,
                record.DebtHolder,
                record.DebtRuleId,
                Guid.NewGuid().ToString(),
                record.AccountNumber,
                record.OriginalAccountNumber,
                tenantId);

            return(ccId);
        }
        /// <summary>
        /// Prototype method.  This will eventually take list of guids to update
        /// </summary>
        /// <param name="consumerTrustId"></param>
        private void GetSavingsBalance(Guid consumerTrustId)
        {
            string gcsAccountNumber = String.Empty;

            using (TransactionScope transactionScope = new TransactionScope())
            {
                // This provides a context for any transactions.
                DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
                ConsumerTrustRow     consumerTrustRow     = DataModel.ConsumerTrust.ConsumerTrustKey.Find(consumerTrustId);
                consumerTrustRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                try
                {
                    if (consumerTrustRow.IsSavingsAccountNull() == false)
                    {
                        gcsAccountNumber = consumerTrustRow.SavingsAccount;
                    }
                }
                finally
                {
                    consumerTrustRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                }
            }

            //If there is no GCS account number then we have no need to continue processing.
            //HACK  add logging for empty account numbers
            if (String.IsNullOrEmpty(gcsAccountNumber) == false)
            {
                Decimal savingsBalance = GetSavingsBalance(gcsAccountNumber);
                if (savingsBalance != -1.0M)
                {
                    UpdateSavingsBalance(consumerTrustId, savingsBalance);
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Create a new Consumer Trust
        /// </summary>
        /// <returns></returns>
        public override Guid Create(Consumer consumer)
        {
            DataModel dataModel  = new DataModel();
            Guid      consumerId = Guid.NewGuid();

            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            dataModel.CreateConsumer(
                consumer.Address1,
                consumer.Address2,
                null,
                null,
                consumer.City,
                consumerId,
                consumer.DateOfBirth,
                consumer.ExternalId0,
                consumer.ExternalId1,
                consumer.FirstName,
                consumer.IsEmployed,
                consumer.LastName,
                consumer.MiddleName,
                consumer.PhoneNumber,
                consumer.PostalCode,
                consumer.ProvinceId,
                consumer.Salutation,
                consumer.SocialSecurityNumber,
                consumer.Suffix);

            return(consumerId);
        }
        /// <summary>
        /// Create a new group.
        /// </summary>
        /// <param name="record">The group object.</param>
        /// <returns>The GroupId of the new group.</returns>
        public override Guid Create(Group record)
        {
            DataModel            dataModel         = new DataModel();
            DataModelTransaction transaction       = DataModelTransaction.Current;
            EntityPersistence    entityPersistence = new EntityPersistence();
            Guid    entityId;
            TypeRow typeRow = DataModel.Type.TypeKeyExternalId0.Find("GROUP");

            typeRow.AcquireReaderLock(transaction.TransactionId, DataModel.LockTimeout);

            try
            {
                record.TypeId  = typeRow.TypeId;
                record.ImageId = typeRow.ImageId;
            }
            finally
            {
                typeRow.ReleaseReaderLock(transaction.TransactionId);
            }

            entityId = entityPersistence.Create(record);

            dataModel.CreateRightsHolder(
                entityId,
                record.TenantId.Value);
            dataModel.CreateGroup(
                entityId,
                GroupTypeMap.FromCode(record.GroupType),
                record.TenantId.Value);

            return(entityId);
        }
Esempio n. 20
0
        /// <summary>
        /// Calculate a unique entity name from a base name.
        /// </summary>
        /// <param name="transaction">The current transaction.</param>
        /// <param name="parentEntityRow">The (writelocked) entity that would be the parent of the entity we intend to name.</param>
        /// <param name="name">The base name (eg. the name of the entity, provided there isn't already a sibling with that name).</param>
        /// <returns>A unique name.</returns>
        private String GetUniqueName(DataModelTransaction transaction, EntityRow parentEntityRow, String name)
        {
            Int64         nameNumber    = 1;
            String        uniqueName    = name;
            List <String> existingNames = new List <String>();

            foreach (EntityTreeRow entityTree in parentEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                EntityRow entityRow;

                entityTree.AcquireReaderLock(transaction);
                entityRow = entityTree.EntityRowByFK_Entity_EntityTree_ChildId;
                entityTree.ReleaseLock(transaction.TransactionId);

                entityRow.AcquireReaderLock(transaction);
                existingNames.Add(entityRow.Name);
                entityRow.ReleaseLock(transaction.TransactionId);
            }

            existingNames.Sort();

            while (existingNames.BinarySearch(uniqueName) >= 0)
            {
                uniqueName  = String.Format("{0} ({1})", name, nameNumber);
                nameNumber += 1;
            }

            return(uniqueName);
        }
        public ErrorCode DeleteRow(DataModel dataModel, DataModelTransaction transaction, DebtRuleRow debtRuleRow)
        {
            debtRuleRow.AcquireReaderLock(transaction);
            DebtRuleMapRow[] debtRuleMaps = debtRuleRow.GetDebtRuleMapRows();

            if (debtRuleRow.GetDebtClassRows().Length != 0)
            {
                return(ErrorCode.AccessDenied);
            }
            debtRuleRow.ReleaseReaderLock(transaction.TransactionId);

            foreach (DebtRuleMapRow debtRuleMapRow in debtRuleMaps)
            {
                debtRuleMapRow.AcquireReaderLock(transaction);
                if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, debtRuleMapRow.DebtClassId, AccessRight.Write))
                {
                    return(ErrorCode.AccessDenied);
                }
                debtRuleMapRow.ReleaseReaderLock(transaction.TransactionId);
            }

            debtRuleRow.AcquireWriterLock(transaction);
            dataModel.DestroyDebtRule(new object[] { debtRuleRow.DebtRuleId }, debtRuleRow.RowVersion);
            debtRuleRow.ReleaseLock(transaction.TransactionId);

            return(ErrorCode.Success);
        }
Esempio n. 22
0
        /// <summary>
        /// Update the SavingsBalance
        /// </summary>
        /// <param name="consumerTrustId"></param>
        /// <param name="savingsBalance"></param>
        private void UpdateSavingsBalance(Guid consumerTrustId, decimal savingsBalance)
        {
            // An instance of the data model is required for CRUD operations.
            DataModel dataModel = new DataModel();

            using (TransactionScope transactionScope = new TransactionScope())
            {
                Int64 consumerTrustRowVersion;
                // This provides a context for any transactions.
                DataModelTransaction dataModelTransaction = DataModelTransaction.Current;
                ConsumerTrustRow     consumerTrustRow     = DataModel.ConsumerTrust.ConsumerTrustKey.Find(consumerTrustId);
                consumerTrustRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                try
                {
                    consumerTrustRowVersion = consumerTrustRow.RowVersion;
                }
                finally
                {
                    consumerTrustRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                }

                dataModel.UpdateConsumerTrust(
                    null,
                    null,
                    new Object[] { consumerTrustId },
                    null,
                    null,
                    consumerTrustRowVersion,
                    null,
                    savingsBalance,
                    null,
                    null,
                    null);
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Changes the state of the Working Order to reflect a filledly filled state.
        /// </summary>
        private static void ClearErrorAction(Object[] key, params Object[] parameters)
        {
            // A middle tier context is also required for a transacted update.
            DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

            // It is possible that the Working Order that is the object of this status update operation may have been deleted since the action was
            // created.  This is not an error condition.  If there is no Working Order to update, then the operation is just terminated prematurely.
            WorkingOrderRow workingOrderRow = DataModel.WorkingOrder.WorkingOrderKey.Find(key);

            if (workingOrderRow == null)
            {
                return;
            }
            workingOrderRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
            dataModelTransaction.AddLock(workingOrderRow);
            if (workingOrderRow.RowState == DataRowState.Detached)
            {
                return;
            }

            // The 'Error' status is only cleared when all the Destination Orders are valid.
            Boolean isErrorStatus = false;

            foreach (DestinationOrderRow siblingOrderRow in workingOrderRow.GetDestinationOrderRows())
            {
                siblingOrderRow.AcquireReaderLock(dataModelTransaction);
                if (siblingOrderRow.StatusId == StatusMap.FromCode(Status.Error))
                {
                    isErrorStatus = true;
                    break;
                }
            }

            // The proper Working Order status must be evaluated when the error status is cleared.
            if (!isErrorStatus)
            {
                // The aggregates will determine the new state of the Working Order.
                Decimal quantityExecuted = WorkingOrder.GetExecutionQuantity(dataModelTransaction, workingOrderRow);
                Decimal quantityOrdered  = WorkingOrder.GetSourceOrderQuantity(dataModelTransaction, workingOrderRow);

                // This restores the 'New' status when the canceled Destination Order was the only order with any fills.
                if (quantityExecuted == 0.0M && workingOrderRow.StatusId != StatusMap.FromCode(Status.New))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.New);
                }

                // This restores the 'Partially Filled' status when other executions remain.
                if (0.0M < quantityExecuted && quantityExecuted < quantityOrdered && workingOrderRow.StatusId != StatusMap.FromCode(Status.PartiallyFilled))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.PartiallyFilled);
                }

                // This restores the 'Filled' status when the quantity executed is the same as the quantity ordered.
                if (quantityExecuted == quantityOrdered && workingOrderRow.StatusId != StatusMap.FromCode(Status.Filled))
                {
                    UpdateWorkingOrderStatus(workingOrderRow, Status.Filled);
                }
            }
        }
Esempio n. 24
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override void Update(Consumer record)
        {
            // These variables are used for auditing the changes to this record.
            DateTime createdTime    = DateTime.UtcNow;
            Guid     createdUserId  = TradingSupport.UserId;
            DateTime modifiedTime   = createdTime;
            Guid     modifiedUserId = createdUserId;

            DataModel            dataModel            = new DataModel();
            DataModelTransaction datamodelTransaction = DataModelTransaction.Current;

            if (record.RowId == null || DataModel.Consumer.ConsumerKey.Find(record.RowId) == null)
            {
                record.RowId = Create(record);
            }

            dataModel.UpdateConsumer(
                record.Address1,
                record.Address2,
                null,
                null,
                record.City,
                null,
                new object[] { record.RowId },
                record.DateOfBirth,
                record.ExternalId0,
                record.ExternalId1,
                record.FirstName,
                record.IsEmployed,
                record.LastName,
                record.MiddleName,
                record.PhoneNumber,
                record.PostalCode,
                record.ProvinceId,
                record.RowVersion,
                record.Salutation,
                record.SocialSecurityNumber,
                record.Suffix);

            //If a working order is given, Update modifyTime.
            Guid workingOrderId = record.WorkingOrderId.GetValueOrDefault(Guid.Empty);

            if (workingOrderId != Guid.Empty)
            {
                WorkingOrderPersistence workingOrderPersistence = new WorkingOrderPersistence();
                workingOrderPersistence.UpdateModifyTime(workingOrderId);
            }

            //If a working order is given, Update modifyTime.
            //Guid matchId = record.MatchId.GetValueOrDefault(Guid.Empty);
            //if (matchId != Guid.Empty)
            //{
            //    MatchPersistence matchPersistence = new MatchPersistence();
            //    matchPersistence.UpdateModifyTime(workingOrderId);
            //}
        }
        /// <summary>
        /// Collect negotiation and settlement data to move
        /// </summary>
        /// <param name="dataModelTransaction"></param>
        /// <param name="moveToInfo"></param>
        /// <param name="matchRow"></param>
        private static void CollectNegotiationData(DataModelTransaction dataModelTransaction, MoveToInfo moveToInfo, MatchRow matchRow)
        {
            foreach (ConsumerTrustNegotiationRow consumerTrustNegotiationRow in matchRow.GetConsumerTrustNegotiationRows())
            {
                consumerTrustNegotiationRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                try
                {
                    moveToInfo.consumerTrustNegotiationRows.Add(new BaseRecord()
                    {
                        RowId = consumerTrustNegotiationRow.ConsumerTrustNegotiationId, RowVersion = consumerTrustNegotiationRow.RowVersion
                    });


                    //Get counter payment rows to move
                    foreach (ConsumerTrustNegotiationCounterPaymentMethodRow counterPaymentMethodRow in consumerTrustNegotiationRow.GetConsumerTrustNegotiationCounterPaymentMethodRows())
                    {
                        counterPaymentMethodRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                        try
                        {
                            moveToInfo.consumerTrustNegotiationCounterPaymentMethodRows.Add(new BaseRecord()
                            {
                                RowId = counterPaymentMethodRow.ConsumerTrustNegotiationCounterPaymentMethodId, RowVersion = counterPaymentMethodRow.RowVersion
                            });
                        }
                        finally
                        {
                            counterPaymentMethodRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                        }
                    }

                    //Get offer payment rows to move
                    foreach (ConsumerTrustNegotiationOfferPaymentMethodRow offerPaymentMethodRow in consumerTrustNegotiationRow.GetConsumerTrustNegotiationOfferPaymentMethodRows())
                    {
                        offerPaymentMethodRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                        try
                        {
                            moveToInfo.consumerTrustNegotiationOfferPaymentMethodRows.Add(new BaseRecord()
                            {
                                RowId = offerPaymentMethodRow.ConsumerTrustNegotiationOfferPaymentMethodId, RowVersion = offerPaymentMethodRow.RowVersion
                            });
                        }
                        finally
                        {
                            offerPaymentMethodRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                        }
                    }

                    //Get Settlement rows to move
                    CollectSettlementData(dataModelTransaction, moveToInfo, consumerTrustNegotiationRow);
                }
                finally
                {
                    consumerTrustNegotiationRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override void Update(DebtNegotiator record)
        {
            DataModel            dataModel            = new DataModel();
            DataModelTransaction transaction          = DataModelTransaction.Current;
            EntityPersistence    entityPersistence    = new EntityPersistence();
            DebtClassPersistence debtClassPersistence = new DebtClassPersistence();

            entityPersistence.Update(record);
            debtClassPersistence.Update(record);
        }
        /// <summary>
        /// Grant a particular rights holder specific rights to an entity.
        /// </summary>
        /// <param name="rightsHolderId">The rights holder's id.</param>
        /// <param name="entityId">The entity's id.</param>
        /// <param name="rightId">The specific right's id.</param>
        /// <returns>The id of the AccessControl row.</returns>
        internal static Guid GrantAccess(Guid rightsHolderId, Guid entityId, Guid rightId)
        {
            DataModelTransaction transaction = DataModelTransaction.Current;
            DataModel            dataModel   = new DataModel();
            Guid             currentUserId   = TradingSupport.UserId;
            UserRow          currentUserRow  = DataModel.User.UserKey.Find(currentUserId);
            RightsHolderRow  rightsHolderRow = DataModel.RightsHolder.RightsHolderKey.Find(rightsHolderId);
            Guid             rightsHolderTenantId;
            AccessControlRow accessControlRow = DataModel.AccessControl.AccessControlKeyRightsHolderIdEntityId.Find(rightsHolderId, entityId);
            Guid             accessControlId  = Guid.Empty;

            // Determine whether current user has write access to the entity.
            if (!DataModelFilters.HasAccess(transaction, currentUserId, entityId, AccessRight.Write))
            {
                throw new FaultException <SecurityFault>(
                          new SecurityFault(String.Format("{0} does not write permission to {1}", rightsHolderId, entityId)));
            }

            rightsHolderRow.AcquireReaderLock(transaction);
            rightsHolderTenantId = rightsHolderRow.TenantId;
            rightsHolderRow.ReleaseReaderLock(transaction.TransactionId);

            // Determine whether current user's tenant is upstream from rights holder we're modifying.
            if (!DataModelFilters.HasTenantAccess(transaction, currentUserId, rightsHolderTenantId))
            {
                throw new FaultException <SecurityFault>(
                          new SecurityFault(String.Format("{0} does not control over tenant {1}", rightsHolderId, rightsHolderTenantId)));
            }

            if (accessControlRow != null)
            {
                accessControlRow.AcquireWriterLock(transaction);
                accessControlId = accessControlRow.AccessControlId;
                dataModel.UpdateAccessControl(
                    accessControlRow.AccessControlId,
                    new object[] { accessControlRow.AccessControlId },
                    rightId,
                    entityId,
                    rightsHolderId,
                    accessControlRow.RowVersion,
                    rightsHolderTenantId);
            }
            else
            {
                accessControlId = Guid.NewGuid();
                dataModel.CreateAccessControl(
                    accessControlId,
                    rightId,
                    entityId,
                    rightsHolderId,
                    rightsHolderTenantId);
            }

            return(accessControlId);
        }
        /// <summary>
        /// Placeholder
        /// </summary>
        /// <param name="record"></param>
        public override void Update(EntityTree record)
        {
            DataModel            dataModel     = new DataModel();
            DataModelTransaction transaction   = DataModelTransaction.Current;
            EntityTreeRow        entityTreeRow = DataModel.EntityTree.EntityTreeKey.Find(record.RowId);
            EntityRow            child         = DataModel.Entity.EntityKey.Find(record.ChildId);
            EntityRow            parent        = DataModel.Entity.EntityKey.Find(record.ParentId);
            String childName;

            entityTreeRow.AcquireWriterLock(transaction);

            if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, entityTreeRow.ParentId, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the old parent entity");
            }

            if (!DataModelFilters.HasAccess(transaction, TradingSupport.UserId, record.ParentId, AccessRight.Write))
            {
                throw new SecurityException("Current user does not have write access to the new parent entity");
            }

            parent.AcquireWriterLock(transaction);
            child.AcquireReaderLock(transaction);
            childName = child.Name;
            child.ReleaseLock(transaction.TransactionId);

            if (record.ChildId == record.ParentId)
            {
                throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"),
                                                         new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName)));
            }


            if (IsParentEntity(transaction, parent, record.ChildId) == true)
            {
                throw new FaultException <ArgumentFault>(new ArgumentFault("Create EntityTree"),
                                                         new FaultReason(String.Format("Cannot add {0} as a child of this element because it wil create a circular relationship", childName)));
            }

            if (!EntityPersistence.IsNameUnique(transaction, parent, childName))
            {
                throw new FaultException <RecordExistsFault>(
                          new RecordExistsFault("Entity", new object[] { childName }),
                          "An entity with this name already exists");
            }

            dataModel.UpdateEntityTree(
                record.ChildId,
                entityTreeRow.EntityTreeId,
                new object[] { entityTreeRow.EntityTreeId },
                null,
                record.ParentId,
                entityTreeRow.RowVersion);
        }
Esempio n. 29
0
        private static void DeleteMatch(MatchRow matchRow)
        {
            for (int deadlockRetry = 0; deadlockRetry < deadlockRetiesMax; deadlockRetry++)
            {
                try
                {
                    using (TransactionScope transactionScope = new TransactionScope())
                    {
                        // This provides a context for any transactions.
                        DataModelTransaction dataModelTransaction = DataModelTransaction.Current;

                        long rowVersion;
                        Guid matchId;
                        matchRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                        try
                        {
                            if (matchRow.RowState == System.Data.DataRowState.Detached ||
                                matchRow.RowState == System.Data.DataRowState.Deleted)
                            {
                                continue;
                            }

                            rowVersion = matchRow.RowVersion;
                            matchId    = matchRow.MatchId;
                        }
                        finally
                        {
                            matchRow.ReleaseReaderLock(dataModelTransaction.TransactionId);
                        }
                        DataModel dataModel = new DataModel();
                        dataModel.DestroyMatch(new object[] { matchId }, rowVersion);

                        transactionScope.Complete();
                        return;
                    }                    //end using
                }
                catch (System.Data.SqlClient.SqlException sqlEx)
                {
                    if (FluidTrade.Core.Utilities.SqlErrorHelper.IsDeadlockException(sqlEx))
                    {
                        if (deadlockRetry == deadlockRetiesMax - 1)
                        {
                            throw;
                        }

                        FluidTrade.Core.EventLog.Warning("Deadlock exception\r\n{0}: {1}\r\n{2}", sqlEx.Message, sqlEx.ToString(), sqlEx.StackTrace);
                    }
                    else
                    {
                        throw;
                    }
                }
            }            //end deadlock retry
        }
Esempio n. 30
0
        /// <summary>
        /// Find the blotter than contains this credit card.
        /// </summary>
        /// <param name="transaction">The transaction object.</param>
        /// <param name="creditCardId">The credit card id.</param>
        /// <returns>The blotter id of the blotter that contains this credit card.</returns>
        private Guid FindContainingBlotter(DataModelTransaction transaction, Guid creditCardId)
        {
            WorkingOrderRow workingOrderRow = this.FindWorkingOrder(transaction, creditCardId);

            workingOrderRow.AcquireReaderLock(transaction);
            Guid blotterId = workingOrderRow.BlotterId;

            workingOrderRow.ReleaseLock(transaction.TransactionId);

            return(blotterId);
        }