示例#1
0
        private void RecurseBlotter(ClientMarketData.ObjectRow objectRow)
        {
            foreach (ClientMarketData.ObjectTreeRow objectTreeRow in objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId())
            {
                RecurseBlotter(objectTreeRow.ObjectRowByFKObjectObjectTreeChildId);
            }

            foreach (ClientMarketData.BlotterRow blotterRow in objectRow.GetBlotterRows())
            {
                foreach (ClientMarketData.BlockOrderRow blockOrderRow in blotterRow.GetBlockOrderRows())
                {
                    if (blockOrderRow.GetBlockOrderTreeRowsByFKBlockOrderBlockOrderTreeChildId().Length == 0)
                    {
                        // At this point, we've found an element that has no parents.  Add it to the tree and recurse down in
                        // to the structure to find all the children.
                        BlockOrderElement blockOrdersElement = this.CreateBlockOrderElement(blockOrderRow);
                        this.DocumentElement.AppendChild(blockOrdersElement);
                        RecurseTree(blockOrdersElement);

                        // This is a CPU intensive task, so sleep between each major branch that's uncovered.
                        Thread.Sleep(0);
                    }
                }
            }
        }
示例#2
0
 public Object(int objectId)
 {
     // Initialize the object
     ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(objectId);
     this.ObjectId    = objectRow.ObjectId;
     this.Name        = objectRow.Name;
     this.Description = objectRow.IsDescriptionNull() ? string.Empty : objectRow.Description;
     this.ReadOnly    = objectRow.ReadOnly;
     this.Hidden      = objectRow.Hidden;
 }
示例#3
0
 /// <summary>
 /// Construct a hierarchical tree structure by recursively scanning the parent-child relations.
 /// </summary>
 /// <param name="objectNode">The current node in the tree structure.</param>
 private void RecurseNodes(ObjectNode objectNode, ClientMarketData.ObjectRow objectRow)
 {
     // Add all the children of this object to the tree.  This, in turn, will add all the children of the children, and so
     // on until we reach the end of the tree.  Simple, elegant, powerful.
     foreach (ClientMarketData.ObjectTreeRow childRelationRow in
              objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId())
     {
         objectNode.Nodes.Add(new ObjectNode(childRelationRow.ObjectRowByFKObjectObjectTreeChildId));
     }
 }
