예제 #1
0
        /// <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;
            Bitmap           logo             = null;
            decimal          leavesQuantity   = 0.0m;
            decimal          minimumQuantity  = 0.0m;
            NegotiationState negotiationState = NegotiationState.None;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // Find the Match record.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(this.matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

                symbol          = securityRow.Symbol;
                name            = securityRow.ObjectRow.Name;
                minimumQuantity = securityRow.MinimumQuantity;
                if (!securityRow.IsLogoNull())
                {
                    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo));
                    logo = new Bitmap(memoryStream);
                }
                title          = string.Format("{0} of {1}", orderTypeRow.Description, symbol);
                leavesQuantity = workingOrderRow.SubmittedQuantity;
                foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                {
                    foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                    {
                        leavesQuantity -= executionRow.ExecutionQuantity;
                    }
                }
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            Invoke(new SetDialogAttributesDelegate(SetDialogAttributes), new object[] { title, symbol, name, logo, leavesQuantity, negotiationState });
        }
예제 #2
0
        /// <summary>
        /// Notifies the user that a match opportunity exists.
        /// </summary>
        /// <param name="parameter">The thread initialization parameters.</param>
        private void NotifyUser(object parameter)
        {
            // Extract the thread parameters.
            int matchId = (int)parameter;

            // The symbol, title and the bitmap for the corporate logo will be retrieved from the data model in the code below.
            // They will be used to initialize the pop-up dialog after the locks on the data model have been released.
            string symbol = string.Empty;
            string title  = string.Empty;
            Bitmap logo   = null;

            try
            {
                // Lock the tables.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait);

                // The match record, working order, order type and security records are used to construct the title, symbol and
                // logo used by the notification window.
                ClientMarketData.MatchRow        matchRow        = ClientMarketData.Match.FindByMatchId(matchId);
                ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow;
                ClientMarketData.OrderTypeRow    orderTypeRow    = workingOrderRow.OrderTypeRow;
                ClientMarketData.SecurityRow     securityRow     = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId;

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

                // Create a logo bitmap.
                if (!securityRow.IsLogoNull())
                {
                    MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo));
                    logo = new Bitmap(memoryStream);
                }

                // Construct the title for the notification window.
                title = string.Format("{0} of {1}", orderTypeRow.Description, symbol);
            }
            finally
            {
                // Release the locks.
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.NegotiationLock.IsReaderLockHeld)
                {
                    ClientMarketData.NegotiationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // The notification window looks and acts like the Microsoft Instant Messaging window.  It will pop up in the lower
            // right hand corner of the screen with a title, the corporate logo and a chance to either accept or decline the
            // opportunity for a match.
            NotificationWindow notificationWindow = new NotificationWindow();

            notificationWindow.MatchId        = matchId;
            notificationWindow.Symbol         = symbol;
            notificationWindow.Message        = title;
            notificationWindow.CompanyLogo    = logo;
            notificationWindow.Accept        += new MatchEventHandler(AcceptNegotiation);
            notificationWindow.Decline       += new MatchEventHandler(DeclineNegotiation);
            notificationWindow.ChangeOptions += new EventHandler(ChangeOptions);
            notificationWindow.Show();
        }