示例#1
0
        public void DetectAndFixMapCollisions(System.Management.Automation.PSCmdlet cmdlet, MappingToolDatabaseDataContext mapDatabaseContext, IEnumerable <Guid> rootMapIds, bool fillRootMapId, bool fixCollisions)
        {
            foreach (Guid rootMapId in rootMapIds)
            {
                if (Consumer.Nodes.ContainsKey(rootMapId))
                {
                    QueryMapNode rootMap = Consumer.Nodes[rootMapId];

                    var dbNodes = from qNode in mapDatabaseContext.Nodes
                                  where qNode.NodeUid == rootMap.NodeUid
                                  select qNode;

                    HashSet <Guid>       convertedNodes = new HashSet <Guid>();
                    List <CollisionInfo> collisions     = new List <CollisionInfo>();

                    if (dbNodes != null && dbNodes.Count() > 0)
                    {
                        var dbNode = dbNodes.First();

                        if (fillRootMapId)
                        {
                            dbNode.RootMapUid = rootMap.NodeUid;
                            mapDatabaseContext.SubmitChanges();
                        }

                        convertedNodes.Add(dbNode.NodeUid);
                    }

                    IEnumerable <QueryMapRelationship> relationships = Consumer.GetRelationships(rootMap, MapContainerRelationship);

                    foreach (QueryMapRelationship relationship in relationships)
                    {
                        IEnumerable <QueryMapNode> nodes = Consumer.GetNodes(relationship, rootMap);

                        foreach (QueryMapNode node in nodes)
                        {
                            if (!convertedNodes.Contains(node.NodeUid))
                            {
                                RecurseNodes(cmdlet, mapDatabaseContext, rootMap, node, convertedNodes, collisions, fillRootMapId);
                            }
                        }
                    }

                    if (fixCollisions)
                    {
                        FixCollisions(cmdlet, mapDatabaseContext, collisions);
                    }
                }
            }
        }
        private void RecurseNodes(System.Management.Automation.PSCmdlet cmdlet, MappingToolDatabaseDataContext mapDatabaseContext, QueryMapNode rootMap, QueryMapNode node, HashSet<Guid> convertedNodes, List<CollisionInfo> collisions, bool fillRootMapId)
        {
            var dbNodes = from qNode in mapDatabaseContext.Nodes
                          where qNode.NodeUid == node.NodeUid
                          select qNode;

            if (dbNodes != null && dbNodes.Count() > 0)
            {
                var dbNode = dbNodes.First();

                convertedNodes.Add(dbNode.NodeUid);

                if (dbNode.RootMapUid != null && dbNode.RootMapUid != rootMap.NodeUid)
                {
                    CollisionInfo collisionInfo = new CollisionInfo();
                    collisionInfo.CollisionPoint = node;
                    collisionInfo.CurrentRootMap = dbNode.RootMapUid.Value;
                    collisionInfo.CollidingRootMap = rootMap;

                    collisions.Add(collisionInfo);
                    cmdlet.WriteWarning("Collision detected.");
                }
                else if (dbNode.RootMapUid == null && fillRootMapId)
                {
                    dbNode.RootMapUid = rootMap.NodeUid;
                    mapDatabaseContext.SubmitChanges();
                }
            }

            IEnumerable<QueryMapRelationship> relationships = Consumer.GetRelationships(node, MapContainerRelationship);

            foreach (QueryMapRelationship relationship in relationships)
            {
                IEnumerable<QueryMapNode> children = Consumer.GetNodes(relationship, node);

                foreach (QueryMapNode childNode in children)
                {
                    if (!convertedNodes.Contains(childNode.NodeUid))
                    {
                        RecurseNodes(cmdlet, mapDatabaseContext, rootMap, childNode, convertedNodes, collisions, fillRootMapId);
                    }
                }
            }
        }
        public IEnumerable <QueryMapRelationship> GetRelationships(QueryMapNode node, params Guid[] relationshipTypes)
        {
            if (relationshipTypes.Length <= 0)
            {
                foreach (QueryMapDescriptor descriptor in Descriptors)
                {
                    if (descriptor.NodeUid == node.NodeUid)
                    {
                        if (descriptor.RelationshipUid.HasValue)
                        {
                            if (Relationships.ContainsKey(descriptor.RelationshipUid.Value))
                            {
                                yield return(Relationships[descriptor.RelationshipUid.Value]);
                            }
                        }
                    }
                }
            }
            else
            {
                HashSet <Guid> relationshipTypesHashSet = new HashSet <Guid>(relationshipTypes);

                foreach (QueryMapDescriptor descriptor in Descriptors)
                {
                    if (descriptor.NodeUid == node.NodeUid)
                    {
                        if (descriptor.RelationshipUid.HasValue)
                        {
                            QueryMapRelationship relationship = Relationships[descriptor.RelationshipUid.Value];

                            if (relationship.RelationshipTypeUid.HasValue && relationshipTypesHashSet.Contains(relationship.RelationshipTypeUid.Value))
                            {
                                yield return(relationship);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
 public JsonBreadcrumb(QueryMapNode node)
 {
     uniqueId = node.NodeUid;
     name = node.FindSingleMetadata("Name").MetadataValue.Replace('"', '\'');
 }
示例#5
0
 public JsonBreadcrumb(QueryMapNode node)
 {
     uniqueId = node.NodeUid;
     name     = node.FindSingleMetadata("Name").MetadataValue.Replace('"', '\'');
 }
示例#6
0
        public JsonNode(QueryMapNode node)
        {
            RootMapId = node.RootMapUid.Value;
            UniqueId = node.NodeUid;
            Name = node.FindSingleMetadata("Name").MetadataValue.Replace('"', '\'');

            QueryMapMetadata xPositionMetadata = node.FindSingleMetadataDefaultView("XPosition");

            if (xPositionMetadata != null && !string.IsNullOrEmpty(xPositionMetadata.MetadataValue))
            {
                double xPosition;

                if (double.TryParse(xPositionMetadata.MetadataValue, out xPosition))
                {
                    int truncatedXPosition = (int)xPosition;

                    XPosition = truncatedXPosition;
                }
                else
                {
                    IsProperlyStructured = false;
                    return;
                }
            }

            QueryMapMetadata yPositionMetadata = node.FindSingleMetadataDefaultView("YPosition");

            if (yPositionMetadata != null && !string.IsNullOrEmpty(yPositionMetadata.MetadataValue))
            {
                double yPosition;

                if (double.TryParse(yPositionMetadata.MetadataValue, out yPosition))
                {
                    int truncatedYPosition = (int)yPosition;

                    YPosition = truncatedYPosition;
                }
                else
                {
                    IsProperlyStructured = false;
                    return;
                }
            }

            NodeType = node.NodeType;

            foreach (QueryMapMetadata metadata in node.FindAllMetadata())
            {
                if (metadata.MetadataName != "Name" && metadata.MetadataName != "XPosition" && metadata.MetadataName != "YPosition")
                {
                    if (metadata.MetadataName.Contains("."))
                    {
                        string[] referenceNames = metadata.MetadataName.Split(new char[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
                        Hashtable nestedReferenceObject = this;

                        for (int i = 0; i < (referenceNames.Length - 1); i++)
                        {
                            string referenceName = referenceNames[i];

                            if (nestedReferenceObject.ContainsKey(referenceName))
                            {
                                if (nestedReferenceObject[referenceName] is Hashtable)
                                {
                                    nestedReferenceObject = (Hashtable)nestedReferenceObject[referenceName];
                                }
                                else
                                {
                                    Hashtable nextNestedReferenceObject = new Hashtable();

                                    nextNestedReferenceObject["this"] = nestedReferenceObject[referenceName];
                                    nestedReferenceObject[referenceName] = nextNestedReferenceObject;
                                    nestedReferenceObject = nextNestedReferenceObject;
                                }
                            }
                            else
                            {
                                Hashtable nextNestedReferenceObject = new Hashtable();

                                nestedReferenceObject[referenceName] = nextNestedReferenceObject;
                                nestedReferenceObject = nextNestedReferenceObject;
                            }
                        }

                        string lastReferenceName = referenceNames[referenceNames.Length - 1];
                        nestedReferenceObject[lastReferenceName] = metadata.MetadataValue;
                    }
                    else
                    {
                        this[metadata.MetadataName] = metadata.MetadataValue;
                    }
                }
            }

            IsProperlyStructured = true;
        }
        public void Consume(IMultipleResults resultSets)
        {
            IEnumerable <QueryMapMultiDepthResult> resultSet = resultSets.GetResult <QueryMapMultiDepthResult>();

            while (resultSet != null)
            {
                foreach (var queryMapResult in resultSet)
                {
                    if (queryMapResult.Level != null)
                    {
                        if (queryMapResult.NodeUid.HasValue && queryMapResult.NodeUid != Guid.Empty)
                        {
                            /// The QueryMap procedure returns ALL nodes by following relationships to max depth meaning some nodes are repeated in some of the levels multiple nodes may connect to them.
                            if (!Nodes.ContainsKey(queryMapResult.NodeUid.Value))
                            {
                                /// TODO: Need to consider copying the NodeOriginalId.
                                QueryMapNode node = new QueryMapNode();
                                node.NodeUid     = queryMapResult.NodeUid.Value;
                                node.DomainUid   = queryMapResult.DomainUid.Value;
                                node.NodeTypeUid = queryMapResult.NodeTypeUid;

                                Nodes[queryMapResult.NodeUid.Value] = node;
                            }
                        }
                    }
                    else if (queryMapResult.MetadataId != null)
                    {
                        if (queryMapResult.MetadataId.HasValue && queryMapResult.MetadataId != Guid.Empty)
                        {
                            QueryMapMetadata metadatum = new QueryMapMetadata();
                            metadatum.MetadataId        = queryMapResult.MetadataId.Value;
                            metadatum.NodeUid           = queryMapResult.NodeUid;
                            metadatum.RelationshipUid   = queryMapResult.RelationshipUid;
                            metadatum.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;
                            metadatum.MetadataTypeUid   = queryMapResult.MetadataTypeUid;
                            metadatum.MetadataName      = queryMapResult.MetadataName;
                            metadatum.MetadataValue     = queryMapResult.MetadataValue;

                            Metadata.Add(metadatum);
                        }
                    }
                    else if (queryMapResult.DescriptorUid != null)
                    {
                        if (queryMapResult.DescriptorUid.HasValue && queryMapResult.DescriptorUid != Guid.Empty)
                        {
                            QueryMapDescriptor descriptor = new QueryMapDescriptor();
                            descriptor.DescriptorUid     = queryMapResult.DescriptorUid.Value;
                            descriptor.NodeUid           = queryMapResult.NodeUid;
                            descriptor.RelationshipUid   = queryMapResult.RelationshipUid;
                            descriptor.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;

                            Descriptors.Add(descriptor);
                        }
                    }
                    else
                    {
                        if (queryMapResult.RelationshipUid.HasValue && queryMapResult.RelationshipUid != Guid.Empty)
                        {
                            /// TODO: Need to consider copying the RelationshipOriginalId.
                            QueryMapRelationship relationship = new QueryMapRelationship();
                            relationship.RelationshipUid     = queryMapResult.RelationshipUid.Value;
                            relationship.DomainUid           = queryMapResult.DomainUid.Value;
                            relationship.RelationshipTypeUid = queryMapResult.RelationshipTypeUid;

                            Relationships[relationship.RelationshipUid] = relationship;
                        }
                    }
                }

                resultSet = resultSets.GetResult <QueryMapMultiDepthResult>();
            }
        }
 public IEnumerable <QueryMapNode> GetNodes(QueryMapRelationship relationship, QueryMapNode excludingNode)
 {
     foreach (QueryMapDescriptor descriptor in Descriptors)
     {
         if (descriptor.RelationshipUid == relationship.RelationshipUid && descriptor.NodeUid != excludingNode.NodeUid)
         {
             if (descriptor.NodeUid.HasValue)
             {
                 if (Nodes.ContainsKey(descriptor.NodeUid.Value))
                 {
                     yield return(Nodes[descriptor.NodeUid.Value]);
                 }
             }
         }
     }
 }
示例#9
0
        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            Dictionary <Guid, QueryMapNode> originalNodes         = new Dictionary <Guid, QueryMapNode>();
            List <QueryMapRelationship>     originalRelationships = new List <QueryMapRelationship>();
            List <QueryMapDescriptor>       originalDescriptors   = new List <QueryMapDescriptor>();
            List <QueryMapMetadata>         originalMetadata      = new List <QueryMapMetadata>();

            if (DestinationDomain == null || !DestinationDomain.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid destination domain has been provided.");

                return;
            }

            if (SourceMap == null || !SourceMap.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid source map has been provided.");

                return;
            }

            Model.IDatabaseInfo sourceMapDbInfo = SourceMap.Domain;

            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(sourceMapDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                var queryMapResultSets = dataContext.QueryMapMultiDepth(SourceMap.Domain.DomainId, SourceMap.NodeId, -1, false);

                var queryMapResultSet = queryMapResultSets.GetResult <QueryMapMultiDepthResult>();

                while (queryMapResultSet != null)
                {
                    foreach (var queryMapResult in queryMapResultSet)
                    {
                        if (queryMapResult.Level != null)
                        {
                            if (queryMapResult.NodeUid.HasValue && queryMapResult.NodeUid != Guid.Empty)
                            {
                                /// Make sure that we aren't copying across a domain node.
                                if (queryMapResult.NodeTypeUid.HasValue && queryMapResult.NodeTypeUid != new Guid("263754C2-2F31-4D21-B9C4-6509E00A5E94"))
                                {
                                    /// The QueryMap procedure returns ALL nodes by following relationships to max depth meaning some nodes are repeated in some of the levels multiple nodes may connect to them.
                                    if (!originalNodes.ContainsKey(queryMapResult.NodeUid.Value))
                                    {
                                        /// TODO: Need to consider copying the NodeOriginalId.
                                        QueryMapNode node = new QueryMapNode();
                                        node.NodeUid     = queryMapResult.NodeUid.Value;
                                        node.DomainUid   = DestinationDomain.DomainId;
                                        node.NodeTypeUid = queryMapResult.NodeTypeUid;
                                        node.RootMapUid  = queryMapResult.RootMapUid;
                                        node.Created     = queryMapResult.Created;
                                        node.Modified    = queryMapResult.Modified;
                                        node.CreatedBy   = queryMapResult.CreatedBy;
                                        node.ModifiedBy  = queryMapResult.ModifiedBy;

                                        originalNodes[queryMapResult.NodeUid.Value] = node;
                                    }
                                }
                            }
                        }
                        else if (queryMapResult.MetadataId != null)
                        {
                            if (queryMapResult.MetadataId.HasValue && queryMapResult.MetadataId != Guid.Empty)
                            {
                                QueryMapMetadata metadatum = new QueryMapMetadata();
                                metadatum.MetadataId        = queryMapResult.MetadataId.Value;
                                metadatum.NodeUid           = queryMapResult.NodeUid;
                                metadatum.RelationshipUid   = queryMapResult.RelationshipUid;
                                metadatum.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;
                                metadatum.MetadataTypeUid   = queryMapResult.MetadataTypeUid;
                                metadatum.MetadataName      = queryMapResult.MetadataName;
                                metadatum.MetadataValue     = queryMapResult.MetadataValue;
                                metadatum.DomainUid         = queryMapResult.DomainUid;
                                metadatum.RootMapUid        = queryMapResult.RootMapUid;
                                metadatum.Created           = queryMapResult.Created;
                                metadatum.Modified          = queryMapResult.Modified;
                                metadatum.CreatedBy         = queryMapResult.CreatedBy;
                                metadatum.ModifiedBy        = queryMapResult.ModifiedBy;

                                originalMetadata.Add(metadatum);
                            }
                        }
                        else if (queryMapResult.DescriptorUid != null)
                        {
                            if (queryMapResult.DescriptorUid.HasValue && queryMapResult.DescriptorUid != Guid.Empty)
                            {
                                QueryMapDescriptor descriptor = new QueryMapDescriptor();
                                descriptor.DescriptorUid     = queryMapResult.DescriptorUid.Value;
                                descriptor.NodeUid           = queryMapResult.NodeUid;
                                descriptor.RelationshipUid   = queryMapResult.RelationshipUid;
                                descriptor.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;

                                originalDescriptors.Add(descriptor);
                            }
                        }
                        else
                        {
                            if (queryMapResult.RelationshipUid.HasValue && queryMapResult.RelationshipUid != Guid.Empty)
                            {
                                /// TODO: Need to consider copying the RelationshipOriginalId.
                                QueryMapRelationship relationship = new QueryMapRelationship();
                                relationship.RelationshipUid     = queryMapResult.RelationshipUid.Value;
                                relationship.DomainUid           = DestinationDomain.DomainId;
                                relationship.RelationshipTypeUid = queryMapResult.RelationshipTypeUid;
                                relationship.RootMapUid          = queryMapResult.RootMapUid;
                                relationship.Created             = queryMapResult.Created;
                                relationship.Modified            = queryMapResult.Modified;
                                relationship.CreatedBy           = queryMapResult.CreatedBy;
                                relationship.ModifiedBy          = queryMapResult.ModifiedBy;

                                originalRelationships.Add(relationship);
                            }
                        }
                    }

                    queryMapResultSet = queryMapResultSets.GetResult <QueryMapMultiDepthResult>();
                }
            }

            int totalNodes         = originalNodes.Count;
            int totalRelationships = originalRelationships.Count;
            int totalMetadata      = originalMetadata.Count;
            int totalDescriptors   = originalDescriptors.Count;

            Dictionary <Guid, Guid> newNodeIds         = new Dictionary <Guid, Guid>();
            Dictionary <Guid, Guid> newRelationshipIds = new Dictionary <Guid, Guid>();

            Model.IDatabaseInfo destinationDomainDbInfo = DestinationDomain;

            /// The following performs the creation of nodes in the new database
            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(destinationDomainDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                int count = 0;

                callingCmdlet.WriteVerbose("Processing of nodes starting.");

                DateTime currentTime = DateTime.Now;

                WindowsIdentity currentUserIdentity = WindowsIdentity.GetCurrent();
                string          currentUserName     = "******";

                if (currentUserIdentity != null)
                {
                    currentUserName = currentUserIdentity.Name;
                }

                Guid newRootMapId = Guid.NewGuid();

                /// If it is the root map node, we want to assign it the pre-determined ID as we've been using this as the RootMapUid for everything;
                QueryMapNode sourceMapNode = originalNodes[SourceMap.NodeId];

                Node newRootMapNode = new Node();
                newRootMapNode.NodeUid     = newRootMapId;
                newRootMapNode.DomainUid   = DestinationDomain.DomainId;
                newRootMapNode.NodeTypeUid = sourceMapNode.NodeTypeUid;
                newRootMapNode.RootMapUid  = newRootMapId;
                newRootMapNode.Created     = sourceMapNode.Created;
                newRootMapNode.Modified    = currentTime;
                newRootMapNode.CreatedBy   = sourceMapNode.CreatedBy;
                newRootMapNode.ModifiedBy  = currentUserName;

                newNodeIds[sourceMapNode.NodeUid] = newRootMapNode.NodeUid;

                dataContext.Nodes.InsertOnSubmit(newRootMapNode);

                /// Iterate through all nodes in memory and change their node IDs and root map IDs so that they won't clash with the map from where they were copied.
                foreach (QueryMapNode memoryNode in originalNodes.Values)
                {
                    if (memoryNode.NodeUid == SourceMap.NodeId)
                    {
                        continue;
                    }

                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalNodes + " Nodes Completed");
                    }

                    Node node = new Node();
                    node.NodeUid     = Guid.NewGuid();
                    node.DomainUid   = DestinationDomain.DomainId;
                    node.NodeTypeUid = memoryNode.NodeTypeUid;
                    node.RootMapUid  = newRootMapId;
                    node.Created     = memoryNode.Created;
                    node.Modified    = currentTime;
                    node.CreatedBy   = memoryNode.CreatedBy;
                    node.ModifiedBy  = currentUserName;

                    newNodeIds[memoryNode.NodeUid] = node.NodeUid;

                    dataContext.Nodes.InsertOnSubmit(node);
                }

                if (!newNodeIds.ContainsKey(SourceMap.NodeId))
                {
                    callingCmdlet.WriteWarning("Unexpected scenario. The source map NodeId can't be found in the list of copied nodes.");

                    return;
                }

                callingCmdlet.WriteVerbose("Committing nodes starting.");

                /// Commit node additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing nodes completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of relationships starting.");

                foreach (QueryMapRelationship memoryRelationship in originalRelationships)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalRelationships + " Relationships Completed");
                    }

                    Relationship relationship = new Relationship();
                    relationship.RelationshipUid     = Guid.NewGuid();
                    relationship.DomainUid           = DestinationDomain.DomainId;
                    relationship.RelationshipTypeUid = memoryRelationship.RelationshipTypeUid;
                    relationship.RootMapUid          = newRootMapId;
                    relationship.Created             = memoryRelationship.Created;
                    relationship.Modified            = currentTime;
                    relationship.CreatedBy           = memoryRelationship.CreatedBy;
                    relationship.ModifiedBy          = currentUserName;

                    newRelationshipIds[memoryRelationship.RelationshipUid] = relationship.RelationshipUid;

                    dataContext.Relationships.InsertOnSubmit(relationship);
                }

                callingCmdlet.WriteVerbose("Committing relationships starting.");

                /// Commit relationship additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing relationships completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of descriptors starting.");

                foreach (QueryMapDescriptor memoryDescriptor in originalDescriptors)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalDescriptors + " Descriptors Completed");
                    }

                    if (newNodeIds.ContainsKey(memoryDescriptor.NodeUid.Value) && newRelationshipIds.ContainsKey(memoryDescriptor.RelationshipUid.Value))
                    {
                        Descriptor descriptor = new Descriptor();
                        descriptor.DescriptorUid     = Guid.NewGuid();
                        descriptor.NodeUid           = newNodeIds[memoryDescriptor.NodeUid.Value];
                        descriptor.RelationshipUid   = newRelationshipIds[memoryDescriptor.RelationshipUid.Value];
                        descriptor.DescriptorTypeUid = memoryDescriptor.DescriptorTypeUid;

                        dataContext.Descriptors.InsertOnSubmit(descriptor);
                    }
                }

                callingCmdlet.WriteVerbose("Committing descriptors starting.");

                /// Commit descriptor additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing descriptors completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of metadata starting.");

                foreach (QueryMapMetadata memoryMetadatum in originalMetadata)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalMetadata + " Metadata Completed");
                    }

                    if (memoryMetadatum.NodeUid == null || newNodeIds.ContainsKey(memoryMetadatum.NodeUid.Value))
                    {
                        if (memoryMetadatum.RelationshipUid == null || newRelationshipIds.ContainsKey(memoryMetadatum.RelationshipUid.Value))
                        {
                            Metadata metadatum = new Metadata();
                            metadatum.MetadataId = Guid.NewGuid();

                            if (memoryMetadatum.NodeUid != null)
                            {
                                metadatum.NodeUid = newNodeIds[memoryMetadatum.NodeUid.Value];
                            }
                            else
                            {
                                metadatum.NodeUid = null;
                            }

                            if (memoryMetadatum.RelationshipUid != null)
                            {
                                metadatum.RelationshipUid = newRelationshipIds[memoryMetadatum.RelationshipUid.Value];
                            }
                            else
                            {
                                metadatum.RelationshipUid = null;
                            }

                            metadatum.DescriptorTypeUid = memoryMetadatum.DescriptorTypeUid;
                            metadatum.MetadataTypeUid   = memoryMetadatum.MetadataTypeUid;
                            metadatum.MetadataName      = memoryMetadatum.MetadataName;
                            metadatum.MetadataValue     = memoryMetadatum.MetadataValue;
                            metadatum.DomainUid         = DestinationDomain.DomainId;
                            metadatum.RootMapUid        = newRootMapId;
                            metadatum.Created           = memoryMetadatum.Created;
                            metadatum.Modified          = currentTime;
                            metadatum.CreatedBy         = memoryMetadatum.CreatedBy;
                            metadatum.ModifiedBy        = currentUserName;

                            dataContext.Metadatas.InsertOnSubmit(metadatum);
                        }
                    }
                }

                callingCmdlet.WriteVerbose("Committing metadata starting.");

                /// Commit metadata additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing metadata completed.");

                callingCmdlet.WriteVerbose("Connecting map to domain.");

                Relationship domainNodeMapRelationship = new Relationship();
                domainNodeMapRelationship.RelationshipUid     = Guid.NewGuid();
                domainNodeMapRelationship.DomainUid           = DestinationDomain.DomainId;
                domainNodeMapRelationship.RelationshipTypeUid = new Guid("4AFF46D7-87BE-48DD-B703-A93E38EF8FFB");
                domainNodeMapRelationship.RootMapUid          = newRootMapId;
                domainNodeMapRelationship.Created             = currentTime;
                domainNodeMapRelationship.Modified            = currentTime;
                domainNodeMapRelationship.CreatedBy           = currentUserName;
                domainNodeMapRelationship.ModifiedBy          = currentUserName;

                Descriptor domainNodeMapFromDescriptor = new Descriptor();
                domainNodeMapFromDescriptor.DescriptorUid     = Guid.NewGuid();
                domainNodeMapFromDescriptor.DescriptorTypeUid = new Guid("96DA1782-058C-4F9B-BB1A-31B048F8C75A");
                domainNodeMapFromDescriptor.NodeUid           = newNodeIds[SourceMap.NodeId];
                domainNodeMapFromDescriptor.RelationshipUid   = domainNodeMapRelationship.RelationshipUid;

                Descriptor domainNodeMapToDescriptor = new Descriptor();
                domainNodeMapToDescriptor.DescriptorUid     = Guid.NewGuid();
                domainNodeMapToDescriptor.DescriptorTypeUid = new Guid("07C91D35-4DAC-431B-966B-64C924B8CDAB");
                domainNodeMapToDescriptor.NodeUid           = DestinationDomain.NodeId;
                domainNodeMapToDescriptor.RelationshipUid   = domainNodeMapRelationship.RelationshipUid;

                dataContext.Relationships.InsertOnSubmit(domainNodeMapRelationship);
                dataContext.Descriptors.InsertOnSubmit(domainNodeMapFromDescriptor);
                dataContext.Descriptors.InsertOnSubmit(domainNodeMapToDescriptor);

                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Completed connecting map to domain.");

                callingCmdlet.WriteVerbose("Copy completed.");
            }
        }
