Example #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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
Example #3
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);
                    }
                }
            }
        }
        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);
                    }
                }
            }
        }
        private void FixCollisions(System.Management.Automation.PSCmdlet cmdlet, MappingToolDatabaseDataContext mapDatabaseContext, List<CollisionInfo> collisions)
        {
            List<QueryMapRelationship> relationshipsToReconnect = new List<QueryMapRelationship>();

            foreach (CollisionInfo collision in collisions)
            {
                cmdlet.WriteWarning("Fixing collision.");
                IEnumerable<QueryMapRelationship> relationships = Consumer.GetRelationships(collision.CollisionPoint);

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

                    foreach (QueryMapNode node in nodes)
                    {
                        var rootMapIds = from qNode in mapDatabaseContext.Nodes
                                         where qNode.NodeUid == node.NodeUid
                                         select qNode.RootMapUid;

                        Guid? rootMapId = rootMapIds.FirstOrDefault();

                        if (rootMapId != null && rootMapId == collision.CollidingRootMap.NodeUid)
                        {
                            relationshipsToReconnect.Add(relationship);
                        }
                    }
                }

                DateTime currentTimestamp = DateTime.Now;

                Node copiedNode = new Node();
                copiedNode.NodeUid = Guid.NewGuid();
                copiedNode.DomainUid = collision.CollisionPoint.DomainUid;
                copiedNode.RootMapUid = collision.CollidingRootMap.NodeUid;
                copiedNode.NodeTypeUid = collision.CollisionPoint.NodeTypeUid;
                copiedNode.NodeOriginalId = collision.CollisionPoint.NodeOriginalId;
                copiedNode.Created = currentTimestamp;
                copiedNode.Modified = currentTimestamp;

                mapDatabaseContext.Nodes.InsertOnSubmit(copiedNode);
                mapDatabaseContext.SubmitChanges();

                var originalMetadata = from qMetadata in Consumer.Metadata
                                       where qMetadata.NodeUid == collision.CollisionPoint.NodeUid
                                       select qMetadata;

                foreach (var originalMetadatum in originalMetadata)
                {
                    Metadata copiedMetadata = new Metadata();
                    copiedMetadata.MetadataId = Guid.NewGuid();
                    copiedMetadata.RootMapUid = collision.CollidingRootMap.NodeUid;
                    copiedMetadata.DomainUid = copiedNode.DomainUid;
                    copiedMetadata.MetadataTypeUid = originalMetadatum.MetadataTypeUid;
                    copiedMetadata.NodeUid = copiedNode.NodeUid;
                    copiedMetadata.RelationshipUid = originalMetadatum.RelationshipUid;
                    copiedMetadata.DescriptorTypeUid = originalMetadatum.DescriptorTypeUid;
                    copiedMetadata.MetadataName = originalMetadatum.MetadataName;
                    copiedMetadata.MetadataValue = originalMetadatum.MetadataValue;
                    copiedMetadata.Created = currentTimestamp;
                    copiedMetadata.Modified = currentTimestamp;

                    mapDatabaseContext.Metadatas.InsertOnSubmit(copiedMetadata);
                }

                mapDatabaseContext.SubmitChanges();

                foreach (QueryMapRelationship relationshipToReconnect in relationshipsToReconnect)
                {
                    var descriptors = from qDescriptor in mapDatabaseContext.Descriptors
                                      where qDescriptor.NodeUid == collision.CollisionPoint.NodeUid && qDescriptor.RelationshipUid == relationshipToReconnect.RelationshipUid
                                      select qDescriptor;

                    if (descriptors != null && descriptors.Count() > 0)
                    {
                        foreach (Descriptor descriptor in descriptors)
                        {
                            descriptor.NodeUid = copiedNode.NodeUid;
                        }
                    }

                    mapDatabaseContext.SubmitChanges();
                }
            }
        }
        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            EmbeddedSqlScript createGetGlymaDbVersionScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateGetGlymaDbVersion.sql");

            using (SqlConnection mapDbConnection = new SqlConnection(MapDatabaseConnectionString))
            {
                mapDbConnection.Open();

                try
                {
                    EmbeddedSqlScript addNewColumnsScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.MapDbAddNewColumns.sql");
                    addNewColumnsScript.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript addNewColumnContraints = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.MapDbAddNewColumnConstraints.sql");
                    addNewColumnContraints.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript modifyQueryMapSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.ModifyQueryMapSP.sql");
                    modifyQueryMapSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createQueryMapSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateQueryMapSP.sql");
                    createQueryMapSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createNodesListTableType = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateNodesListTableType.sql");
                    createNodesListTableType.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createQueryNodesSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateQueryNodesSP.sql");
                    createQueryNodesSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    createGetGlymaDbVersionScript.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                mapDbConnection.Close();
            }

            using (SqlConnection transactionDbConnection = new SqlConnection(TransactionDatabaseConnectionString))
            {
                transactionDbConnection.Open();

                try
                {
                    EmbeddedSqlScript addNewColumnsScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.TransactionDbModifyColumns.sql");
                    addNewColumnsScript.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                }

                try
                {
                    createGetGlymaDbVersionScript.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                }

                transactionDbConnection.Close();
            }

            QueryMapResultConsumer domainNodesConsumer = new QueryMapResultConsumer();

            using (MappingToolDatabaseDataContext mapDatabaseContext = new MappingToolDatabaseDataContext(MapDatabaseConnectionString))
            {
                mapDatabaseContext.CommandTimeout = 600;
                var domainNodes = from node in mapDatabaseContext.Nodes
                                  where node.NodeTypeUid.HasValue && node.NodeTypeUid.Value == DomainNodeType
                                  select node;

                if (domainNodes != null && domainNodes.Count() > 0)
                {
                    foreach (var domainNode in domainNodes)
                    {
                        var domainMaps = mapDatabaseContext.QueryMapMultiDepth(domainNode.DomainUid, domainNode.NodeUid, 1, true);

                        domainNodesConsumer.Consume(domainMaps);
                    }
                }

                var rootMaps = from qNode in domainNodesConsumer.Nodes.Values
                               select qNode.NodeUid;

                DateTime startTime = new DateTime(2014, 04, 01, 0, 0, 0);

                foreach (var map in domainNodesConsumer.Nodes.Values)
                {
                    if (map.NodeTypeUid.HasValue && map.NodeTypeUid != DomainNodeType)
                    {
                        QueryMapResultConsumer mapNodesConsumer = new QueryMapResultConsumer();
                        DbIntegrityUtilities integrityUtilities = new DbIntegrityUtilities(mapNodesConsumer);

                        var mapNodes = mapDatabaseContext.QueryMapMultiDepth(map.DomainUid, map.NodeUid, -1, false);

                        callingCmdlet.WriteVerbose("Processing nodes");
                        mapNodesConsumer.Consume(mapNodes);
                        integrityUtilities.DetectAndFixMapCollisions(callingCmdlet, mapDatabaseContext, rootMaps, false, false);
                        callingCmdlet.WriteVerbose("Finished processing nodes");

                        callingCmdlet.WriteVerbose("Processing nodes and related metadata");
                        foreach (var node in mapNodesConsumer.Nodes.Values)
                        {
                            var dbNodes = from qNode in mapDatabaseContext.Nodes
                                          where qNode.NodeUid == node.NodeUid
                                          select qNode;

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

                                dbNode.Created = startTime;
                                dbNode.Modified = startTime;
                                dbNode.RootMapUid = map.NodeUid;

                                foreach (var dbMetadata in dbNode.Metadatas)
                                {
                                    dbMetadata.Created = startTime;
                                    dbMetadata.Modified = startTime;

                                    if (dbMetadata.DomainUid == null)
                                    {
                                        dbMetadata.DomainUid = map.DomainUid;
                                    }

                                    if (dbMetadata.RootMapUid == null)
                                    {
                                        dbMetadata.RootMapUid = map.NodeUid;
                                    }
                                }

                                mapDatabaseContext.SubmitChanges();
                            }

                            callingCmdlet.WriteVerbose("Finished node " + node.NodeUid);
                        }
                        callingCmdlet.WriteVerbose("Finished processing nodes");

                        callingCmdlet.WriteVerbose("Processing relationships and related metadata");
                        foreach (var relationship in mapNodesConsumer.Relationships.Values)
                        {
                            var dbRelationships = from qRelationship in mapDatabaseContext.Relationships
                                                  where qRelationship.RelationshipUid == relationship.RelationshipUid
                                                  select qRelationship;

                            if (dbRelationships != null && dbRelationships.Count() > 0)
                            {
                                var dbRelationship = dbRelationships.First();

                                dbRelationship.Created = startTime;
                                dbRelationship.Modified = startTime;
                                dbRelationship.RootMapUid = map.NodeUid;

                                foreach (var dbMetadata in dbRelationship.Metadatas)
                                {
                                    dbMetadata.Created = startTime;
                                    dbMetadata.Modified = startTime;

                                    if (dbMetadata.DomainUid == null)
                                    {
                                        dbMetadata.DomainUid = map.DomainUid;
                                    }

                                    if (dbMetadata.RootMapUid == null)
                                    {
                                        dbMetadata.RootMapUid = map.NodeUid;
                                    }
                                }

                                mapDatabaseContext.SubmitChanges();
                            }

                            callingCmdlet.WriteVerbose("Finished relationship " + relationship.RelationshipUid);
                        }
                        callingCmdlet.WriteVerbose("Finished processing relationships");
                    }
                }
            }
        }