示例#4
0
        /// <summary>
        /// Constructor for a common object.
        /// </summary>
        /// <param name="objectId">The objects' unique identifier.</param>
        protected virtual void Initialize(int objectId)
        {
            ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(objectId);
            if (objectRow == null)
            {
                throw new Exception(String.Format("Object {0} doesn't exist", objectId));
            }

            Initialize(objectRow);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the ObjectNode class.
        /// </summary>
        public ObjectNode(ClientMarketData.ObjectRow objectRow) :
            base(objectRow.Name, UnselectedIndex(objectRow), SelectedIndex(objectRow))
        {
            // Add the attributes to the parent node.
            this.objectId       = objectRow.ObjectId;
            this.objectTypeCode = objectRow.ObjectTypeCode;
            this.name           = objectRow.Name;

            // And recursivley add the children.
            RecurseNodes(this, objectRow);
        }
示例#6
0
        private void RecurseBlotter(XmlNode parentNode, ClientMarketData.ObjectRow objectRow)
        {
            foreach (ClientMarketData.ObjectTreeRow objectTreeRow in objectRow.GetObjectTreeRowsByObjectObjectTreeParentId())
            {
                RecurseBlotter(parentNode, objectTreeRow.ObjectRowByObjectObjectTreeChildId);
            }

            foreach (ClientMarketData.BlotterRow blotterRow in objectRow.GetBlotterRows())
            {
                foreach (ClientMarketData.WorkingOrderRow workingOrderRow in blotterRow.GetWorkingOrderRows())
                {
                    parentNode.AppendChild(new WorkingOrderElement(this, workingOrderRow, FieldArray.Set));
                }
            }
        }
示例#7
0
        /// <summary>
        /// Creates a TreeNode with the attributes of an object found in the database.
        /// </summary>
        /// <param name="objectRow">A row that describes how to construct the attributes for this node.</param>
        /// <returns>A node that contains the attributes of the object found in the database, and its descendants.</returns>
        private TreeNode CreateTreeNode(ArrayList images, ClientMarketData.ObjectRow objectRow)
        {
            // This node will be attached to the tree view in a hierarchical order according to the data found in the 'ObjectTree'
            // data structure.  The node itself will be given the properties of the object in the database used to create this
            // node.
            TreeNode treeNode = new TreeNode();

            // IMPORTANT CONCEPT: This will extract the specification for the type from the database and construct an instance of
            // an object of that type.  For instance, the specification 'MarkThree.Guardian.Blotter, Object Library' would be used
            // to build a 'MarkThree.Guardian.Blotter' object from the 'Object Library'.  The object identifier is used to populate
            // the object from the persistent store with the properties of that item.  Once the object is built, it is installed in
            // the tree. When the user selects and item on the tree to be opened, this object is passed to the container which will
            // know how to view the object based on its type and the viewer mapped to that type.
            TypeSpecification typeSpecification = new TypeSpecification(objectRow.TypeRow.Specification);
            Assembly          assembly          = Assembly.Load(typeSpecification.AssemblyName);

            MarkThree.Guardian.Object folderObject = (MarkThree.Guardian.Object)assembly.CreateInstance(
                typeSpecification.TypeName, false, BindingFlags.CreateInstance, null, new object[] { objectRow.ObjectId },
                System.Globalization.CultureInfo.CurrentCulture, null);

            // The attributes of the object just created become the main attributes of the TreeNode.
            treeNode.Tag  = folderObject;
            treeNode.Text = folderObject.Name;

            // The 'Image' is the picture that is displayed in the TreeView along with the text.  It's the visual que that shows
            // what kind of object is stored on the tree.  The 'ImageKey' is a unique key that allows the TreeView control to map a
            // node to an item in the ImageList.
            if (folderObject.Image16x16 != null)
            {
                treeNode.ImageKey = (string)folderObject.Image16x16.Tag;
                images.Add(folderObject.Image16x16);
            }

            // This is the image that is displayed when the object is selected.
            if (folderObject.SelectedImage16x16 != null)
            {
                treeNode.SelectedImageKey = (string)folderObject.SelectedImage16x16.Tag;
                images.Add(folderObject.SelectedImage16x16);
            }

            // And recursivley add the children.
            RecurseNodes(images, treeNode, objectRow);

            // This represents the node that was created above, and all the children found in the hierarchy.
            return(treeNode);
        }
示例#8
0
        /// <summary>
        /// Creates an object from the object identifier.  This method assumes that the tables are locked.
        /// </summary>
        /// <param name="objectId">The unique object identifier.</param>
        /// <returns>One of the objects recognized by the Guaridan application.</returns>
        public static MarkThree.Guardian.Object CreateObject(int objectId)
        {
            // If the object record doesn't exist, then the record can't be created.  This is likely due to the fact that the data
            // model hasn't been loaded from the server at this time.
            ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(objectId);
            if (objectRow == null)
            {
                return(null);
            }

            // This will use the data in the object record to build a call to the constructor for that object.
            TypeSpecification typeSpecification = new TypeSpecification(objectRow.TypeRow.Specification);
            Assembly          assembly          = Assembly.Load(typeSpecification.AssemblyName);

            return((MarkThree.Guardian.Object)assembly.CreateInstance(typeSpecification.TypeName, false,
                                                                      BindingFlags.CreateInstance, null, new object[] { objectRow.ObjectId },
                                                                      System.Globalization.CultureInfo.CurrentCulture, null));
        }
示例#9
0
        /// <summary>
        /// Construct a hierarchical tree structure by recursively scanning the parent-child relations.
        /// </summary>
        /// <param name="objectNode">The current node in the tree structure.</param>
        private void RecurseNodes(ObjectNode objectNode)
        {
            // Recursion is sometimes difficult to follow.  At this point, we have an object node with a valid object. We
            // know that all the ancestors of this node have been populated already, so we're just concerned with finding
            // the descendants.  The 'ObjectTree' table can be used effectively for this.  Simply trace the parent
            // relation back to the 'ObjectTree' and you have a list of children.  For every child we find, we're going to
            // recurse down until there are no more descendants.
            ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(objectNode.ObjectId);
            foreach (ClientMarketData.ObjectTreeRow childRelationRow in objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId())
            {
                // Trace the 'child id' column back to the 'objects' table and get the full record that belongs to
                // this relation.  We can create a new node from this information and add it to the tree.
                ObjectNode childNode = new ObjectNode(childRelationRow.ObjectRowByFKObjectObjectTreeChildId);
                objectNode.Nodes.Add(childNode);

                // Finally, go look for any children of this node.
                RecurseNodes(childNode);
            }
        }
示例#10
0
        /// <summary>
        /// Shows a dialog box for maintaining an object or fund.
        /// </summary>
        /// <param name="objectId">Primary identifier for the object.</param>
        public virtual void Show(MarkThree.Guardian.Object guardianObject)
        {
            try
            {
                // Make sure locks are not nested.
                Debug.Assert(!ClientMarketData.IsLocked);

                // Lock the tables needed for the dialog.
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TypeLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Find the object in the data model.
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(guardianObject.ObjectId);
                if (objectRow == null)
                {
                    throw new Exception("Some else has deleted this object.");
                }

                // General Tab
                this.textBoxName.Text        = objectRow.Name;
                this.labelTypeText.Text      = objectRow.TypeRow.Description;
                this.textBoxDescription.Text = (objectRow.IsDescriptionNull()) ? string.Empty : objectRow.Description;
                this.pictureBox.Image        = guardianObject.Image32x32;
            }
            finally
            {
                // Release the tables used for the dialog.
                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.
            ShowDialog();
        }
示例#11
0
 protected void Initialize(ClientMarketData.ObjectRow objectRow)
 {
     this.objectId   = objectRow.ObjectId;
     this.objectType = (ObjectType)objectRow.ObjectTypeCode;
     this.name       = objectRow.Name;
     if (!objectRow.IsDescriptionNull())
     {
         this.description = objectRow.Description;
     }
     if (!objectRow.IsExternalId0Null())
     {
         this.userId0 = objectRow.ExternalId0;
     }
     if (!objectRow.IsExternalId1Null())
     {
         this.userId1 = objectRow.ExternalId1;
     }
     if (!objectRow.IsExternalId2Null())
     {
         this.userId2 = objectRow.ExternalId2;
     }
     if (!objectRow.IsExternalId3Null())
     {
         this.userId3 = objectRow.ExternalId3;
     }
     if (!objectRow.IsExternalId4Null())
     {
         this.userId4 = objectRow.ExternalId4;
     }
     if (!objectRow.IsExternalId5Null())
     {
         this.userId5 = objectRow.ExternalId5;
     }
     if (!objectRow.IsExternalId6Null())
     {
         this.userId6 = objectRow.ExternalId6;
     }
     if (!objectRow.IsExternalId7Null())
     {
         this.userId7 = objectRow.ExternalId7;
     }
 }
示例#12
0
        private void RecurseBlotter(XmlNode parentNode, ClientMarketData.ObjectRow objectRow)
        {
            foreach (ClientMarketData.ObjectTreeRow objectTreeRow in objectRow.GetObjectTreeRowsByObjectObjectTreeParentId())
            {
                RecurseBlotter(parentNode, objectTreeRow.ObjectRowByObjectObjectTreeChildId);
            }

            foreach (ClientMarketData.BlotterRow blotterRow in objectRow.GetBlotterRows())
            {
                foreach (ClientMarketData.WorkingOrderRow workingOrderRow in blotterRow.GetWorkingOrderRows())
                {
                    foreach (ClientMarketData.MatchRow matchRow in workingOrderRow.GetMatchRows())
                    {
                        if (matchRow.StatusCode == Status.Active)
                        {
                            parentNode.AppendChild(new MatchElement(this, matchRow, FieldArray.Set));
                        }
                    }
                }
            }
        }
示例#13
0
        private bool IsChildBlotter(ClientMarketData.BlotterRow parentBlotter, int blotterId)
        {
            if (parentBlotter.BlotterId == blotterId)
            {
                return(true);
            }

            ClientMarketData.ObjectRow parentObject = parentBlotter.ObjectRow;
            foreach (ClientMarketData.ObjectTreeRow objectTreeRow in parentObject.GetObjectTreeRowsByObjectObjectTreeParentId())
            {
                foreach (ClientMarketData.BlotterRow childBlotter in objectTreeRow.ObjectRowByObjectObjectTreeChildId.GetBlotterRows())
                {
                    if (IsChildBlotter(childBlotter, this.blotter.BlotterId))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#14
0
        /// <summary>
        /// Provides a mapping between the document type and the typeCode of the selected image for the node.
        /// </summary>
        /// <param name="typeCode">Identifies what kind of Quasar object the node prepresents.</param>
        /// <returns></returns>
        private static int UnselectedIndex(ClientMarketData.ObjectRow objectRow)
        {
            switch (objectRow.ObjectTypeCode)
            {
            case ObjectType.Account:

                foreach (ClientMarketData.AccountRow accountRow in objectRow.GetAccountRows())
                {
                    return(unselectedAccountIndex[accountRow.AccountTypeCode]);
                }
                break;

            case ObjectType.Blotter:

                foreach (ClientMarketData.BlotterRow blotterRow in objectRow.GetBlotterRows())
                {
                    return(unselectedBlotterIndex[blotterRow.BlotterTypeCode]);
                }
                break;

            case ObjectType.Folder:

                foreach (ClientMarketData.FolderRow folderRow in objectRow.GetFolderRows())
                {
                    return(unselectedFolderIndex[folderRow.FolderTypeCode]);
                }
                break;

            case ObjectType.Model:

                foreach (ClientMarketData.ModelRow modelRow in objectRow.GetModelRows())
                {
                    return(unselectedModelIndex[modelRow.ModelTypeCode]);
                }
                break;
            }

            // This catches any generic types and maps them to the first bitmap as a default.
            return(0);
        }
示例#15
0
        private bool RecurseContains(ClientMarketData.ObjectRow objectRow, int securityId)
        {
            foreach (ClientMarketData.ObjectTreeRow objectsTreeRow in objectRow.GetObjectTreeRowsByFKObjectObjectTreeParentId())
            {
                foreach (ClientMarketData.SectorRow sectorRow in objectsTreeRow.ObjectRowByFKObjectObjectTreeChildId.GetSectorRows())
                {
                    if (RecurseContains(sectorRow.ObjectRow, securityId))
                    {
                        return(true);
                    }
                }

                foreach (ClientMarketData.SecurityRow securityRow in objectsTreeRow.ObjectRowByFKObjectObjectTreeChildId.GetSecurityRows())
                {
                    if (securityRow.SecurityId == securityId)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#16
0
        /// <summary>
        /// Recusively builds the XML document from the document outline.
        /// </summary>
        /// <param name="parentElement">The parent XML element the node being built.</param>
        /// <param name="parentSecurity">The parent security.</param>
        private void BuildDocument(CommonElement parentElement, AppraisalSet.ObjectRow parentObject)
        {
            // The code below will test to see if the current node is a sector or security, then create the appropriate
            // element. The outline doesn't have the full information about the securities, so we need to get a record
            // into the data model that can reference the security master.
            ClientMarketData.ObjectRow childObject = ClientMarketData.Object.FindByObjectId(parentObject.ObjectId);

            // Attach the sectors to this level of the document.
            foreach (ClientMarketData.SectorRow sectorRow in childObject.GetSectorRows())
            {
                // Create the new sector element and attach it to the document.
                SectorElement sectorElement = new SectorElement(this, sectorRow);
                parentElement.InsertBySortOrder(sectorElement);

                // Recurse down into the children securities looking for more sectors or securities to attach.
                foreach (AppraisalSet.ObjectTreeRow objectTreeRow in parentObject.GetObjectTreeRowsByFKObjectObjectTreeParentId())
                {
                    BuildDocument(sectorElement, objectTreeRow.ObjectRowByFKObjectObjectTreeChildId);
                }
            }

            // Attach the securities to this level of the document.
            foreach (ClientMarketData.SecurityRow securityRow in childObject.GetSecurityRows())
            {
                // Attach long and short Debts to this level of the document.
                foreach (ClientMarketData.DebtRow debtRow in securityRow.GetDebtRowsByFKSecurityDebtDebtId())
                {
                    foreach (AppraisalSet.SecurityRow driverSecurity in parentObject.GetSecurityRows())
                    {
                        foreach (AppraisalSet.PositionRow driverPosition in driverSecurity.GetPositionRows())
                        {
                            parentElement.InsertByName(new DebtElement(this, debtRow, driverPosition));
                        }
                    }
                }

                // Attach long and short Currencies to this level of the document.
                foreach (ClientMarketData.CurrencyRow currencyRow in securityRow.GetCurrencyRows())
                {
                    foreach (AppraisalSet.SecurityRow driverSecurity in parentObject.GetSecurityRows())
                    {
                        foreach (AppraisalSet.PositionRow driverPosition in driverSecurity.GetPositionRows())
                        {
                            parentElement.InsertByName(new CurrencyElement(this, currencyRow, driverPosition));
                        }
                    }
                }

                // Attach long and short Equities to this level of the document.
                foreach (ClientMarketData.EquityRow equityRow in securityRow.GetEquityRowsByFKSecurityEquityEquityId())
                {
                    foreach (AppraisalSet.SecurityRow driverSecurity in parentObject.GetSecurityRows())
                    {
                        foreach (AppraisalSet.PositionRow driverPosition in driverSecurity.GetPositionRows())
                        {
                            parentElement.InsertByName(new EquityElement(this, equityRow, driverPosition));
                        }
                    }
                }
            }
        }
示例#17
0
        /// <summary>
        /// Creates a Currency Element for an Appraisal Document.
        /// </summary>
        /// <param name="appraisalDocument">The parent Xml Document.</param>
        /// <param name="currencyRow">A currency record in the data model.</param>
        /// <param name="PositionTypeCode">Whether a short or long position.</param>
        public CurrencyElement(AppraisalDocument appraisalDocument, ClientMarketData.CurrencyRow currencyRow,
                               AppraisalSet.PositionRow positionRow) : base("Currency", appraisalDocument)
        {
            // These records are used to access information held in the ancestors.
            ClientMarketData.SecurityRow securityRow = currencyRow.SecurityRow;
            ClientMarketData.ObjectRow   objectRow   = securityRow.ObjectRow;

            // Add the essential attributes for this element.
            AddAttribute("SecurityId", currencyRow.CurrencyId.ToString());
            AddAttribute("PositionTypeCode", positionRow.PositionTypeCode.ToString());
            AddAttribute("Name", objectRow.Name.ToString());

            // Add the price info.
            ClientMarketData.PriceRow priceRow =
                ClientMarketData.Price.FindBySecurityIdCurrencyId(securityRow.SecurityId,
                                                                  appraisalDocument.AccountRow.CurrencyRow.CurrencyId);
            if (priceRow == null)
            {
                AddAttribute("Price", "0.0");
            }
            else
            {
                if (ClientPreferences.Pricing == Pricing.Close)
                {
                    AddAttribute("Price", priceRow.ClosePrice.ToString());
                }
                if (ClientPreferences.Pricing == Pricing.Last)
                {
                    AddAttribute("Price", priceRow.LastPrice.ToString());
                }
            }

            // Add a target percentage if one is associated with this security.
            ClientMarketData.PositionTargetRow positionTargetRow =
                ClientMarketData.PositionTarget.FindByModelIdSecurityIdPositionTypeCode(
                    appraisalDocument.ModelRow.ModelId, currencyRow.CurrencyId, positionRow.PositionTypeCode);
            if (positionTargetRow != null)
            {
                AddAttribute("ModelPercent", positionTargetRow.Percent.ToString());
            }

            // If there is a position record associated with this, er..  position, then add the externally supplied data
            // to the record.  Since the tax lots are always aggregated as we need them into a position, there's no static
            // table that keeps position data.  This information is generally from an outside system that is related to
            // the position, such as risk metrics or quantitative calculations.
            ClientMarketData.PositionRow position = ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(
                appraisalDocument.AccountRow.AccountId, positionRow.SecurityId, positionRow.PositionTypeCode);
            if (position != null)
            {
                if (!position.IsUserData0Null())
                {
                    AddAttribute("UserData0", position.UserData0.ToString());
                }
                if (!position.IsUserData1Null())
                {
                    AddAttribute("UserData1", position.UserData1.ToString());
                }
                if (!position.IsUserData2Null())
                {
                    AddAttribute("UserData2", position.UserData2.ToString());
                }
                if (!position.IsUserData3Null())
                {
                    AddAttribute("UserData3", position.UserData3.ToString());
                }
                if (!position.IsUserData4Null())
                {
                    AddAttribute("UserData4", position.UserData4.ToString());
                }
                if (!position.IsUserData5Null())
                {
                    AddAttribute("UserData5", position.UserData5.ToString());
                }
                if (!position.IsUserData6Null())
                {
                    AddAttribute("UserData6", position.UserData6.ToString());
                }
                if (!position.IsUserData7Null())
                {
                    AddAttribute("UserData7", position.UserData7.ToString());
                }
            }

            // Append the account level aggregates to this security/position type element.
            foreach (AppraisalSet.AccountRow accountRow in positionRow.GetAccountRows())
            {
                this.AppendChild(new AccountElement(appraisalDocument, accountRow));
            }
        }
示例#18
0
        /// <summary>
        /// Moves a child object from one parent to another.
        /// </summary>
        /// <param name="parameter">An array consiting of the target parent, the current parent and the child to be moved.</param>
        private void MoveChild(object parameter)
        {
            // Extract the objects selected by the drag-and-drop operation.
            object[] parameters = (object[])parameter;
            MarkThree.Guardian.Object toObject    = (MarkThree.Guardian.Object)parameters[0];
            MarkThree.Guardian.Object fromObject  = (MarkThree.Guardian.Object)parameters[1];
            MarkThree.Guardian.Object childObject = (MarkThree.Guardian.Object)parameters[2];

            try
            {
                // Lock the tables needed for this operation.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);

                // It's critical that circular references aren't created, either by accident or design.  First, find the object
                // record associated with the destination node.
                ClientMarketData.ObjectRow parentRow = ClientMarketData.Object.FindByObjectId(toObject.ObjectId);
                if (parentRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // This is the object that is being dragged.  Find the row
                ClientMarketData.ObjectRow childRow = ClientMarketData.Object.FindByObjectId(childObject.ObjectId);
                if (childRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // This will remove the possibility of a circular relationship.
                if (MarkThree.Guardian.Relationship.IsChildObject(childRow, parentRow))
                {
                    Invoke(new MessageDelegate(ShowMessage), Properties.Resources.CircularReferenceError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // Any commands created below will be constructed in this object and sent to the server for execution.
            bool  isBatchValid = true;
            Batch batch        = new Batch();

            // If we made it here, the drag-and-drop is interpreted as a command to move a child from one parent to another.
            try
            {
                // Lock the tables needed for this operation.
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Extract the primary identifiers from the user interface nodes.
                // This is the object that is being dragged.  Find the row
                ClientMarketData.ObjectRow childRow = ClientMarketData.Object.FindByObjectId(childObject.ObjectId);
                if (childRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // Find the object in the data model and make sure it still exists.
                ClientMarketData.ObjectTreeRow objectTreeRow = null;
                foreach (ClientMarketData.ObjectTreeRow innerObjectTreeRow in childRow.GetObjectTreeRowsByObjectObjectTreeChildId())
                {
                    if (innerObjectTreeRow.ParentId == fromObject.ObjectId)
                    {
                        objectTreeRow = innerObjectTreeRow;
                    }
                }
                if (objectTreeRow == null)
                {
                    throw new Exception("This relationship has been deleted by someone else.");
                }

                // Moving a child object from one parent to another must be accomplished as a transaction.  Otherwise, an
                // orhpan object will be created if the operation fails midway through.
                TransactionPlan transaction = batch.Transactions.Add();
                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.ObjectTree");

                // Construct a command delete the old parent relation.
                MethodPlan deleteObjectTree = transaction.Methods.Add(type, "Update");
                deleteObjectTree.Parameters.Add(new InputParameter("objectTreeId", objectTreeRow.ObjectTreeId));
                deleteObjectTree.Parameters.Add(new InputParameter("parentId", toObject.ObjectId));
                deleteObjectTree.Parameters.Add(new InputParameter("childId", childObject.ObjectId));
                deleteObjectTree.Parameters.Add(new InputParameter("rowVersion", objectTreeRow.RowVersion));
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);

                // This indicates that the batch shouldn't be executed.
                isBatchValid = false;
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.
            if (isBatchValid)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there are
                    // no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        MessageBox.Show(exception.Message, "Guardian Error");
                    }
                }
            }
        }
示例#19
0
        /// <summary>
        /// Rename the object.
        /// </summary>
        /// <param name="parameters">The object to be renamed.</param>
        private void RenameObject(object parameter)
        {
            // Extract the thread arguments
            object[] parameters = (object[])parameter;
            TreeNode treeNode   = (TreeNode)parameters[0];
            string   name       = (string)parameters[1];

            // Extract the object that is associated with the TreeView node.
            MarkThree.Guardian.Object commonObject = (MarkThree.Guardian.Object)treeNode.Tag;

            // This command batch is constructed below and sent to the server for execution.  Note that the batch is designed to
            // live beyond the block of code that locks the data model.  This is to prevent the data model from being locked while
            // a relatively long server database operation is underway.
            bool  isBatchValid = true;
            Batch batch        = new Batch();

            try
            {
                // Lock the table
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Find the object in the data model and make sure it still exists.
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(commonObject.ObjectId);
                if (objectRow == null)
                {
                    throw new Exception("This object has been deleted.");
                }

                // Construct a command to rename the object.
                AssemblyPlan    assembly    = batch.Assemblies.Add("Core Service");
                TypePlan        type        = assembly.Types.Add("MarkThree.Guardian.Core.Object");
                TransactionPlan transaction = batch.Transactions.Add();
                MethodPlan      method      = transaction.Methods.Add(type, "Update");
                method.Parameters.Add(new InputParameter("rowVersion", objectRow.RowVersion));
                method.Parameters.Add(new InputParameter("objectId", objectRow.ObjectId));
                method.Parameters.Add(new InputParameter("name", name));
            }
            catch (Exception exception)
            {
                // This serves as an indication that the batch couldn't be constructed.
                isBatchValid = false;

                // Write the error and stack trace out to the debug listener
                EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace);
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }

            // If the command batch was built successfully, then execute it.  If any part of it should fail, cancel the edit and
            // display the server errors.
            if (isBatchValid)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there
                    // are no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(batch);
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (Exception exception in batchException.Exceptions)
                    {
                        Invoke(new MessageDelegate(ShowMessage), exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
示例#20
0
        /// <summary>
        /// Creates an Equity Element for an Appriasal Document.
        /// </summary>
        /// <param name="appraisalDocument">The parent Xml Document.</param>
        /// <param name="equityRow">An equity record from the data model.</param>
        /// <param name="PositionTypeCode">Whether a short or long position.</param>
        public EquityElement(AppraisalDocument appraisalDocument, ClientMarketData.EquityRow equityRow,
                             AppraisalSet.PositionRow positionRow) : base("Equity", appraisalDocument)
        {
            // These records are used to access information held in the ancestors.
            ClientMarketData.SecurityRow securityRow = equityRow.SecurityRowByFKSecurityEquityEquityId;
            ClientMarketData.ObjectRow   objectRow   = securityRow.ObjectRow;

            // Add the essential attributes for this element.
            AddAttribute("SecurityId", equityRow.EquityId.ToString());
            AddAttribute("PositionTypeCode", positionRow.PositionTypeCode.ToString());
            AddAttribute("Name", objectRow.Name.ToString());
            AddAttribute("PriceFactor", securityRow.PriceFactor.ToString());
            AddAttribute("QuantityFactor", securityRow.QuantityFactor.ToString());

            // Find the price based on the default currency found in the equity record.  If the security master doesn't
            // have a price for this security, provide dummy values to insure a market value can be calculated.  Zero is a
            // perfectly reasonable interpretation of a missing price.
            ClientMarketData.PriceRow securityPrice = ClientMarketData.Price.FindBySecurityIdCurrencyId(
                securityRow.SecurityId, equityRow.SettlementId);
            if (securityPrice == null)
            {
                AddAttribute("Price", "0.0");
            }
            else
            {
                if (ClientPreferences.Pricing == Pricing.Close)
                {
                    AddAttribute("Price", securityPrice.ClosePrice.ToString());
                }
                if (ClientPreferences.Pricing == Pricing.Last)
                {
                    AddAttribute("Price", securityPrice.LastPrice.ToString());
                }
            }

            // Find the crossing price.  This is used to convert any local price into the account's base currency. Provide
            // defaults if the crossing price can be found.  While this will lead to wrong values, they will be obvious on
            // the appraisal.
            ClientMarketData.PriceRow currencyPrice = ClientMarketData.Price.FindBySecurityIdCurrencyId(
                equityRow.SettlementId, appraisalDocument.AccountRow.CurrencyRow.CurrencyId);
            if (currencyPrice == null)
            {
                AddAttribute("CloseCrossPrice", "0.0");
                AddAttribute("LastCrossPrice", "0.0");
            }
            else
            {
                AddAttribute("CloseCrossPrice", currencyPrice.ClosePrice.ToString());
                AddAttribute("LastCrossPrice", currencyPrice.LastPrice.ToString());
            }

            // Add a target percentage if one is associated with this security.
            ClientMarketData.PositionTargetRow positionTargetRow =
                ClientMarketData.PositionTarget.FindByModelIdSecurityIdPositionTypeCode(
                    appraisalDocument.ModelRow.ModelId, equityRow.EquityId, positionRow.PositionTypeCode);
            if (positionTargetRow != null)
            {
                AddAttribute("ModelPercent", positionTargetRow.Percent.ToString());
            }

            // If there is a position record associated with this, er..  position, then add the externally supplied data
            // to the record.  Since the tax lots are always aggregated as we need them into a position, there's no static
            // table that keeps position data.  This information is generally from an outside system that is related to
            // the position, such as risk metrics or quantitative calculations.
            ClientMarketData.PositionRow position = ClientMarketData.Position.FindByAccountIdSecurityIdPositionTypeCode(
                appraisalDocument.AccountRow.AccountId, positionRow.SecurityId, positionRow.PositionTypeCode);
            if (position != null)
            {
                if (!position.IsUserData0Null())
                {
                    AddAttribute("UserData0", position.UserData0.ToString());
                }
                if (!position.IsUserData1Null())
                {
                    AddAttribute("UserData1", position.UserData1.ToString());
                }
                if (!position.IsUserData2Null())
                {
                    AddAttribute("UserData2", position.UserData2.ToString());
                }
                if (!position.IsUserData3Null())
                {
                    AddAttribute("UserData3", position.UserData3.ToString());
                }
                if (!position.IsUserData4Null())
                {
                    AddAttribute("UserData4", position.UserData4.ToString());
                }
                if (!position.IsUserData5Null())
                {
                    AddAttribute("UserData5", position.UserData5.ToString());
                }
                if (!position.IsUserData6Null())
                {
                    AddAttribute("UserData6", position.UserData6.ToString());
                }
                if (!position.IsUserData7Null())
                {
                    AddAttribute("UserData7", position.UserData7.ToString());
                }
            }

            // Add the account level aggregates for this security/position type pair.
            foreach (AppraisalSet.AccountRow accountRow in positionRow.GetAccountRows())
            {
                this.AppendChild(new AccountElement(appraisalDocument, accountRow));
            }
        }
示例#21
0
        /// <summary>
        /// Creates a well formed working order document object model.
        /// </summary>
        /// <param name="userId">The blotter identifies what blocks are to be included in this document.</param>
        public MatchHistoryDocument(int userId)
        {
            try
            {
                // Lock the tables
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SourceOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.MatchLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StatusLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Create the root element for the document.
                XmlNode documentNode = this.AppendChild(this.CreateElement("Document"));

                // Find the top level blotter record and recursively construct the report by merging all the children.
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(userId);
                if (objectRow != null)
                {
                    RecurseBlotter(documentNode, objectRow);
                }
            }
            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.SourceOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.SourceOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ExecutionLock.IsReaderLockHeld)
                {
                    ClientMarketData.ExecutionLock.ReleaseReaderLock();
                }
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StatusLock.IsReaderLockHeld)
                {
                    ClientMarketData.StatusLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StylesheetLock.IsReaderLockHeld)
                {
                    ClientMarketData.StylesheetLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TimeInForceLock.IsReaderLockHeld)
                {
                    ClientMarketData.TimeInForceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.UserLock.IsReaderLockHeld)
                {
                    ClientMarketData.UserLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }
        }
示例#22
0
        /// <summary>
        /// Creates a well formed working order document object model.
        /// </summary>
        /// <param name="blotterId">The blotter identifies what blocks are to be included in this document.</param>
        public ExecutionDocument(Blotter blotter, WorkingOrder[] workingOrders)
        {
            try
            {
                // Lock the tables
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.BrokerLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.BrokerAccountLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SourceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StateLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Create the root element for the document.
                XmlNode documentNode = this.AppendChild(this.CreateElement("Document"));

                if (workingOrders == null)
                {
                    // Find the top level blotter record and recursively construct the report by merging all the children.
                    ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(blotter.BlotterId);
                    if (objectRow != null)
                    {
                        RecurseBlotter(documentNode, objectRow);
                    }
                }
                else
                {
                    foreach (WorkingOrder workingOrder in workingOrders)
                    {
                        ClientMarketData.WorkingOrderRow workingOrderRow = ClientMarketData.WorkingOrder.FindByWorkingOrderId(workingOrder.WorkingOrderId);
                        if (workingOrderRow != null)
                        {
                            foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows())
                            {
                                foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows())
                                {
                                    documentNode.AppendChild(new ExecutionElement(this, executionRow, FieldArray.Set));
                                }
                            }
                        }
                    }
                }
            }
            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.BrokerAccountLock.IsReaderLockHeld)
                {
                    ClientMarketData.BrokerAccountLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ExecutionLock.IsReaderLockHeld)
                {
                    ClientMarketData.ExecutionLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StateLock.IsReaderLockHeld)
                {
                    ClientMarketData.StateLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SourceLock.IsReaderLockHeld)
                {
                    ClientMarketData.SourceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StylesheetLock.IsReaderLockHeld)
                {
                    ClientMarketData.StylesheetLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TimeInForceLock.IsReaderLockHeld)
                {
                    ClientMarketData.TimeInForceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.UserLock.IsReaderLockHeld)
                {
                    ClientMarketData.UserLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }
        }
示例#23
0
        private void DragDropHandler(params object[] arguments)
        {
            ObjectNode toNode    = (ObjectNode)arguments[0];
            ObjectNode fromNode  = (ObjectNode)arguments[1];
            ObjectNode childNode = (ObjectNode)arguments[2];

            // Make sure the user has selected a valid source and destination for the operation.  It's illegal to move the node
            //		1.  To the root of the tree
            //		2.  From the root of the tree
            if (toNode == null || fromNode == null)
            {
                return;
            }

            // Don't allow for circular references.
            try
            {
                // Lock the tables needed for this operation.
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);

                // It's critical that circular references aren't created, either by accident or design.  First, find the object
                // record associated with the destination node.
                ClientMarketData.ObjectRow parentRow = ClientMarketData.Object.FindByObjectId(toNode.ObjectId);
                if (parentRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                // This is the object that is being dragged.  Find the row
                ClientMarketData.ObjectRow childRow = ClientMarketData.Object.FindByObjectId(childNode.ObjectId);
                if (childRow == null)
                {
                    throw new Exception("This object has been deleted");
                }

                if (Shadows.Quasar.Common.Relationship.IsChildObject(childRow, parentRow))
                {
                    MessageBox.Show(this.TopLevelControl, "This would create a circular references.", "Quasar Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                Debug.WriteLine(String.Format("{0}, {1}", exception.Message, exception.StackTrace));
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }

            // Any commands created below will be constructed in this object and sent to the server for execution.
            RemoteBatch remoteBatch = new RemoteBatch();

            // Change the default model of an account.  When the destination is an account group, account or sub account and the
            // source is a model, a command will be constructed to change the default model.
            if (toNode.ObjectTypeCode == ObjectType.Account && dragNode.ObjectTypeCode == ObjectType.Model)
            {
                try
                {
                    // Lock the tables needed for this operation.
                    Debug.Assert(!ClientMarketData.AreLocksHeld);
                    ClientMarketData.AccountLock.AcquireReaderLock(CommonTimeout.LockWait);

                    // Find the account used, throw an error if it's been deleted.
                    ClientMarketData.AccountRow accountRow;
                    if ((accountRow = ClientMarketData.Account.FindByAccountId(toNode.ObjectId)) == null)
                    {
                        throw new Exception("This account has been deleted");
                    }

                    // Construct a command to change the default model associated with the account.
                    RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Core");
                    RemoteType     remoteType     = remoteAssembly.Types.Add("Shadows.WebService.Core.Account");
                    RemoteMethod   remoteMethod   = remoteType.Methods.Add("Update");
                    remoteMethod.Parameters.Add("rowVersion", accountRow.RowVersion);
                    remoteMethod.Parameters.Add("accountId", accountRow.AccountId);
                    remoteMethod.Parameters.Add("modelId", dragNode.ObjectId);
                }
                catch (Exception exception)
                {
                    // Write the error and stack trace out to the debug listener
                    Debug.WriteLine(String.Format("{0}, {1}", exception.Message, exception.StackTrace));
                }
                finally
                {
                    // Release table locks.
                    if (ClientMarketData.AccountLock.IsReaderLockHeld)
                    {
                        ClientMarketData.AccountLock.ReleaseReaderLock();
                    }
                    Debug.Assert(!ClientMarketData.AreLocksHeld);
                }
            }
            else
            {
                // If we made it here, the drag-and-drop is interpreted as a command to move a child from one parent to another.
                try
                {
                    // Lock the tables needed for this operation.
                    Debug.Assert(!ClientMarketData.AreLocksHeld);
                    ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);

                    // Extract the primary identifiers from the user interface nodes.
                    int fromId  = fromNode.ObjectId;
                    int toId    = toNode.ObjectId;
                    int childId = dragNode.ObjectId;

                    // Find the object in the data model and make sure it still exists.
                    ClientMarketData.ObjectTreeRow objectTreeRow = ClientMarketData.ObjectTree.FindByParentIdChildId(fromNode.ObjectId, dragNode.ObjectId);
                    if (objectTreeRow == null)
                    {
                        throw new Exception("This relationship has been deleted by someone else.");
                    }

                    // Moving a child object from one parent to another must be accomplished as a transaction.  Otherwise, an
                    // orhpan object will be created if the operation fails midway through.
                    RemoteTransaction remoteTransaction = remoteBatch.Transactions.Add();
                    RemoteAssembly    remoteAssembly    = remoteBatch.Assemblies.Add("Service.Core");
                    RemoteType        remoteType        = remoteAssembly.Types.Add("Shadows.WebService.Core.ObjectTree");

                    // Construct a command delete the old parent relation.
                    RemoteMethod deleteObjectTree = remoteType.Methods.Add("Delete");
                    deleteObjectTree.Transaction = remoteTransaction;
                    deleteObjectTree.Parameters.Add("rowVersion", objectTreeRow.RowVersion);
                    deleteObjectTree.Parameters.Add("parentId", fromId);
                    deleteObjectTree.Parameters.Add("childId", childId);

                    // Construct a command insert a new parent relation.
                    RemoteMethod insertObjectTree = remoteType.Methods.Add("Insert");
                    insertObjectTree.Transaction = remoteTransaction;
                    insertObjectTree.Parameters.Add("parentId", toId);
                    insertObjectTree.Parameters.Add("childId", childId);
                }
                catch (Exception exception)
                {
                    // Write the error and stack trace out to the debug listener
                    Debug.WriteLine(String.Format("{0}, {1}", exception.Message, exception.StackTrace));
                }
                finally
                {
                    // Release table locks.
                    if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                    {
                        ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                    }
                    Debug.Assert(!ClientMarketData.AreLocksHeld);
                }
            }

            // If the command batch was built successfully, then execute it.
            if (remoteBatch != null)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there are
                    // no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(remoteBatch);
                }
                catch (BatchException batchException)
                {
                    // Display each error in the batch.
                    foreach (RemoteException remoteException in batchException.Exceptions)
                    {
                        MessageBox.Show(remoteException.Message, "Quasar Error");
                    }
                }
            }
        }
示例#24
0
        /// <summary>
        /// Event handler for changing the name of a label.
        /// </summary>
        /// <param name="sender">The window control that generated the 'LabelEdit' event.</param>
        /// <param name="e">Event Parameters used to control the actions taken by the event handler.</param>
        private void treeView_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)
        {
            // The TreeView has a bug in it: if you leave the edit mode without typing anything, the returned text of the control
            // will be an empty string. Since we don't want to bother the server or the user with this nonsense, we'll filter out
            // the possiblity here.
            if (e.Label == null)
            {
                e.CancelEdit = true;
                return;
            }

            // Extract the object's properties from the node.
            ObjectNode objectNode = (ObjectNode)e.Node;

            // This command batch is constructed below and sent to the server for execution.
            RemoteBatch remoteBatch = new RemoteBatch();

            // This will insure that table locks are cleaned up.
            try
            {
                // Lock the table
                Debug.Assert(!ClientMarketData.AreLocksHeld);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Find the object in the data model and make sure it still exists.
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(objectNode.ObjectId);
                if (objectRow == null)
                {
                    throw new Exception("This object has been deleted.");
                }

                // Construct a command to rename the object.
                RemoteAssembly remoteAssembly = remoteBatch.Assemblies.Add("Service.Core");
                RemoteType     remoteType     = remoteAssembly.Types.Add("Shadows.WebService.Core.Object");
                RemoteMethod   remoteMethod   = remoteType.Methods.Add("Update");
                remoteMethod.Parameters.Add("rowVersion", objectRow.RowVersion);
                remoteMethod.Parameters.Add("objectId", objectRow.ObjectId);
                remoteMethod.Parameters.Add("name", e.Label);
            }
            catch (Exception exception)
            {
                // Write the error and stack trace out to the debug listener
                Debug.WriteLine(String.Format("{0}, {1}", exception.Message, exception.StackTrace));

                // Cancel the tree operation if we can't execute the command.  The text in the tree control will revert to the
                // previous value.
                e.CancelEdit = true;
            }
            finally
            {
                // Release table locks.
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                Debug.Assert(!ClientMarketData.AreLocksHeld);
            }

            // If the command batch was built successfully, then execute it.  If any part of it should fail, cancel the edit and
            // display the server errors.
            if (remoteBatch != null)
            {
                try
                {
                    // Call the web server to rename the object on the database.  Note that this method must be called when there are
                    // no locks to prevent deadlocking.  That is why it appears in it's own 'try/catch' block.
                    ClientMarketData.Execute(remoteBatch);
                }
                catch (BatchException batchException)
                {
                    // Undo the editing action.  This will restore the name of the object to what it was before the operation.
                    e.CancelEdit = true;

                    // Display each error in the batch.
                    foreach (RemoteException remoteException in batchException.Exceptions)
                    {
                        MessageBox.Show(remoteException.Message, "Quasar Error");
                    }
                }
            }
        }
示例#25
0
        /*
         * private void RecurseBlotter(XmlNode parentNode, ClientMarketData.ObjectRow objectRow)
         * {
         *  foreach (ClientMarketData.ObjectTreeRow objectTreeRow in objectRow.GetObjectTreeRowsByObjectObjectTreeParentId())
         *      RecurseBlotter(parentNode, objectTreeRow.ObjectRowByObjectObjectTreeChildId);
         *
         *  foreach (ClientMarketData.BlotterRow blotterRow in objectRow.GetBlotterRows())
         *      foreach (ClientMarketData.WorkingOrderRow workingOrderRow in blotterRow.GetWorkingOrderRows())
         *          foreach (ClientMarketData.MatchRow matchRow in workingOrderRow.GetMatchRows())
         *              parentNode.AppendChild(new MatchElement(this, matchRow, FieldArray.Set));
         *
         * }
         */


        /// <summary>
        /// Creates a well formed quote document object model.
        /// </summary>
        /// <param name="securityID">The user id that identifies the blotter being viewed.</param>
        public QuoteDocument(int securityId)
        {
            try
            {
                // Lock the tables
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
                ClientMarketData.BlotterLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SourceOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.DestinationOrderLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ExecutionLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.MatchLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.ObjectTreeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.OrderTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceTypeLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.PriceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.SecurityLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StatusLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.StylesheetLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.TimeInForceLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.UserLock.AcquireReaderLock(CommonTimeout.LockWait);
                ClientMarketData.WorkingOrderLock.AcquireReaderLock(CommonTimeout.LockWait);

                // Create the root element for the document.
                XmlNode documentNode = this.AppendChild(this.CreateElement("Document"));

                // build a Quote order document based on security id
                ClientMarketData.ObjectRow objectRow = ClientMarketData.Object.FindByObjectId(securityId);

                // navigate down to the price row
                if (objectRow != null)
                {
                    // get the security rows array - make sure it is non-null and there is at least 1 security in there
                    ClientMarketData.SecurityRow[] securityRows = objectRow.GetSecurityRows();
                    if (securityRows != null && securityRows.Length > 0)
                    {
                        // get the price rows - make sure non-null and there is at least 1 price row
                        ClientMarketData.PriceRow[] priceRows = securityRows[0].GetPriceRows();
                        if (priceRows != null && priceRows.Length > 0)
                        {
                            documentNode.AppendChild(new QuoteElement(this, priceRows[0], FieldArray.Set));
                        }
                    }
                }
            }
            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.SourceOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.SourceOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.DestinationOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.DestinationOrderLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ExecutionLock.IsReaderLockHeld)
                {
                    ClientMarketData.ExecutionLock.ReleaseReaderLock();
                }
                if (ClientMarketData.MatchLock.IsReaderLockHeld)
                {
                    ClientMarketData.MatchLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectLock.ReleaseReaderLock();
                }
                if (ClientMarketData.ObjectTreeLock.IsReaderLockHeld)
                {
                    ClientMarketData.ObjectTreeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.OrderTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.OrderTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceTypeLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceTypeLock.ReleaseReaderLock();
                }
                if (ClientMarketData.PriceLock.IsReaderLockHeld)
                {
                    ClientMarketData.PriceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.SecurityLock.IsReaderLockHeld)
                {
                    ClientMarketData.SecurityLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StatusLock.IsReaderLockHeld)
                {
                    ClientMarketData.StatusLock.ReleaseReaderLock();
                }
                if (ClientMarketData.StylesheetLock.IsReaderLockHeld)
                {
                    ClientMarketData.StylesheetLock.ReleaseReaderLock();
                }
                if (ClientMarketData.TimeInForceLock.IsReaderLockHeld)
                {
                    ClientMarketData.TimeInForceLock.ReleaseReaderLock();
                }
                if (ClientMarketData.UserLock.IsReaderLockHeld)
                {
                    ClientMarketData.UserLock.ReleaseReaderLock();
                }
                if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld)
                {
                    ClientMarketData.WorkingOrderLock.ReleaseReaderLock();
                }
                System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked);
            }
        }