示例#10
0
        private void RecurseNodes(System.Management.Automation.PSCmdlet cmdlet, MappingToolDatabaseDataContext mapDatabaseContext, QueryMapNode rootMap, QueryMapNode node, HashSet <Guid> convertedNodes, List <CollisionInfo> collisions, bool fillRootMapId)
        {
            var dbNodes = from qNode in mapDatabaseContext.Nodes
                          where qNode.NodeUid == node.NodeUid
                          select qNode;

            if (dbNodes != null && dbNodes.Count() > 0)
            {
                var dbNode = dbNodes.First();

                convertedNodes.Add(dbNode.NodeUid);

                if (dbNode.RootMapUid != null && dbNode.RootMapUid != rootMap.NodeUid)
                {
                    CollisionInfo collisionInfo = new CollisionInfo();
                    collisionInfo.CollisionPoint   = node;
                    collisionInfo.CurrentRootMap   = dbNode.RootMapUid.Value;
                    collisionInfo.CollidingRootMap = rootMap;

                    collisions.Add(collisionInfo);
                    cmdlet.WriteWarning("Collision detected.");
                }
                else if (dbNode.RootMapUid == null && fillRootMapId)
                {
                    dbNode.RootMapUid = rootMap.NodeUid;
                    mapDatabaseContext.SubmitChanges();
                }
            }

            IEnumerable <QueryMapRelationship> relationships = Consumer.GetRelationships(node, MapContainerRelationship);

            foreach (QueryMapRelationship relationship in relationships)
            {
                IEnumerable <QueryMapNode> children = Consumer.GetNodes(relationship, node);

                foreach (QueryMapNode childNode in children)
                {
                    if (!convertedNodes.Contains(childNode.NodeUid))
                    {
                        RecurseNodes(cmdlet, mapDatabaseContext, rootMap, childNode, convertedNodes, collisions, fillRootMapId);
                    }
                }
            }
        }
