/// <summary>
 /// Called when a node is removed.
 /// </summary>
 /// <param name="node">The node.</param>
 private void OnNodeRemoved(EnterpriseTestMapNode node)
 {
     if (NodeRemoved != null)
     {
         NodeRemoved(this, new EnterpriseTestUIEventArgs(node));
     }
 }
        /// <summary>
        /// Gets the entity object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public EntityObject GetEntityObject(Guid id)
        {
            // Discard our old entity context and create a new one.  This seems wasteful,
            // but if we maintain the same context it will cache all the data that is ever
            // loaded from it.  This can cause huge memory growth over time, as well as
            // concurrency issues.  Creating a new context is cheap and avoids these issues.
            if (_context != null)
            {
                _context.Dispose();
            }
            _context = new EnterpriseTestContext();

            EnterpriseTestMapNode node = _databaseMap[id];

            switch (node.NodeType)
            {
            case ConfigurationObjectType.EnterpriseScenario:
                return(EnterpriseScenario.Select(_context, id));

            case ConfigurationObjectType.VirtualResource:
                return(VirtualResource.Select(_context, id));

            case ConfigurationObjectType.ResourceMetadata:
                return(VirtualResourceMetadata.Select(_context, id));

            case ConfigurationObjectType.ScenarioFolder:
            case ConfigurationObjectType.ResourceFolder:
            case ConfigurationObjectType.MetadataFolder:
                return(ConfigurationTreeFolder.Select(_context, id));

            default:
                return(null);
            }
        }
        private void HandleObjectChange(EnterpriseTestEntities entities, EntityObject entity)
        {
            // Get a node that is representative of this item
            EnterpriseTestMapNode node = EnterpriseTestMapNode.Create(entity);

            if (node != null)
            {
                switch (entity.EntityState)
                {
                case EntityState.Added:
                    _databaseMap.Add(node);
                    OnNodeAdded(node);
                    break;

                case EntityState.Modified:
                    _databaseMap.Update(node);
                    OnNodeModified(node);
                    break;

                case EntityState.Deleted:
                    _databaseMap.Remove(node);
                    OnNodeRemoved(node);
                    break;
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EnterpriseTestUIEventArgs"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        internal EnterpriseTestUIEventArgs(EnterpriseTestMapNode node)
        {
            Id       = node.Id;
            ParentId = node.FolderId ?? node.ParentId;
            Name     = node.Name;

            // Determine the correct image key
            switch (node.NodeType)
            {
            case ConfigurationObjectType.ScenarioFolder:
            case ConfigurationObjectType.ResourceFolder:
            case ConfigurationObjectType.MetadataFolder:
                ImageKey = "Folder";
                break;

            case ConfigurationObjectType.EnterpriseScenario:
                ImageKey = "Scenario";
                break;

            case ConfigurationObjectType.VirtualResource:
                ImageKey = node.ResourceType;
                break;

            case ConfigurationObjectType.ResourceMetadata:
                ImageKey = node.MetadataType;
                break;
            }

            // If the node is disabled, modify the key
            if (!node.Enabled)
            {
                ImageKey += "Disabled";
            }
        }
        /// <summary>
        /// Creates a new folder under the specified parent id.
        /// </summary>
        /// <param name="parentId">The parent id.</param>
        /// <returns>The ID of the created folder.</returns>
        public Guid CreateFolder(Guid?parentId)
        {
            // Create a default folder, which is valid if the parent is null
            var folder = new ConfigurationTreeFolder(SequentialGuid.NewGuid(), "New Folder", "ScenarioFolder", parentId);

            // Determine the real folder type and parent
            if (parentId != null)
            {
                EnterpriseTestMapNode node = _databaseMap[(Guid)parentId];
                switch (node.NodeType)
                {
                case ConfigurationObjectType.EnterpriseScenario:
                case ConfigurationObjectType.ResourceFolder:
                    folder.FolderType = "ResourceFolder";
                    break;

                case ConfigurationObjectType.VirtualResource:
                case ConfigurationObjectType.MetadataFolder:
                    folder.FolderType = "MetadataFolder";
                    break;
                }
            }

            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                context.ConfigurationTreeFolders.AddObject(folder);
                HandleObjectChange(context, folder);
                context.SaveChanges();
            }

            return(folder.ConfigurationTreeFolderId);
        }
        /// <summary>
        /// Manages the copying of any of the nodes used. Tries to link the UI structure to the database
        /// structure of the trees.
        /// </summary>
        /// <param name="SourceNodes">List representation of the tree.  In couplet format -
        ///   [0] is parent, [1] is the 'node'. Using List because any node can be parent to multiple
        ///   other nodes and reversing it to use a dictionary negates the performance benefit of dictioanries</param>
        /// <param name="Ndx">Index into the tree representation list.</param>
        /// <param name="Mappings">Dictionary. Key is the original node ID, and the Value is the new/copy
        ///   node Id</param>
        /// <returns>Guid / Node ID of the node that was created during the copy.</returns>
        public Guid CopyNode(List <Guid?> SourceNodes, int Ndx, Dictionary <Guid?, Guid?> Mappings, ConfigurationObjectType rootMovedType)
        {
            if (SourceNodes.Count <= (Ndx + 1))
            {
                throw new Exception("Bad Source List / Index in CopyNode ::" + Ndx.ToString());
            }
            if (Mappings.ContainsKey(SourceNodes[Ndx + 1]))
            {
                throw new Exception("Doubly Linked Node in UI Tree: " + SourceNodes[Ndx + 1].ToString());
            }
            EnterpriseTestMapNode src = _databaseMap[(Guid)SourceNodes[Ndx + 1]];

            switch (src.NodeType)
            {
            case ConfigurationObjectType.ScenarioFolder:
            case ConfigurationObjectType.ResourceFolder:
            case ConfigurationObjectType.MetadataFolder:
                return(CopyFolder((Guid)SourceNodes[Ndx + 1], Mappings[(Guid?)SourceNodes[Ndx]]));

            case ConfigurationObjectType.EnterpriseScenario:
                return(CopyScenario((Guid)SourceNodes[Ndx + 1], Mappings[(Guid?)SourceNodes[Ndx]]));

            case ConfigurationObjectType.VirtualResource:
                return(CopyResource((Guid)SourceNodes[Ndx + 1], (Guid)SourceNodes[Ndx], (Guid)Mappings[(Guid?)SourceNodes[Ndx]], Mappings));

            case ConfigurationObjectType.ResourceMetadata:
                bool partOfResource = (rootMovedType != ConfigurationObjectType.ResourceMetadata && rootMovedType != ConfigurationObjectType.MetadataFolder);
                return(CopyActivity((Guid)SourceNodes[Ndx + 1], (Guid)SourceNodes[Ndx], (Guid)Mappings[(Guid?)SourceNodes[Ndx]], Mappings, partOfResource));

            default:
                throw new Exception("Unknown Node type in CopyNode?");
            }
        }
 /// <summary>
 /// Called when a node is modified.
 /// </summary>
 /// <param name="node">The node.</param>
 private void OnNodeModified(EnterpriseTestMapNode node)
 {
     if (NodeModified != null && DisplayNode(node))
     {
         NodeModified(this, new EnterpriseTestUIEventArgs(node));
     }
 }
Esempio n. 8
0
        private static IEnumerable <EnterpriseTestMapNode> Sort(IEnumerable <EnterpriseTestMapNode> nodes)
        {
            // The scenarios, resources, and metadata require no special sorting.
            EnterpriseTestMapNode first = nodes.FirstOrDefault();

            if (first == null || !first.NodeType.IsFolder())
            {
                return(nodes);
            }

            // Otherwise, we have a folder set
            List <EnterpriseTestMapNode> remaining = new List <EnterpriseTestMapNode>(nodes);
            List <EnterpriseTestMapNode> sorted    = new List <EnterpriseTestMapNode>();

            // We need to make sure that any subfolders come after their parent folder.
            // Since this will be a relatively small set, we'll use a simple (though inefficient) approach.
            while (remaining.Count > 0)
            {
                // Create a list of the node IDs that have not been processed yet.
                IEnumerable <Guid> remainingIds = remaining.Select(n => n.Id);

                // Find all nodes whose parents are not in the "unprocessed" list.
                // Their parents must either be processed already, or some other type (scenario, etc.)
                // so these nodes can be moved to the sorted list.
                var readyNodes = remaining.Where(n => n.ParentId == null || !remainingIds.Contains((Guid)n.ParentId));
                foreach (EnterpriseTestMapNode ready in readyNodes.ToList())
                {
                    remaining.Remove(ready);
                    sorted.Add(ready);
                }
            }

            return(sorted);
        }
        /// <summary>
        /// Checks if the id is the guid for any type of a folder
        /// </summary>
        /// <param name="id">The id to check</param>
        /// <returns>True if this node is any type of a folder</returns>
        public bool IsFolder(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType == ConfigurationObjectType.ScenarioFolder ||
                   node.NodeType == ConfigurationObjectType.ResourceFolder ||
                   node.NodeType == ConfigurationObjectType.MetadataFolder);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationObjectTag"/> class.
 /// </summary>
 /// <param name="node">The node.</param>
 internal ConfigurationObjectTag(EnterpriseTestMapNode node)
 {
     Id         = node.Id;
     ObjectType = node.NodeType;
     if (!string.IsNullOrEmpty(node.ResourceType))
     {
         ResourceType = EnumUtil.Parse <VirtualResourceType>(node.ResourceType);
         MetadataType = node.MetadataType;
     }
 }
        /// <summary>
        /// Checks two RadTreeNodes to see if they are of different 'types'.
        /// </summary>
        /// <param name="id1">First node</param>
        /// <param name="id2">Second node</param>
        /// <returns>true of the nodes are the same type, else false</returns>
        public bool NodeCCPGroupsMatch(Guid id1, Guid id2)
        {
            if ((id1 == Guid.Empty) || (id2 == Guid.Empty))
            {
                return(false);
            }
            EnterpriseTestMapNode node1 = _databaseMap[id1];
            EnterpriseTestMapNode node2 = _databaseMap[id2];

            return(node1.NodeType == node2.NodeType);
        }
 private static bool DisplayNode(EnterpriseTestMapNode node)
 {
     if (node.NodeType == ConfigurationObjectType.ResourceMetadata)
     {
         VirtualResourceType resourceType = EnumUtil.Parse <VirtualResourceType>(node.ResourceType);
         return(resourceType.UsesPlugins());
     }
     else
     {
         return(true);
     }
 }
        /// <summary>
        /// Gets a descriptive tag for the object with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public ConfigurationObjectTag GetObjectTag(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            if (node == null)
            {
                return(null);
            }
            else
            {
                return(new ConfigurationObjectTag(node));
            }
        }
        /// <summary>
        /// Determines whether the object with the specified id can be enabled or disabled.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Tuple <bool, string> CanEnableDisable(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            if (node.NodeType.CanEnableDisable())
            {
                return(new Tuple <bool, string>(true, node.Enabled ? "Disable" : "Enable"));
            }
            else
            {
                return(new Tuple <bool, string>(false, null));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Gets al nodes in the subtree starting at the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public IEnumerable <EnterpriseTestMapNode> GetSubtree(EnterpriseTestMapNode node)
        {
            var nodes = new List <EnterpriseTestMapNode>()
            {
                node
            };

            foreach (EnterpriseTestMapNode child in FindChildren(node))
            {
                nodes.AddRange(GetSubtree(child));
            }
            return(nodes);
        }
Esempio n. 16
0
 private Guid?FindNonFolderParentId(EnterpriseTestMapNode node)
 {
     if (!node.NodeType.IsFolder())
     {
         return(node.Id);
     }
     else if (node.ParentId == null)
     {
         return(null);
     }
     else
     {
         return(FindNonFolderParentId(this[(Guid)node.ParentId]));
     }
 }
Esempio n. 17
0
        private IEnumerable <EnterpriseTestMapNode> FindNonFolderChildren(EnterpriseTestMapNode node)
        {
            List <EnterpriseTestMapNode> childNodes = new List <EnterpriseTestMapNode>();

            foreach (EnterpriseTestMapNode child in _nodes.Where(n => n.ParentId == node.Id || n.FolderId == node.Id))
            {
                if (!child.NodeType.IsFolder())
                {
                    childNodes.Add(child);
                }
                else
                {
                    childNodes.AddRange(FindNonFolderChildren(child));
                }
            }
            return(childNodes);
        }
Esempio n. 18
0
        /// <summary>
        /// Gets all nodes that would be affected if the specified node was moved.
        /// (This will usually not include the entire subtree.)
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        public IEnumerable <Guid> GetMoveAffectedNodes(EnterpriseTestMapNode node)
        {
            var affectedNodes = new List <Guid>()
            {
                node.Id
            };

            // If the node being moved is a folder, then children of that node may be affected,
            // since the parent ID could change
            if (node.NodeType.IsFolder())
            {
                foreach (EnterpriseTestMapNode child in FindChildren(node))
                {
                    affectedNodes.AddRange(GetMoveAffectedNodes(child));
                }
            }

            return(affectedNodes);
        }
        /// <summary>
        /// Removes the object with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        public void Delete(Guid id)
        {
            // Get the map node that this id corresponds to and the subtree below it
            EnterpriseTestMapNode node = _databaseMap[id];
            IEnumerable <EnterpriseTestMapNode> subtree = _databaseMap.GetSubtree(node);

            foreach (EnterpriseTestMapNode removingNode in subtree)
            {
                OnNodeRemoving(removingNode);
            }

            // Update all the database objects that were affected
            DatabaseDelete(subtree);

            // Handle object changes
            foreach (EnterpriseTestMapNode deleted in subtree)
            {
                _databaseMap.Remove(deleted);
            }
            OnNodeRemoved(subtree.FirstOrDefault());
        }
        /// <summary>
        /// Determines whether the node with the specified ID can be dropped onto the target node with the specified ID.
        /// </summary>
        /// <param name="nodeId">The node id.</param>
        /// <param name="targetId">The target id.</param>
        /// <returns>
        ///   <c>true</c> if the drop is valid; otherwise, <c>false</c>.
        /// </returns>
        public bool CanDrop(Guid nodeId, Guid targetId)
        {
            EnterpriseTestMapNode source = _databaseMap[nodeId];
            EnterpriseTestMapNode target = _databaseMap[targetId];

            // Do a schema check first
            if (!target.NodeType.CanContain(source.NodeType))
            {
                return(false);
            }

            // Make sure we don't copy metadata to a different resource type
            if (target.NodeType == ConfigurationObjectType.VirtualResource)
            {
                return(target.ResourceType == source.ResourceType);
            }
            else
            {
                // Otherwise, we're good.
                return(true);
            }
        }
        /// <summary>
        /// Enables/disable the specified object.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="enabled">Whether the object should be enabled.</param>
        public void EnableDisable(Guid id, bool enabled)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                EnterpriseTestMapNode node = _databaseMap[id];
                switch (node.NodeType)
                {
                case ConfigurationObjectType.VirtualResource:
                    var resource = VirtualResource.Select(context, id);
                    resource.Enabled = enabled;
                    HandleObjectChange(context, resource);
                    break;

                case ConfigurationObjectType.ResourceMetadata:
                    var metadata = VirtualResourceMetadata.Select(context, id);
                    metadata.Enabled = enabled;
                    HandleObjectChange(context, metadata);
                    break;
                }
                context.SaveChanges();
            }
        }
        private void MoveHandler(EnterpriseTestContext context, IEnumerable <Guid> affected)
        {
            foreach (Guid affectedId in affected)
            {
                EnterpriseTestMapNode moved = _databaseMap[affectedId];
                switch (moved.NodeType)
                {
                case ConfigurationObjectType.EnterpriseScenario:
                    var scenario = EnterpriseScenario.Select(context, affectedId);
                    scenario.FolderId = moved.FolderId;
                    HandleObjectChange(context, scenario);
                    break;

                case ConfigurationObjectType.VirtualResource:
                    var resource = VirtualResource.Select(context, affectedId);
                    resource.EnterpriseScenarioId = (Guid)moved.ParentId;
                    resource.FolderId             = moved.FolderId;
                    HandleObjectChange(context, resource);
                    break;

                case ConfigurationObjectType.ResourceMetadata:
                    var metadata = VirtualResourceMetadata.Select(context, affectedId);
                    metadata.VirtualResourceId = (Guid)moved.ParentId;
                    metadata.FolderId          = moved.FolderId;
                    HandleObjectChange(context, metadata);
                    break;

                case ConfigurationObjectType.ScenarioFolder:
                case ConfigurationObjectType.ResourceFolder:
                case ConfigurationObjectType.MetadataFolder:
                    var folder = ConfigurationTreeFolder.Select(context, affectedId);
                    folder.ParentId = moved.ParentId;
                    HandleObjectChange(context, folder);
                    break;
                }
            }
            context.SaveChanges();
        }
        /// <summary>
        /// Moves the object with the specified id to the specified parent.
        /// </summary>
        /// <param name="nodeId">The id.</param>
        /// <param name="targetId">The target parent id.</param>
        public void Move(Guid nodeId, Guid?targetId)
        {
            // Get the map node that this id corresponds to and update it
            EnterpriseTestMapNode node = _databaseMap[nodeId];
            var affected = _databaseMap.GetMoveAffectedNodes(node);

            _databaseMap.Move(node, targetId);

            // Update all database objects that were affected
            // Use the local context if it is available - this fixes an issue where the parent id changes
            // but the cached copy in the local context does not get updated, which causes a crash when the object is committed
            if (_context != null)
            {
                MoveHandler(_context, affected);
            }
            else
            {
                using (EnterpriseTestContext context = new EnterpriseTestContext())
                {
                    MoveHandler(context, affected);
                }
            }
        }
        /// <summary>
        /// Renames the object with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        public void Rename(Guid id, string name)
        {
            using (EnterpriseTestContext context = new EnterpriseTestContext())
            {
                EnterpriseTestMapNode node = _databaseMap[id];
                switch (node.NodeType)
                {
                case ConfigurationObjectType.EnterpriseScenario:
                    var scenario = EnterpriseScenario.Select(context, id);
                    scenario.Name = name;
                    HandleObjectChange(context, scenario);
                    break;

                case ConfigurationObjectType.VirtualResource:
                    var resource = VirtualResource.Select(context, id);
                    resource.Name = name;
                    HandleObjectChange(context, resource);
                    break;

                case ConfigurationObjectType.ResourceMetadata:
                    var metadata = VirtualResourceMetadata.Select(context, id);
                    metadata.Name = name;
                    HandleObjectChange(context, metadata);
                    break;

                case ConfigurationObjectType.ScenarioFolder:
                case ConfigurationObjectType.ResourceFolder:
                case ConfigurationObjectType.MetadataFolder:
                    var folder = ConfigurationTreeFolder.Select(context, id);
                    folder.Name = name;
                    HandleObjectChange(context, folder);
                    break;
                }
                context.SaveChanges();
            }
        }
        /// <summary>
        /// Determines whether the object with the specified id can contain a folder.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>
        ///   <c>true</c> if the object with the specified id can contain a folder; otherwise, <c>false</c>.
        /// </returns>
        public bool CanContainFolder(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType != ConfigurationObjectType.ResourceMetadata);
        }
        /// <summary>
        /// Determines whether the object with the specified id can contain a scenario.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>
        ///   <c>true</c> if the object with the specified id can contain a scenario; otherwise, <c>false</c>.
        /// </returns>
        public bool CanContainScenario(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType == ConfigurationObjectType.ScenarioFolder);
        }
        /// <summary>
        /// Checks if the id is the guid for resource metadata (Activity)
        /// </summary>
        /// <param name="id">Guid</param>
        /// <returns>True if the node 'is' an activity (Resource Metadata)</returns>
        public bool IsResourceMetaData(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType == ConfigurationObjectType.ResourceMetadata);
        }
        /// <summary>
        /// Checks if the id is a Guid for a Virtual Resource
        /// </summary>
        /// <param name="id">The node id (Guid)</param>
        /// <returns>True if the node 'is' a Virtual Resource</returns>
        public bool IsResource(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType == ConfigurationObjectType.VirtualResource);
        }
        /// <summary>
        /// Checks if the id is a guid for a scenario
        /// </summary>
        /// <param name="id">The id to check</param>
        /// <returns>True if the Node 'is' a scenario</returns>
        public bool IsScenario(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType == ConfigurationObjectType.EnterpriseScenario);
        }
        public ConfigurationObjectType GetType(Guid id)
        {
            EnterpriseTestMapNode node = _databaseMap[id];

            return(node.NodeType);
        }