Exemple #1
0
        /// <summary>
        /// Initialize the list of root folders.
        /// </summary>
        private void InitializeFolders()
        {
            lock (DataModel.SyncRoot)
            {
                LambdaComparer <FolderTreeNode> folderTreeNodeComparer = new LambdaComparer <FolderTreeNode>((l, r) => l.Entity.Name.CompareTo(r.Entity.Name));
                List <FolderTreeNode>           folders = new List <FolderTreeNode>();
                EntityRow userEntityRow = DataModel.Entity.EntityKey.Find(UserContext.Instance.UserId);

                foreach (EntityTreeRow entityTreeRow in userEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
                {
                    FolderTreeNode folderTreeNode = new FolderTreeNode(entityTreeRow);
                    Int32          index          = folders.BinarySearch(folderTreeNode, folderTreeNodeComparer);

                    if (index < 0)
                    {
                        index = ~index;
                    }

                    folders.Insert(index, folderTreeNode);
                }

                this.Dispatcher.BeginInvoke(new Action(delegate()
                {
                    this.Folders = folders;
                    this.ExpandFolder();
                }), DispatcherPriority.Normal);
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculate a unique entity name from a base name.
        /// </summary>
        /// <param name="transaction">The current transaction.</param>
        /// <param name="parentEntityRow">The (writelocked) entity that would be the parent of the entity we intend to name.</param>
        /// <param name="name">The base name (eg. the name of the entity, provided there isn't already a sibling with that name).</param>
        /// <returns>A unique name.</returns>
        private String GetUniqueName(DataModelTransaction transaction, EntityRow parentEntityRow, String name)
        {
            Int64         nameNumber    = 1;
            String        uniqueName    = name;
            List <String> existingNames = new List <String>();

            foreach (EntityTreeRow entityTree in parentEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                EntityRow entityRow;

                entityTree.AcquireReaderLock(transaction);
                entityRow = entityTree.EntityRowByFK_Entity_EntityTree_ChildId;
                entityTree.ReleaseLock(transaction.TransactionId);

                entityRow.AcquireReaderLock(transaction);
                existingNames.Add(entityRow.Name);
                entityRow.ReleaseLock(transaction.TransactionId);
            }

            existingNames.Sort();

            while (existingNames.BinarySearch(uniqueName) >= 0)
            {
                uniqueName  = String.Format("{0} ({1})", name, nameNumber);
                nameNumber += 1;
            }

            return(uniqueName);
        }
        /// <summary>
        /// Build the folder tree below this node.
        /// </summary>
        /// <param name="entityRow"></param>
        private void BuildTree(EntityRow entityRow)
        {
            EntityTreeRow[] entityTreeRows = entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId();

            foreach (EntityTreeRow entityTreeRow in entityTreeRows)
            {
                Boolean inserted = false;

                // Add the new tree relations in alphabetical order.
                for (int targetIndex = 0; !inserted && targetIndex < this.Children.Count; targetIndex++)
                {
                    if (entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId.Name.CompareTo(this.Children[targetIndex].Entity.Name) < 0)
                    {
                        this.Children.Insert(targetIndex, new FolderTreeNode(entityTreeRow));
                        inserted = true;
                    }
                }

                // Any we missed go at the end.
                if (!inserted)
                {
                    this.Children.Add(new FolderTreeNode(entityTreeRow));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Determine whether a name is unique within a parent entity.
        /// </summary>
        /// <param name="transaction"></param>
        /// <param name="parentEntityRow"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Boolean IsNameUnique(DataModelTransaction transaction, EntityRow parentEntityRow, String name)
        {
            Boolean isNameUnique = true;

            foreach (EntityTreeRow entityTree in parentEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                EntityRow entityRow;
                String    oldName;

                entityTree.AcquireReaderLock(transaction);
                entityRow = entityTree.EntityRowByFK_Entity_EntityTree_ChildId;
                entityTree.ReleaseLock(transaction.TransactionId);

                entityRow.AcquireReaderLock(transaction);
                oldName      = entityRow.Name;
                isNameUnique = !entityRow.Name.Equals(name);
                entityRow.ReleaseLock(transaction.TransactionId);

                if (!isNameUnique)
                {
                    break;
                }
            }

            return(isNameUnique);
        }
Exemple #5
0
        /// <summary>
        /// Initialize the list of root folders.
        /// </summary>
        private void InitializeFolders(Guid parentId)
        {
            lock (DataModel.SyncRoot)
            {
                LambdaComparer <FolderTreeNode> folderTreeNodeComparer = new LambdaComparer <FolderTreeNode>((l, r) => l.Entity.Name.CompareTo(r.Entity.Name));
                List <FolderTreeNode>           folders = new List <FolderTreeNode>();
                EntityRow parentEntityRow = DataModel.Entity.EntityKey.Find(parentId);

                foreach (EntityTreeRow entityTreeRow in parentEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
                {
                    FolderTreeNode folderTreeNode = new FolderTreeNode()
                    {
                        Entity = new Entity(entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId)
                    };
                    Int32 index = folders.BinarySearch(folderTreeNode, folderTreeNodeComparer);

                    if (index < 0)
                    {
                        index = ~index;
                    }

                    folders.Insert(index, folderTreeNode);
                }

                this.Dispatcher.BeginInvoke(new Action(() => this.Folders = folders), DispatcherPriority.Normal);
            }
        }
        /// <summary>
        /// Get a list of the entity names that describes the path to this object.
        /// </summary>
        /// <param name="current">The current entity in the path to the object.</param>
        /// <param name="target">The entityId of the entity we're building a path for.</param>
        /// <returns>The list of entity names that represent the path to the object.</returns>
        private List <string> GetLocation(EntityRow current, Guid target)
        {
            List <string> list = null;

            if (current == null)
            {
                return(null);
            }

            // If current is the entity that we're looking for, we'll create our own list.
            if (current.EntityId == target)
            {
                list = new List <string>();
            }
            // .... Otherwise, see if we can generate a path list from one of our children.
            else
            {
                foreach (EntityTreeRow node in current.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
                {
                    list = this.GetLocation(node.EntityRowByFK_Entity_EntityTree_ChildId, target);
                    if (list != null)
                    {
                        break;
                    }
                }
            }

            if (list != null)
            {
                list.Insert(0, current.Name);
            }

            return(list);
        }
        /// <summary>
        /// Count all of the entities beneath an entity in the hierarchy and return the total. The caller should lock the DataModel.
        /// </summary>
        /// <param name="parent">The entity to start from.</param>
        /// <returns>The total number of entities beneath 'entity' in the hierarchy.</returns>
        private int CountChildren(EntityRow parent)
        {
            int count = 0;

            foreach (EntityTreeRow row in parent.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                count += 1;
                count += this.CountChildren(row.EntityRowByFK_Entity_EntityTree_ChildId);
            }

            return(count);
        }
Exemple #8
0
        /// <summary>
        /// Determines if a given blotter is visible on the current document.
        /// </summary>
        /// <param name="parentRow">The current object in the recursive search.</param>
        /// <param name="blotterId">The blotter id to be found.</param>
        /// <returns>true if the blotter is part of the tree structure.</returns>
        private static void GetDescendants(List <Guid> descendants, EntityRow parentRow)
        {
            // Don't attempt to search if there is no starting point.
            if (parentRow != null)
            {
                descendants.Add(parentRow.EntityId);

                // Recursively search each of the children of the current node.
                foreach (EntityTreeRow entityTreeRow in parentRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
                {
                    GetDescendants(descendants, entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId);
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Retrieve a list of GuardianObjects that depend on this one. That is, objects that must be deleted if this one is.
        /// </summary>
        /// <param name="list">The list to add dependent objects to.</param>
        /// <returns>A list of dependent objects.</returns>
        private List <GuardianObject> GetDependents(List <GuardianObject> list)
        {
            EntityRow entityRow = DataModel.Entity.EntityKey.Find(this.EntityId);

            list.Add(this);

            // We're basically building a heap out of this branch of the tree so we can run through it LIFO order and maintain the integrity of the
            // entity tree.
            foreach (EntityTreeRow entityTreeRow in entityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                Entity child = Entity.New(entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId);

                (child as Blotter).GetDependents(list);
            }

            return(list);
        }
        private Guid FindUserFolder()
        {
            EntityRow userEntityRow = DataModel.Entity.EntityKey.Find(UserContext.Instance.UserId);

            EntityTreeRow[] children = userEntityRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId();

            foreach (EntityTreeRow entityTreeRow in children)
            {
                EntityRow folderEntityRow = entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId;

                if (folderEntityRow.TypeRow.ExternalId0.Equals("SYSTEM FOLDER"))
                {
                    return(folderEntityRow.EntityId);
                }
            }

            throw new ArgumentException("Current user has no system folder");
        }
        private static void CreateAccessControlItem(XElement elementTransaction, UserRow userRow, EntityRow childRow)
        {
            //    <method name="CreateWorkingOrderEx" client="DataModelClient">
            XElement elementAccessControlItem = new XElement(
                "method",
                new XAttribute("name", "CreateAccessControlEx"),
                new XAttribute("client", "DataModelClient"));

            elementTransaction.Add(elementAccessControlItem);

            //    <parameter name="accessRights" value="FullControl" />
            elementAccessControlItem.Add(
                new XElement("parameter",
                             new XAttribute("name", "accessRights"),
                             new XAttribute("value", "FullControl")));

            //      <parameter name="configurationId" value="Default" />
            elementAccessControlItem.Add(
                new XElement("parameter",
                             new XAttribute("name", "configurationId"),
                             new XAttribute("value", "Default")));

            //    <parameter name="entityKey" value="ATLAS BANK" />
            elementAccessControlItem.Add(
                new XElement("parameter",
                             new XAttribute("name", "entityKey"),
                             new XAttribute("value", childRow.ExternalId0)));

            //    <parameter name="userKey" value="ADMINISTRATOR" />
            elementAccessControlItem.Add(
                new XElement("parameter",
                             new XAttribute("name", "userKey"),
                             new XAttribute("value", userRow.EntityRow.ExternalId0)));

            foreach (EntityTreeRow childRelationRow in childRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
            {
                CreateAccessControlItem(elementTransaction, userRow, childRelationRow.EntityRowByFK_Entity_EntityTree_ChildId);
            }
        }
Exemple #12
0
        /// <summary>
        /// Determines if a given blotter is visible on the current document.
        /// </summary>
        /// <param name="parentRow">The current object in the recursive search.</param>
        /// <param name="blotterId">The blotter id to be found.</param>
        /// <returns>true if the blotter is part of the tree structure.</returns>
        public static bool IsDescendant(EntityRow parentRow, EntityRow childRow)
        {
            // Don't attempt to search if there is no starting point.
            if (parentRow != null)
            {
                // If the parent is the same as the child, then the original records are related.
                if (parentRow == childRow)
                {
                    return(true);
                }

                // Recursively search each of the children of the current node.
                foreach (EntityTreeRow entityTreeRow in parentRow.GetEntityTreeRowsByFK_Entity_EntityTree_ParentId())
                {
                    if (IsDescendant(entityTreeRow.EntityRowByFK_Entity_EntityTree_ChildId, childRow))
                    {
                        return(true);
                    }
                }
            }

            // At this point, there were no children found on this tree that matched the blotter id.
            return(false);
        }