示例#11
0
        public JsonNode(QueryMapNode node)
        {
            RootMapId = node.RootMapUid.Value;
            UniqueId  = node.NodeUid;
            Name      = node.FindSingleMetadata("Name").MetadataValue.Replace('"', '\'');

            QueryMapMetadata xPositionMetadata = node.FindSingleMetadataDefaultView("XPosition");

            if (xPositionMetadata != null && !string.IsNullOrEmpty(xPositionMetadata.MetadataValue))
            {
                double xPosition;

                if (double.TryParse(xPositionMetadata.MetadataValue, out xPosition))
                {
                    int truncatedXPosition = (int)xPosition;

                    XPosition = truncatedXPosition;
                }
                else
                {
                    IsProperlyStructured = false;
                    return;
                }
            }

            QueryMapMetadata yPositionMetadata = node.FindSingleMetadataDefaultView("YPosition");

            if (yPositionMetadata != null && !string.IsNullOrEmpty(yPositionMetadata.MetadataValue))
            {
                double yPosition;

                if (double.TryParse(yPositionMetadata.MetadataValue, out yPosition))
                {
                    int truncatedYPosition = (int)yPosition;

                    YPosition = truncatedYPosition;
                }
                else
                {
                    IsProperlyStructured = false;
                    return;
                }
            }

            NodeType = node.NodeType;

            foreach (QueryMapMetadata metadata in node.FindAllMetadata())
            {
                if (metadata.MetadataName != "Name" && metadata.MetadataName != "XPosition" && metadata.MetadataName != "YPosition")
                {
                    if (metadata.MetadataName.Contains("."))
                    {
                        string[]  referenceNames        = metadata.MetadataName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                        Hashtable nestedReferenceObject = this;

                        for (int i = 0; i < (referenceNames.Length - 1); i++)
                        {
                            string referenceName = referenceNames[i];

                            if (nestedReferenceObject.ContainsKey(referenceName))
                            {
                                if (nestedReferenceObject[referenceName] is Hashtable)
                                {
                                    nestedReferenceObject = (Hashtable)nestedReferenceObject[referenceName];
                                }
                                else
                                {
                                    Hashtable nextNestedReferenceObject = new Hashtable();

                                    nextNestedReferenceObject["this"]    = nestedReferenceObject[referenceName];
                                    nestedReferenceObject[referenceName] = nextNestedReferenceObject;
                                    nestedReferenceObject = nextNestedReferenceObject;
                                }
                            }
                            else
                            {
                                Hashtable nextNestedReferenceObject = new Hashtable();

                                nestedReferenceObject[referenceName] = nextNestedReferenceObject;
                                nestedReferenceObject = nextNestedReferenceObject;
                            }
                        }

                        string lastReferenceName = referenceNames[referenceNames.Length - 1];
                        nestedReferenceObject[lastReferenceName] = metadata.MetadataValue;
                    }
                    else
                    {
                        this[metadata.MetadataName] = metadata.MetadataValue;
                    }
                }
            }

            IsProperlyStructured = true;
        }
        public void Consume(IMultipleResults resultSets)
        {
            IEnumerable<QueryMapMultiDepthResult> resultSet = resultSets.GetResult<QueryMapMultiDepthResult>();

            while (resultSet != null)
            {
                foreach (var queryMapResult in resultSet)
                {
                    if (queryMapResult.Level != null)
                    {
                        if (queryMapResult.NodeUid.HasValue && queryMapResult.NodeUid != Guid.Empty)
                        {
                            /// The QueryMap procedure returns ALL nodes by following relationships to max depth meaning some nodes are repeated in some of the levels multiple nodes may connect to them.
                            if (!Nodes.ContainsKey(queryMapResult.NodeUid.Value))
                            {
                                /// TODO: Need to consider copying the NodeOriginalId.
                                QueryMapNode node = new QueryMapNode();
                                node.NodeUid = queryMapResult.NodeUid.Value;
                                node.DomainUid = queryMapResult.DomainUid.Value;
                                node.NodeTypeUid = queryMapResult.NodeTypeUid;

                                Nodes[queryMapResult.NodeUid.Value] = node;
                            }
                        }
                    }
                    else if (queryMapResult.MetadataId != null)
                    {
                        if (queryMapResult.MetadataId.HasValue && queryMapResult.MetadataId != Guid.Empty)
                        {
                            QueryMapMetadata metadatum = new QueryMapMetadata();
                            metadatum.MetadataId = queryMapResult.MetadataId.Value;
                            metadatum.NodeUid = queryMapResult.NodeUid;
                            metadatum.RelationshipUid = queryMapResult.RelationshipUid;
                            metadatum.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;
                            metadatum.MetadataTypeUid = queryMapResult.MetadataTypeUid;
                            metadatum.MetadataName = queryMapResult.MetadataName;
                            metadatum.MetadataValue = queryMapResult.MetadataValue;

                            Metadata.Add(metadatum);
                        }
                    }
                    else if (queryMapResult.DescriptorUid != null)
                    {
                        if (queryMapResult.DescriptorUid.HasValue && queryMapResult.DescriptorUid != Guid.Empty)
                        {
                            QueryMapDescriptor descriptor = new QueryMapDescriptor();
                            descriptor.DescriptorUid = queryMapResult.DescriptorUid.Value;
                            descriptor.NodeUid = queryMapResult.NodeUid;
                            descriptor.RelationshipUid = queryMapResult.RelationshipUid;
                            descriptor.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;

                            Descriptors.Add(descriptor);
                        }
                    }
                    else
                    {
                        if (queryMapResult.RelationshipUid.HasValue && queryMapResult.RelationshipUid != Guid.Empty)
                        {
                            /// TODO: Need to consider copying the RelationshipOriginalId.
                            QueryMapRelationship relationship = new QueryMapRelationship();
                            relationship.RelationshipUid = queryMapResult.RelationshipUid.Value;
                            relationship.DomainUid = queryMapResult.DomainUid.Value;
                            relationship.RelationshipTypeUid = queryMapResult.RelationshipTypeUid;

                            Relationships[relationship.RelationshipUid] = relationship;
                        }
                    }
                }

                resultSet = resultSets.GetResult<QueryMapMultiDepthResult>();
            }
        }
 public IEnumerable<QueryMapNode> GetNodes(QueryMapRelationship relationship, QueryMapNode excludingNode)
 {
     foreach (QueryMapDescriptor descriptor in Descriptors)
     {
         if (descriptor.RelationshipUid == relationship.RelationshipUid && descriptor.NodeUid != excludingNode.NodeUid)
         {
             if (descriptor.NodeUid.HasValue)
             {
                 if (Nodes.ContainsKey(descriptor.NodeUid.Value))
                 {
                     yield return Nodes[descriptor.NodeUid.Value];
                 }
             }
         }
     }
 }
        public IEnumerable<QueryMapRelationship> GetRelationships(QueryMapNode node, params Guid[] relationshipTypes)
        {
            if (relationshipTypes.Length <= 0)
            {
                foreach (QueryMapDescriptor descriptor in Descriptors)
                {
                    if (descriptor.NodeUid == node.NodeUid)
                    {
                        if (descriptor.RelationshipUid.HasValue)
                        {
                            if (Relationships.ContainsKey(descriptor.RelationshipUid.Value))
                            {
                                yield return Relationships[descriptor.RelationshipUid.Value];
                            }
                        }
                    }
                }
            }
            else
            {
                HashSet<Guid> relationshipTypesHashSet = new HashSet<Guid>(relationshipTypes);

                foreach (QueryMapDescriptor descriptor in Descriptors)
                {
                    if (descriptor.NodeUid == node.NodeUid)
                    {
                        if (descriptor.RelationshipUid.HasValue)
                        {
                            QueryMapRelationship relationship = Relationships[descriptor.RelationshipUid.Value];

                            if (relationship.RelationshipTypeUid.HasValue && relationshipTypesHashSet.Contains(relationship.RelationshipTypeUid.Value))
                            {
                                yield return relationship;
                            }
                        }
                    }
                }
            }
        }
