/// <summary> /// Shows a dialog box for maintaining an blotter or fund. /// </summary> /// <param name="blotterId">Primary identifier for the blotter.</param> public virtual void Show(Blotter blotter) { try { // Make sure locks are not nested. Debug.Assert(!ClientMarketData.IsLocked); // Lock the tables needed for the dialog. ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.TypeLock.AcquireReaderLock(CommonTimeout.LockWait); // Find the blotter in the data model. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(blotter.BlotterId); if (blotterRow == null) { throw new Exception("Some else has deleted this blotter."); } // General Tab this.textBoxName.Text = blotterRow.ObjectRow.Name; this.labelTypeText.Text = blotterRow.ObjectRow.TypeRow.Description; this.textBoxDescription.Text = (blotterRow.ObjectRow.IsDescriptionNull()) ? "" : blotterRow.ObjectRow.Description; this.pictureBox.Image = blotter.Image32x32; } finally { // Release the tables used for the dialog. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.TypeLock.IsReaderLockHeld) { ClientMarketData.TypeLock.ReleaseReaderLock(); } // Make sure all locks have been released Debug.Assert(!ClientMarketData.IsLocked); } // Display the dialog. this.ShowDialog(); }
/// <summary> /// Opens the Blotter Document. /// </summary> /// <param name="blotterId">The blotter identifier.</param> protected override void OpenCommand() { try { // Lock the tables. System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.MatchLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait); if (this.Tag is BlotterMatchDetail) { this.blotter = ((BlotterMatchDetail)this.Tag).Blotter; } if (this.Tag is Blotter) { this.blotter = (Blotter)this.Tag; } // Each blotter can have a stylesheet assigned to it so Fixed Income traders view Fixed Income data, // equity traders Equity data, and so forth. If no blotter is assigned, a default will be provided. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null) { throw new ArgumentException("This blotter has been deleted", this.blotter.BlotterId.ToString()); } // If a viewer is avaiable for the objects associated with the blotter, then we'll enable the viewers for those // objects. For example, debt blotters don't require destinationOrder viewers, so there won't be one associated // with that blotter. this.hasAdvertisementViewer = !blotterRow.IsAdvertisementStylesheetIdNull(); this.hasDestinationOrderViewer = !blotterRow.IsDestinationOrderStylesheetIdNull(); this.hasExecutionViewer = !blotterRow.IsExecutionStylesheetIdNull(); this.hasMatchViewer = !blotterRow.IsMatchStylesheetIdNull(); this.hasMatchHistoryViewer = !blotterRow.IsMatchHistoryStylesheetIdNull(); this.hasSourceOrderViewer = !blotterRow.IsSourceOrderStylesheetIdNull(); this.hasWorkingOrderViewer = !blotterRow.IsWorkingOrderStylesheetIdNull(); } catch (Exception exception) { // Write the error out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the tables. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.MatchLock.IsReaderLockHeld) { ClientMarketData.MatchLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.StylesheetLock.IsReaderLockHeld) { ClientMarketData.StylesheetLock.ReleaseReaderLock(); } if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld) { ClientMarketData.WorkingOrderLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } BeginInvoke(new EventHandler(OpenChildren)); }
/// <summary> /// Creates an displays an execution report. /// </summary> /// <param name="workingOrderId">The block order of the executions.</param> /// <param name="execution">Optional temporary execution.</param> protected override void DrawDocumentCommand(object parameter) { // Extract the command arguments. Blotter blotter = (Blotter)parameter; try { // Lock all the tables that we'll reference while building a destinationOrder document. System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BrokerLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait); // Make sure the block order still exists. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null && this.blotter.BlotterId != 0) { throw new ArgumentException("The block order has been deleted.", this.blotter.BlotterId.ToString()); } // Create the execution document. AdvertisementDocument ticketDocument = new AdvertisementDocument(blotter.BlotterId); #if DEBUGXML // We need to make sure that an error writing the debug file doesn't disturb the debug session. try { // Dump the DOM to a file. This is very useful when debugging. ticketDocument.Save("ticketDOM.xml"); } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } #endif // At this point, we've constructed a string that is compatible with the XML format of the spreadsheet // control. We can invoke the foreground thread to move the data into the control. this.XmlDocument = ticketDocument; } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the locks if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld) { ClientMarketData.WorkingOrderLock.ReleaseReaderLock(); } if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.BrokerLock.IsReaderLockHeld) { ClientMarketData.BrokerLock.ReleaseReaderLock(); } if (ClientMarketData.ExecutionLock.IsReaderLockHeld) { ClientMarketData.ExecutionLock.ReleaseReaderLock(); } if (ClientMarketData.UserLock.IsReaderLockHeld) { ClientMarketData.UserLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld) { ClientMarketData.ObjectTreeLock.ReleaseReaderLock(); } if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld) { ClientMarketData.DestinationOrderLock.ReleaseReaderLock(); } if (ClientMarketData.PriceTypeLock.IsReaderLockHeld) { ClientMarketData.PriceTypeLock.ReleaseReaderLock(); } if (ClientMarketData.SecurityLock.IsReaderLockHeld) { ClientMarketData.SecurityLock.ReleaseReaderLock(); } if (ClientMarketData.TimeInForceLock.IsReaderLockHeld) { ClientMarketData.TimeInForceLock.ReleaseReaderLock(); } if (ClientMarketData.OrderTypeLock.IsReaderLockHeld) { ClientMarketData.OrderTypeLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } }
/// <summary> /// Opens the Advertisement Viewer. /// </summary> protected void OpenCommand(params object[] parameters) { this.blotter = (Blotter)parameters[0]; try { // Lock the tables System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.BrokerLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait); ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait); // Install the event handlers. The ClientMarketData component will advise us when the data has changed. ClientMarketData.Blotter.BlotterRowChanged += new ClientMarketData.BlotterRowChangeEventHandler(this.BlotterRowChangeEvent); ClientMarketData.Blotter.BlotterRowDeleted += new ClientMarketData.BlotterRowChangeEventHandler(this.BlotterRowChangeEvent); ClientMarketData.Broker.BrokerRowChanged += new ClientMarketData.BrokerRowChangeEventHandler(this.BrokerRowChangeEvent); ClientMarketData.Broker.BrokerRowDeleted += new ClientMarketData.BrokerRowChangeEventHandler(this.BrokerRowChangeEvent); ClientMarketData.Execution.ExecutionRowChanged += new ClientMarketData.ExecutionRowChangeEventHandler(this.ExecutionRowChangeEvent); ClientMarketData.Execution.ExecutionRowDeleted += new ClientMarketData.ExecutionRowChangeEventHandler(this.ExecutionRowChangeEvent); ClientMarketData.Stylesheet.StylesheetRowChanged += new ClientMarketData.StylesheetRowChangeEventHandler(this.StylesheetRowChangeEvent); ClientMarketData.Stylesheet.StylesheetRowDeleted += new ClientMarketData.StylesheetRowChangeEventHandler(this.StylesheetRowChangeEvent); ClientMarketData.EndMerge += new EventHandler(this.EndMerge); // Find the block order and extract the securty level data if it exists. This security level data is // needed to calculate the trade and settlement dates and other defaults for the executions. ClientMarketData.BlotterRow blotterRow = ClientMarketData.Blotter.FindByBlotterId(this.blotter.BlotterId); if (blotterRow == null) { throw new Exception(String.Format("Blotter {0} has been deleted", this.blotter.BlotterId)); } // See if a stylesheet has been associated with the blotter. ClientMarketData.StylesheetRow stylesheetRow = blotterRow.IsAdvertisementStylesheetIdNull() ? null : ClientMarketData.Stylesheet.FindByStylesheetId(blotterRow.AdvertisementStylesheetId); if (stylesheetRow == null) { throw new Exception(String.Format("Blotter {0} has no Advertisement stylesheet", this.blotter.BlotterId)); } // As an optimization, don't reload the stylesheet if the prevous document used the same stylesheet. This // will save a few hundred milliseconds when scrolling through similar documents. if (this.stylesheetId != stylesheetRow.StylesheetId) { // Keep track of the stylesheet id in case it is changed while we're viewing it. The event handler // will use this id to determine if an incoming stylesheet will trigger a refresh of the document. this.stylesheetId = stylesheetRow.StylesheetId; } } catch (Exception exception) { // Write the error and stack trace out to the debug listener EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); } finally { // Release the table locks. if (ClientMarketData.BlotterLock.IsReaderLockHeld) { ClientMarketData.BlotterLock.ReleaseReaderLock(); } if (ClientMarketData.BrokerLock.IsReaderLockHeld) { ClientMarketData.BrokerLock.ReleaseReaderLock(); } if (ClientMarketData.ExecutionLock.IsReaderLockHeld) { ClientMarketData.ExecutionLock.ReleaseReaderLock(); } if (ClientMarketData.StylesheetLock.IsReaderLockHeld) { ClientMarketData.StylesheetLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } }