Beispiel #1
0
        /// <summary>
        /// Event handler for a match.
        /// </summary>
        /// <param name="sender">The object that originated the event.</param>
        /// <param name="e">The event arguments.</param>
        private void OnMatchRowChanged(Object sender, MatchRowChangeEventArgs e)
        {
            // When a new, pending match record has been added to the data mode, start a thread that will
            // display the notification window.
            if (e.Action == DataRowAction.Commit && e.Row.RowState != DataRowState.Detached)
            {
                if (e.Row.StatusRow.StatusCode == Status.Active ||
                    e.Row.StatusRow.StatusCode == Status.PartialMatch ||
                    e.Row.StatusRow.StatusCode == Status.ValidMatch ||
                    e.Row.StatusRow.StatusCode == Status.ValidMatchFunds ||
                    e.Row.StatusRow.StatusCode == Status.Declined)
                {
                    NotificationInfo notificationInfo = new NotificationInfo();

                    // The match record, working order, order type and security records are used to construct the title, symbol and
                    // logo used by the notification window.
                    MatchRow        matchRow        = e.Row;
                    WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                    OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                    SecurityRow     securityRow     = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId;

                    // This is the primary method of identifying a match between two working orders.
                    notificationInfo.MatchId = matchRow.MatchId;

                    // The current status of the match is used to tell whether we're coming or going.
                    notificationInfo.Status = matchRow.StatusRow.StatusCode;

                    // Get the security symbol.
                    notificationInfo.Symbol = securityRow.Symbol;

                    // Create a logo bitmap.
                    notificationInfo.Logo = securityRow.IsLogoNull() ? String.Empty : securityRow.Logo;

                    // Provide a handler for the notification.
                    if (!securityRow.EntityRow.TypeRow.IsNotifyingTypeNull())
                    {
                        notificationInfo.NotifierType = securityRow.EntityRow.TypeRow.NotifyingType;

                        // Construct the title for the notification window.
                        notificationInfo.Message = String.Format("{0} of {1}", workingOrderRow.SideRow.Description, securityRow.Symbol);

                        // Now that the information has been extracted for the data model, the background execution queue can handle the rest of the
                        // notification of the user.
                        this.OnNotification(notificationInfo);
                    }
                }
            }
        }
        /// <summary>
        /// Initialize the data used in this application.
        /// </summary>
        private void InitializeData(object parameter)
        {
            String           title            = String.Empty;
            String           symbol           = String.Empty;
            String           name             = String.Empty;
            String           logoSource       = null;
            Decimal          leavesQuantity   = 0.0m;
            NegotiationState negotiationState = NegotiationState.None;

            lock (DataModel.SyncRoot)
            {
                // Find the Match record.
                MatchRow        matchRow        = DataModel.Match.MatchKey.Find(this.matchId);
                WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                SecurityRow     securityRow     = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId;

                symbol         = securityRow.Symbol;
                name           = securityRow.EntityRow.Name;
                logoSource     = securityRow.IsLogoNull() ? String.Empty : securityRow.Logo;
                title          = String.Format("{0} of {1}", orderTypeRow.Description, symbol);
                leavesQuantity = 0.0M;
                foreach (SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows())
                {
                    leavesQuantity += sourceOrderRow.OrderedQuantity;
                }
                foreach (DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                {
                    foreach (ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                    {
                        leavesQuantity -= executionRow.ExecutionQuantity;
                    }
                }
                leavesQuantity /= securityRow.QuantityFactor;
            }

            this.Dispatcher.Invoke(DispatcherPriority.Normal, new SetDialogAttributesDelegate(SetDialogAttributes), title, symbol, name, logoSource, leavesQuantity, negotiationState);
        }