示例#15
0
        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            Dictionary<Guid, QueryMapNode> originalNodes = new Dictionary<Guid, QueryMapNode>();
            List<QueryMapRelationship> originalRelationships = new List<QueryMapRelationship>();
            List<QueryMapDescriptor> originalDescriptors = new List<QueryMapDescriptor>();
            List<QueryMapMetadata> originalMetadata = new List<QueryMapMetadata>();

            if (DestinationDomain == null || !DestinationDomain.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid destination domain has been provided.");

                return;
            }

            if (SourceMap == null || !SourceMap.CheckIsValid())
            {
                callingCmdlet.WriteWarning("An invalid source map has been provided.");

                return;
            }

            Model.IDatabaseInfo sourceMapDbInfo = SourceMap.Domain;

            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(sourceMapDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                var queryMapResultSets = dataContext.QueryMapMultiDepth(SourceMap.Domain.DomainId, SourceMap.NodeId, -1, false);

                var queryMapResultSet = queryMapResultSets.GetResult<QueryMapMultiDepthResult>();

                while (queryMapResultSet != null)
                {
                    foreach (var queryMapResult in queryMapResultSet)
                    {
                        if (queryMapResult.Level != null)
                        {
                            if (queryMapResult.NodeUid.HasValue && queryMapResult.NodeUid != Guid.Empty)
                            {
                                /// Make sure that we aren't copying across a domain node.
                                if (queryMapResult.NodeTypeUid.HasValue && queryMapResult.NodeTypeUid != new Guid("263754C2-2F31-4D21-B9C4-6509E00A5E94"))
                                {
                                    /// The QueryMap procedure returns ALL nodes by following relationships to max depth meaning some nodes are repeated in some of the levels multiple nodes may connect to them.
                                    if (!originalNodes.ContainsKey(queryMapResult.NodeUid.Value))
                                    {
                                        /// TODO: Need to consider copying the NodeOriginalId.
                                        QueryMapNode node = new QueryMapNode();
                                        node.NodeUid = queryMapResult.NodeUid.Value;
                                        node.DomainUid = DestinationDomain.DomainId;
                                        node.NodeTypeUid = queryMapResult.NodeTypeUid;
                                        node.RootMapUid = queryMapResult.RootMapUid;
                                        node.Created = queryMapResult.Created;
                                        node.Modified = queryMapResult.Modified;
                                        node.CreatedBy = queryMapResult.CreatedBy;
                                        node.ModifiedBy = queryMapResult.ModifiedBy;

                                        originalNodes[queryMapResult.NodeUid.Value] = node;
                                    }
                                }
                            }
                        }
                        else if (queryMapResult.MetadataId != null)
                        {
                            if (queryMapResult.MetadataId.HasValue && queryMapResult.MetadataId != Guid.Empty)
                            {
                                QueryMapMetadata metadatum = new QueryMapMetadata();
                                metadatum.MetadataId = queryMapResult.MetadataId.Value;
                                metadatum.NodeUid = queryMapResult.NodeUid;
                                metadatum.RelationshipUid = queryMapResult.RelationshipUid;
                                metadatum.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;
                                metadatum.MetadataTypeUid = queryMapResult.MetadataTypeUid;
                                metadatum.MetadataName = queryMapResult.MetadataName;
                                metadatum.MetadataValue = queryMapResult.MetadataValue;
                                metadatum.DomainUid = queryMapResult.DomainUid;
                                metadatum.RootMapUid = queryMapResult.RootMapUid;
                                metadatum.Created = queryMapResult.Created;
                                metadatum.Modified = queryMapResult.Modified;
                                metadatum.CreatedBy = queryMapResult.CreatedBy;
                                metadatum.ModifiedBy = queryMapResult.ModifiedBy;

                                originalMetadata.Add(metadatum);
                            }
                        }
                        else if (queryMapResult.DescriptorUid != null)
                        {
                            if (queryMapResult.DescriptorUid.HasValue && queryMapResult.DescriptorUid != Guid.Empty)
                            {
                                QueryMapDescriptor descriptor = new QueryMapDescriptor();
                                descriptor.DescriptorUid = queryMapResult.DescriptorUid.Value;
                                descriptor.NodeUid = queryMapResult.NodeUid;
                                descriptor.RelationshipUid = queryMapResult.RelationshipUid;
                                descriptor.DescriptorTypeUid = queryMapResult.DescriptorTypeUid;

                                originalDescriptors.Add(descriptor);
                            }
                        }
                        else
                        {
                            if (queryMapResult.RelationshipUid.HasValue && queryMapResult.RelationshipUid != Guid.Empty)
                            {
                                /// TODO: Need to consider copying the RelationshipOriginalId.
                                QueryMapRelationship relationship = new QueryMapRelationship();
                                relationship.RelationshipUid = queryMapResult.RelationshipUid.Value;
                                relationship.DomainUid = DestinationDomain.DomainId;
                                relationship.RelationshipTypeUid = queryMapResult.RelationshipTypeUid;
                                relationship.RootMapUid = queryMapResult.RootMapUid;
                                relationship.Created = queryMapResult.Created;
                                relationship.Modified = queryMapResult.Modified;
                                relationship.CreatedBy = queryMapResult.CreatedBy;
                                relationship.ModifiedBy = queryMapResult.ModifiedBy;

                                originalRelationships.Add(relationship);
                            }
                        }
                    }

                    queryMapResultSet = queryMapResultSets.GetResult<QueryMapMultiDepthResult>();
                }
            }

            int totalNodes = originalNodes.Count;
            int totalRelationships = originalRelationships.Count;
            int totalMetadata = originalMetadata.Count;
            int totalDescriptors = originalDescriptors.Count;

            Dictionary<Guid, Guid> newNodeIds = new Dictionary<Guid, Guid>();
            Dictionary<Guid, Guid> newRelationshipIds = new Dictionary<Guid, Guid>();

            Model.IDatabaseInfo destinationDomainDbInfo = DestinationDomain;

            /// The following performs the creation of nodes in the new database
            using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(destinationDomainDbInfo.ConnectionString))
            {
                dataContext.CommandTimeout = 180;
                int count = 0;

                callingCmdlet.WriteVerbose("Processing of nodes starting.");

                DateTime currentTime = DateTime.Now;

                WindowsIdentity currentUserIdentity = WindowsIdentity.GetCurrent();
                string currentUserName = "******";

                if (currentUserIdentity != null)
                {
                    currentUserName = currentUserIdentity.Name;
                }

                Guid newRootMapId = Guid.NewGuid();

                /// If it is the root map node, we want to assign it the pre-determined ID as we've been using this as the RootMapUid for everything;
                QueryMapNode sourceMapNode = originalNodes[SourceMap.NodeId];

                Node newRootMapNode = new Node();
                newRootMapNode.NodeUid = newRootMapId;
                newRootMapNode.DomainUid = DestinationDomain.DomainId;
                newRootMapNode.NodeTypeUid = sourceMapNode.NodeTypeUid;
                newRootMapNode.RootMapUid = newRootMapId;
                newRootMapNode.Created = sourceMapNode.Created;
                newRootMapNode.Modified = currentTime;
                newRootMapNode.CreatedBy = sourceMapNode.CreatedBy;
                newRootMapNode.ModifiedBy = currentUserName;

                newNodeIds[sourceMapNode.NodeUid] = newRootMapNode.NodeUid;

                dataContext.Nodes.InsertOnSubmit(newRootMapNode);

                /// Iterate through all nodes in memory and change their node IDs and root map IDs so that they won't clash with the map from where they were copied.
                foreach (QueryMapNode memoryNode in originalNodes.Values)
                {
                    if (memoryNode.NodeUid == SourceMap.NodeId)
                    {
                        continue;
                    }

                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalNodes + " Nodes Completed");
                    }

                    Node node = new Node();
                    node.NodeUid = Guid.NewGuid();
                    node.DomainUid = DestinationDomain.DomainId;
                    node.NodeTypeUid = memoryNode.NodeTypeUid;
                    node.RootMapUid = newRootMapId;
                    node.Created = memoryNode.Created;
                    node.Modified = currentTime;
                    node.CreatedBy = memoryNode.CreatedBy;
                    node.ModifiedBy = currentUserName;

                    newNodeIds[memoryNode.NodeUid] = node.NodeUid;

                    dataContext.Nodes.InsertOnSubmit(node);
                }

                if (!newNodeIds.ContainsKey(SourceMap.NodeId))
                {
                    callingCmdlet.WriteWarning("Unexpected scenario. The source map NodeId can't be found in the list of copied nodes.");

                    return;
                }

                callingCmdlet.WriteVerbose("Committing nodes starting.");

                /// Commit node additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing nodes completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of relationships starting.");

                foreach (QueryMapRelationship memoryRelationship in originalRelationships)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalRelationships + " Relationships Completed");
                    }

                    Relationship relationship = new Relationship();
                    relationship.RelationshipUid = Guid.NewGuid();
                    relationship.DomainUid = DestinationDomain.DomainId;
                    relationship.RelationshipTypeUid = memoryRelationship.RelationshipTypeUid;
                    relationship.RootMapUid = newRootMapId;
                    relationship.Created = memoryRelationship.Created;
                    relationship.Modified = currentTime;
                    relationship.CreatedBy = memoryRelationship.CreatedBy;
                    relationship.ModifiedBy = currentUserName;

                    newRelationshipIds[memoryRelationship.RelationshipUid] = relationship.RelationshipUid;

                    dataContext.Relationships.InsertOnSubmit(relationship);
                }

                callingCmdlet.WriteVerbose("Committing relationships starting.");

                /// Commit relationship additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing relationships completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of descriptors starting.");

                foreach (QueryMapDescriptor memoryDescriptor in originalDescriptors)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalDescriptors + " Descriptors Completed");
                    }

                    if (newNodeIds.ContainsKey(memoryDescriptor.NodeUid.Value) && newRelationshipIds.ContainsKey(memoryDescriptor.RelationshipUid.Value))
                    {
                        Descriptor descriptor = new Descriptor();
                        descriptor.DescriptorUid = Guid.NewGuid();
                        descriptor.NodeUid = newNodeIds[memoryDescriptor.NodeUid.Value];
                        descriptor.RelationshipUid = newRelationshipIds[memoryDescriptor.RelationshipUid.Value];
                        descriptor.DescriptorTypeUid = memoryDescriptor.DescriptorTypeUid;

                        dataContext.Descriptors.InsertOnSubmit(descriptor);
                    }
                }

                callingCmdlet.WriteVerbose("Committing descriptors starting.");

                /// Commit descriptor additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing descriptors completed.");

                count = 0;

                callingCmdlet.WriteVerbose("Processing of metadata starting.");

                foreach (QueryMapMetadata memoryMetadatum in originalMetadata)
                {
                    count++;

                    if (count % 10 == 0)
                    {
                        callingCmdlet.WriteVerbose(count + " / " + totalMetadata + " Metadata Completed");
                    }

                    if (memoryMetadatum.NodeUid == null || newNodeIds.ContainsKey(memoryMetadatum.NodeUid.Value))
                    {
                        if (memoryMetadatum.RelationshipUid == null || newRelationshipIds.ContainsKey(memoryMetadatum.RelationshipUid.Value))
                        {
                            Metadata metadatum = new Metadata();
                            metadatum.MetadataId = Guid.NewGuid();

                            if (memoryMetadatum.NodeUid != null)
                            {
                                metadatum.NodeUid = newNodeIds[memoryMetadatum.NodeUid.Value];
                            }
                            else
                            {
                                metadatum.NodeUid = null;
                            }

                            if (memoryMetadatum.RelationshipUid != null)
                            {
                                metadatum.RelationshipUid = newRelationshipIds[memoryMetadatum.RelationshipUid.Value];
                            }
                            else
                            {
                                metadatum.RelationshipUid = null;
                            }

                            metadatum.DescriptorTypeUid = memoryMetadatum.DescriptorTypeUid;
                            metadatum.MetadataTypeUid = memoryMetadatum.MetadataTypeUid;
                            metadatum.MetadataName = memoryMetadatum.MetadataName;
                            metadatum.MetadataValue = memoryMetadatum.MetadataValue;
                            metadatum.DomainUid = DestinationDomain.DomainId;
                            metadatum.RootMapUid = newRootMapId;
                            metadatum.Created = memoryMetadatum.Created;
                            metadatum.Modified = currentTime;
                            metadatum.CreatedBy = memoryMetadatum.CreatedBy;
                            metadatum.ModifiedBy = currentUserName;

                            dataContext.Metadatas.InsertOnSubmit(metadatum);
                        }
                    }
                }

                callingCmdlet.WriteVerbose("Committing metadata starting.");

                /// Commit metadata additions.
                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Committing metadata completed.");

                callingCmdlet.WriteVerbose("Connecting map to domain.");

                Relationship domainNodeMapRelationship = new Relationship();
                domainNodeMapRelationship.RelationshipUid = Guid.NewGuid();
                domainNodeMapRelationship.DomainUid = DestinationDomain.DomainId;
                domainNodeMapRelationship.RelationshipTypeUid = new Guid("4AFF46D7-87BE-48DD-B703-A93E38EF8FFB");
                domainNodeMapRelationship.RootMapUid = newRootMapId;
                domainNodeMapRelationship.Created = currentTime;
                domainNodeMapRelationship.Modified = currentTime;
                domainNodeMapRelationship.CreatedBy = currentUserName;
                domainNodeMapRelationship.ModifiedBy = currentUserName;

                Descriptor domainNodeMapFromDescriptor = new Descriptor();
                domainNodeMapFromDescriptor.DescriptorUid = Guid.NewGuid();
                domainNodeMapFromDescriptor.DescriptorTypeUid = new Guid("96DA1782-058C-4F9B-BB1A-31B048F8C75A");
                domainNodeMapFromDescriptor.NodeUid = newNodeIds[SourceMap.NodeId];
                domainNodeMapFromDescriptor.RelationshipUid = domainNodeMapRelationship.RelationshipUid;

                Descriptor domainNodeMapToDescriptor = new Descriptor();
                domainNodeMapToDescriptor.DescriptorUid = Guid.NewGuid();
                domainNodeMapToDescriptor.DescriptorTypeUid = new Guid("07C91D35-4DAC-431B-966B-64C924B8CDAB");
                domainNodeMapToDescriptor.NodeUid = DestinationDomain.NodeId;
                domainNodeMapToDescriptor.RelationshipUid = domainNodeMapRelationship.RelationshipUid;

                dataContext.Relationships.InsertOnSubmit(domainNodeMapRelationship);
                dataContext.Descriptors.InsertOnSubmit(domainNodeMapFromDescriptor);
                dataContext.Descriptors.InsertOnSubmit(domainNodeMapToDescriptor);

                dataContext.SubmitChanges();

                callingCmdlet.WriteVerbose("Completed connecting map to domain.");

                callingCmdlet.WriteVerbose("Copy completed.");
            }
        }