Example #7
0
        private void FixCollisions(System.Management.Automation.PSCmdlet cmdlet, MappingToolDatabaseDataContext mapDatabaseContext, List <CollisionInfo> collisions)
        {
            List <QueryMapRelationship> relationshipsToReconnect = new List <QueryMapRelationship>();

            foreach (CollisionInfo collision in collisions)
            {
                cmdlet.WriteWarning("Fixing collision.");
                IEnumerable <QueryMapRelationship> relationships = Consumer.GetRelationships(collision.CollisionPoint);

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

                    foreach (QueryMapNode node in nodes)
                    {
                        var rootMapIds = from qNode in mapDatabaseContext.Nodes
                                         where qNode.NodeUid == node.NodeUid
                                         select qNode.RootMapUid;

                        Guid?rootMapId = rootMapIds.FirstOrDefault();

                        if (rootMapId != null && rootMapId == collision.CollidingRootMap.NodeUid)
                        {
                            relationshipsToReconnect.Add(relationship);
                        }
                    }
                }

                DateTime currentTimestamp = DateTime.Now;

                Node copiedNode = new Node();
                copiedNode.NodeUid        = Guid.NewGuid();
                copiedNode.DomainUid      = collision.CollisionPoint.DomainUid;
                copiedNode.RootMapUid     = collision.CollidingRootMap.NodeUid;
                copiedNode.NodeTypeUid    = collision.CollisionPoint.NodeTypeUid;
                copiedNode.NodeOriginalId = collision.CollisionPoint.NodeOriginalId;
                copiedNode.Created        = currentTimestamp;
                copiedNode.Modified       = currentTimestamp;

                mapDatabaseContext.Nodes.InsertOnSubmit(copiedNode);
                mapDatabaseContext.SubmitChanges();

                var originalMetadata = from qMetadata in Consumer.Metadata
                                       where qMetadata.NodeUid == collision.CollisionPoint.NodeUid
                                       select qMetadata;

                foreach (var originalMetadatum in originalMetadata)
                {
                    Metadata copiedMetadata = new Metadata();
                    copiedMetadata.MetadataId        = Guid.NewGuid();
                    copiedMetadata.RootMapUid        = collision.CollidingRootMap.NodeUid;
                    copiedMetadata.DomainUid         = copiedNode.DomainUid;
                    copiedMetadata.MetadataTypeUid   = originalMetadatum.MetadataTypeUid;
                    copiedMetadata.NodeUid           = copiedNode.NodeUid;
                    copiedMetadata.RelationshipUid   = originalMetadatum.RelationshipUid;
                    copiedMetadata.DescriptorTypeUid = originalMetadatum.DescriptorTypeUid;
                    copiedMetadata.MetadataName      = originalMetadatum.MetadataName;
                    copiedMetadata.MetadataValue     = originalMetadatum.MetadataValue;
                    copiedMetadata.Created           = currentTimestamp;
                    copiedMetadata.Modified          = currentTimestamp;

                    mapDatabaseContext.Metadatas.InsertOnSubmit(copiedMetadata);
                }

                mapDatabaseContext.SubmitChanges();

                foreach (QueryMapRelationship relationshipToReconnect in relationshipsToReconnect)
                {
                    var descriptors = from qDescriptor in mapDatabaseContext.Descriptors
                                      where qDescriptor.NodeUid == collision.CollisionPoint.NodeUid && qDescriptor.RelationshipUid == relationshipToReconnect.RelationshipUid
                                      select qDescriptor;

                    if (descriptors != null && descriptors.Count() > 0)
                    {
                        foreach (Descriptor descriptor in descriptors)
                        {
                            descriptor.NodeUid = copiedNode.NodeUid;
                        }
                    }

                    mapDatabaseContext.SubmitChanges();
                }
            }
        }
        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            EmbeddedSqlScript createGetGlymaDbVersionScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateGetGlymaDbVersion.sql");

            using (SqlConnection mapDbConnection = new SqlConnection(MapDatabaseConnectionString))
            {
                mapDbConnection.Open();

                try
                {
                    EmbeddedSqlScript addNewColumnsScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.MapDbAddNewColumns.sql");
                    addNewColumnsScript.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript addNewColumnContraints = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.MapDbAddNewColumnConstraints.sql");
                    addNewColumnContraints.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript modifyQueryMapSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.ModifyQueryMapSP.sql");
                    modifyQueryMapSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createQueryMapSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateQueryMapSP.sql");
                    createQueryMapSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createNodesListTableType = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateNodesListTableType.sql");
                    createNodesListTableType.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    EmbeddedSqlScript createQueryNodesSP = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.CreateQueryNodesSP.sql");
                    createQueryNodesSP.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                try
                {
                    createGetGlymaDbVersionScript.ExecuteNonQuery(mapDbConnection);
                }
                catch
                {
                }

                mapDbConnection.Close();
            }

            using (SqlConnection transactionDbConnection = new SqlConnection(TransactionDatabaseConnectionString))
            {
                transactionDbConnection.Open();

                try
                {
                    EmbeddedSqlScript addNewColumnsScript = new EmbeddedSqlScript("Glyma.Powershell.Update.v1_5_0_r1.TransactionDbModifyColumns.sql");
                    addNewColumnsScript.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                }

                try
                {
                    createGetGlymaDbVersionScript.ExecuteNonQuery(transactionDbConnection);
                }
                catch
                {
                }

                transactionDbConnection.Close();
            }

            QueryMapResultConsumer domainNodesConsumer = new QueryMapResultConsumer();

            using (MappingToolDatabaseDataContext mapDatabaseContext = new MappingToolDatabaseDataContext(MapDatabaseConnectionString))
            {
                mapDatabaseContext.CommandTimeout = 600;
                var domainNodes = from node in mapDatabaseContext.Nodes
                                  where node.NodeTypeUid.HasValue && node.NodeTypeUid.Value == DomainNodeType
                                  select node;

                if (domainNodes != null && domainNodes.Count() > 0)
                {
                    foreach (var domainNode in domainNodes)
                    {
                        var domainMaps = mapDatabaseContext.QueryMapMultiDepth(domainNode.DomainUid, domainNode.NodeUid, 1, true);

                        domainNodesConsumer.Consume(domainMaps);
                    }
                }

                var rootMaps = from qNode in domainNodesConsumer.Nodes.Values
                               select qNode.NodeUid;

                DateTime startTime = new DateTime(2014, 04, 01, 0, 0, 0);

                foreach (var map in domainNodesConsumer.Nodes.Values)
                {
                    if (map.NodeTypeUid.HasValue && map.NodeTypeUid != DomainNodeType)
                    {
                        QueryMapResultConsumer mapNodesConsumer   = new QueryMapResultConsumer();
                        DbIntegrityUtilities   integrityUtilities = new DbIntegrityUtilities(mapNodesConsumer);

                        var mapNodes = mapDatabaseContext.QueryMapMultiDepth(map.DomainUid, map.NodeUid, -1, false);

                        callingCmdlet.WriteVerbose("Processing nodes");
                        mapNodesConsumer.Consume(mapNodes);
                        integrityUtilities.DetectAndFixMapCollisions(callingCmdlet, mapDatabaseContext, rootMaps, false, false);
                        callingCmdlet.WriteVerbose("Finished processing nodes");

                        callingCmdlet.WriteVerbose("Processing nodes and related metadata");
                        foreach (var node in mapNodesConsumer.Nodes.Values)
                        {
                            var dbNodes = from qNode in mapDatabaseContext.Nodes
                                          where qNode.NodeUid == node.NodeUid
                                          select qNode;

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

                                dbNode.Created    = startTime;
                                dbNode.Modified   = startTime;
                                dbNode.RootMapUid = map.NodeUid;

                                foreach (var dbMetadata in dbNode.Metadatas)
                                {
                                    dbMetadata.Created  = startTime;
                                    dbMetadata.Modified = startTime;

                                    if (dbMetadata.DomainUid == null)
                                    {
                                        dbMetadata.DomainUid = map.DomainUid;
                                    }

                                    if (dbMetadata.RootMapUid == null)
                                    {
                                        dbMetadata.RootMapUid = map.NodeUid;
                                    }
                                }

                                mapDatabaseContext.SubmitChanges();
                            }

                            callingCmdlet.WriteVerbose("Finished node " + node.NodeUid);
                        }
                        callingCmdlet.WriteVerbose("Finished processing nodes");

                        callingCmdlet.WriteVerbose("Processing relationships and related metadata");
                        foreach (var relationship in mapNodesConsumer.Relationships.Values)
                        {
                            var dbRelationships = from qRelationship in mapDatabaseContext.Relationships
                                                  where qRelationship.RelationshipUid == relationship.RelationshipUid
                                                  select qRelationship;

                            if (dbRelationships != null && dbRelationships.Count() > 0)
                            {
                                var dbRelationship = dbRelationships.First();

                                dbRelationship.Created    = startTime;
                                dbRelationship.Modified   = startTime;
                                dbRelationship.RootMapUid = map.NodeUid;

                                foreach (var dbMetadata in dbRelationship.Metadatas)
                                {
                                    dbMetadata.Created  = startTime;
                                    dbMetadata.Modified = startTime;

                                    if (dbMetadata.DomainUid == null)
                                    {
                                        dbMetadata.DomainUid = map.DomainUid;
                                    }

                                    if (dbMetadata.RootMapUid == null)
                                    {
                                        dbMetadata.RootMapUid = map.NodeUid;
                                    }
                                }

                                mapDatabaseContext.SubmitChanges();
                            }

                            callingCmdlet.WriteVerbose("Finished relationship " + relationship.RelationshipUid);
                        }
                        callingCmdlet.WriteVerbose("Finished processing relationships");
                    }
                }
            }
        }