예제 #1
0
        /// <summary>
        /// Gets the user's unique identifier.
        /// </summary>
        /// <returns>The user's unique identifier.</returns>
        public static Guid GetUserId()
        {
            // Get the current transaction and the user's identity principal.
            DataModelTransaction  dataModelTransaction  = DataModel.CurrentTransaction;
            OrganizationPrincipal organizationPrincipal = Thread.CurrentPrincipal as OrganizationPrincipal;

            // Try to find the user in the user tables.
            DataModel.UserRow userRow = DataModel.User.UserKeyDistinguishedName.Find(organizationPrincipal.DistinguishedName);
            if (userRow == null)
            {
                Log.Error(String.Format("Invalid Login request for {0}", organizationPrincipal.DistinguishedName));
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("User", new Object[] { organizationPrincipal.DistinguishedName }));
            }

            // If a record is found in the User table that matches the thread's identity, then lock it for the duration of the transaction and insure that it wasn't
            // deleted between the time it was found and the time it was locked.
            userRow.AcquireReaderLock(dataModelTransaction);
            dataModelTransaction.AddLock(userRow);
            if (userRow.RowState == DataRowState.Detached)
            {
                throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("User", new Object[] { organizationPrincipal.DistinguishedName }));
            }

            // This is the user's internal identity to the data model.
            return(userRow.UserId);
        }
예제 #2
0
        /// <summary>
        /// Handles a change to the DestinationOrder table.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="e">The event data.</param>
        static void OnDestinationOrderRowChanged(object sender, DataModel.DestinationOrderRowChangeEventArgs e)
        {
            // This will turn new DestinationOrder records into orders that can be sent to a destination for execution.
            if (e.Action == DataRowAction.Add)
            {
                // The current transaction is going to be needed to lock records.
                DataModelTransaction dataModelTransaction = DataModel.CurrentTransaction;

                // Create a new message for the order we're going to build from the DestinationOrder.
                Message message = new Message();

                // The market execution engine will need to know the source firm so it knows how to route the order back.
                OrganizationPrincipal organizationPrincipal = Thread.CurrentPrincipal as OrganizationPrincipal;
                message.SenderCompID = organizationPrincipal.Organization;

                // Copy the basic properties of the DestinationOrder into the message.
                DataModel.DestinationOrderRow destinationOrderRow = e.Row;
                message.ClOrdID         = destinationOrderRow.DestinationOrderId.ToString();
                message.OrderQty        = destinationOrderRow.OrderedQuantity;
                message.OrdType         = destinationOrderRow.OrderTypeCode;
                message.SideCode        = destinationOrderRow.SideCode;
                message.TimeInForceCode = destinationOrderRow.TimeInForceCode;

                // Get the symbol to use as a security identifier.
                DataModel.SecurityRow securityRow = destinationOrderRow.SecurityRowByFK_Security_DestinationOrder_SecurityId;
                securityRow.AcquireReaderLock(dataModelTransaction.TransactionId, DataModel.LockTimeout);
                dataModelTransaction.AddLock(securityRow);
                if (securityRow.RowState == DataRowState.Detached)
                {
                    throw new FaultException <RecordNotFoundFault>(new RecordNotFoundFault("Security", new Object[] { destinationOrderRow.SecurityId }));
                }
                message.Symbol = securityRow.Symbol;

                // This will put the new order in a queue.  The DestinatonThread will pull it out, batch it up and send it to the destination to be executed.
                lock (MarketEngine.syncRoot)
                {
                    MarketEngine.messageQueue.Enqueue(message);
                    if (messageQueue.Count == 1)
                    {
                        MarketEngine.orderEvent.Set();
                    }
                }
            }
        }