private Model.Map GetMapById(MappingToolDatabaseDataContext dataContext, Guid mapId) { var dbMapNodes = from qNode in dataContext.Nodes where qNode.NodeUid == mapId && qNode.DomainUid == Domain.DomainId select qNode; if (dbMapNodes == null || dbMapNodes.Count() == 0) { return(null); } var dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == mapId && qMetadata.MetadataName == "Name" select qMetadata; if (dbMapNameMetadata == null || dbMapNameMetadata.Count() == 0) { return(null); } var dbMapNode = dbMapNodes.First(); var dbMapNameDatum = dbMapNameMetadata.First(); Model.Map map = new Model.Map(); map.Domain = Domain; map.NodeId = mapId; map.Name = dbMapNameDatum.MetadataValue; return(map); }
private Model.Map GetMapById(MappingToolDatabaseDataContext dataContext, Guid mapId) { var dbMapNodes = from qNode in dataContext.Nodes where qNode.NodeUid == mapId && qNode.DomainUid == Domain.DomainId select qNode; if (dbMapNodes == null || dbMapNodes.Count() == 0) { return null; } var dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == mapId && qMetadata.MetadataName == "Name" select qMetadata; if (dbMapNameMetadata == null || dbMapNameMetadata.Count() == 0) { return null; } var dbMapNode = dbMapNodes.First(); var dbMapNameDatum = dbMapNameMetadata.First(); Model.Map map = new Model.Map(); map.Domain = Domain; map.NodeId = mapId; map.Name = dbMapNameDatum.MetadataValue; return map; }
public void ExecuteCmdletBase(PSCmdlet callingCmdlet) { using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(ConnectionString)) { dataContext.CommandTimeout = 180; if (DomainId != Guid.Empty) { /// Find domains by domain ID. /// Model.Domain domain = GetDomainById(dataContext, DomainId); callingCmdlet.WriteObject(domain); } else if (!string.IsNullOrEmpty(DomainName)) { /// Find domains by domain name. /// List <Model.Domain> domains = GetDomainsByName(dataContext, DomainName); callingCmdlet.WriteObject(domains, true); } else { /// Find all domains. /// List <Model.Domain> domains = GetAllDomains(dataContext); callingCmdlet.WriteObject(domains, true); } } }
public static ISoapTypeElement GetSoapType <SoapType>(Guid typeUid) where SoapType : ISoapTypeElement { lock (_lock) { if (_soapTypes.ContainsKey(typeUid)) { return(_soapTypes[typeUid]); } using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { if (typeof(SoapType).IsAssignableFrom(typeof(SoapNodeType))) { var nodeType = (from dbNodeType in mappingDb.NodeTypes where dbNodeType.NodeTypeUid == typeUid select dbNodeType).First(); SoapNodeType soapNodeType = new SoapNodeType(); soapNodeType.Id = nodeType.NodeTypeUid; soapNodeType.Name = nodeType.NodeTypeName; return((ISoapTypeElement)soapNodeType); } else if (typeof(SoapType).IsAssignableFrom(typeof(SoapDescriptorType))) { var nodeType = (from dbNodeType in mappingDb.DescriptorTypes where dbNodeType.DescriptorTypeUid == typeUid select dbNodeType).First(); SoapDescriptorType soapDescriptorType = new SoapDescriptorType(); soapDescriptorType.Id = nodeType.DescriptorTypeUid; soapDescriptorType.Name = nodeType.DescriptorTypeName; return((ISoapTypeElement)soapDescriptorType); } else if (typeof(SoapType).IsAssignableFrom(typeof(SoapRelationshipType))) { var nodeType = (from dbNodeType in mappingDb.RelationshipTypes where dbNodeType.RelationshipTypeUid == typeUid select dbNodeType).First(); SoapRelationshipType soapRelationshipType = new SoapRelationshipType(); soapRelationshipType.Id = nodeType.RelationshipTypeUid; soapRelationshipType.Name = nodeType.RelationshipTypeName; return((ISoapTypeElement)soapRelationshipType); } else if (typeof(SoapType).IsAssignableFrom(typeof(SoapMetadataType))) { var nodeType = (from dbNodeType in mappingDb.MetadataTypes where dbNodeType.MetadataTypeUid == typeUid select dbNodeType).First(); SoapMetadataType soapMetadataType = new SoapMetadataType(); soapMetadataType.Id = nodeType.MetadataTypeUid; soapMetadataType.Name = nodeType.MetadataTypeName; return((ISoapTypeElement)soapMetadataType); } else { throw new NotSupportedException("The requested type is not supported"); } } } }
private List<Model.Map> GetMapsByName(MappingToolDatabaseDataContext dataContext, string mapName) { var dbLocalNodeResultSets = dataContext.QueryMapMultiDepth(Domain.DomainId, Domain.NodeId, 1, true); var dbLocalNodeLevel0 = dbLocalNodeResultSets.GetResult<QueryMapMultiDepthResult>(); var dbLocalNodeLevel1 = dbLocalNodeResultSets.GetResult<QueryMapMultiDepthResult>(); List<Model.Map> matchingMaps = new List<Model.Map>(); if (dbLocalNodeLevel1 != null) { foreach (var dbLocalNode in dbLocalNodeLevel1) { if (dbLocalNode.Level.HasValue && dbLocalNode.Level.Value == 1) { IQueryable<Metadata> dbMapNameMetadata; if (mapName == "*") { dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbLocalNode.NodeUid && qMetadata.MetadataName == "Name" select qMetadata; } else { dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbLocalNode.NodeUid && qMetadata.MetadataName == "Name" && qMetadata.MetadataValue == mapName select qMetadata; } if (dbMapNameMetadata != null && dbMapNameMetadata.Count() > 0) { if (dbLocalNode.NodeUid != Guid.Empty) { var dbMapNameMetadatum = dbMapNameMetadata.First(); Model.Map map = new Model.Map(); map.Domain = Domain; map.NodeId = dbLocalNode.NodeUid.Value; map.Name = dbMapNameMetadatum.MetadataValue; matchingMaps.Add(map); } } } } } return matchingMaps; }
private List <Model.Map> GetMapsByName(MappingToolDatabaseDataContext dataContext, string mapName) { var dbLocalNodeResultSets = dataContext.QueryMapMultiDepth(Domain.DomainId, Domain.NodeId, 1, true); var dbLocalNodeLevel0 = dbLocalNodeResultSets.GetResult <QueryMapMultiDepthResult>(); var dbLocalNodeLevel1 = dbLocalNodeResultSets.GetResult <QueryMapMultiDepthResult>(); List <Model.Map> matchingMaps = new List <Model.Map>(); if (dbLocalNodeLevel1 != null) { foreach (var dbLocalNode in dbLocalNodeLevel1) { if (dbLocalNode.Level.HasValue && dbLocalNode.Level.Value == 1) { IQueryable <Metadata> dbMapNameMetadata; if (mapName == "*") { dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbLocalNode.NodeUid && qMetadata.MetadataName == "Name" select qMetadata; } else { dbMapNameMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbLocalNode.NodeUid && qMetadata.MetadataName == "Name" && qMetadata.MetadataValue == mapName select qMetadata; } if (dbMapNameMetadata != null && dbMapNameMetadata.Count() > 0) { if (dbLocalNode.NodeUid != Guid.Empty) { var dbMapNameMetadatum = dbMapNameMetadata.First(); Model.Map map = new Model.Map(); map.Domain = Domain; map.NodeId = dbLocalNode.NodeUid.Value; map.Name = dbMapNameMetadatum.MetadataValue; matchingMaps.Add(map); } } } } } return(matchingMaps); }
public void ExecuteCmdletBase(PSCmdlet callingCmdlet) { if (Domain == null) { callingCmdlet.WriteWarning("No valid domain has been provided."); return; } if (!Domain.CheckIsValid()) { callingCmdlet.WriteWarning("An invalid domain object has been provided."); return; } Model.IDatabaseInfo dbInfo = Domain; using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(dbInfo.ConnectionString)) { dataContext.CommandTimeout = 180; if (MapId != Guid.Empty) { /// Find maps by ID. /// Model.Map map = GetMapById(dataContext, MapId); callingCmdlet.WriteObject(map); } else if (!string.IsNullOrEmpty(MapName)) { /// Find maps by name. /// List <Model.Map> maps = GetMapsByName(dataContext, MapName); callingCmdlet.WriteObject(maps, true); } else { /// Fine all maps. /// List <Model.Map> maps = GetAllMaps(dataContext); callingCmdlet.WriteObject(maps, true); } } }
private IEnumerable<Node> CheckMetadataStringOperator(MappingToolDatabaseDataContext dbContext, IEnumerable<Node> nodes, GraphQueryMetadata metadataTest) { List<Node> filteredNodes = null; if (metadataTest.Operator.Equals("Contains", StringComparison.InvariantCultureIgnoreCase)) { IQueryable<Node> queryableNodes = nodes.AsQueryable(); var filteredMetadata = from dbMetadata in dbContext.udf_SearchMetadataContains(metadataTest.Name, metadataTest.Value) select dbMetadata; int counter = filteredMetadata.Count(); filteredNodes = nodes.Join(filteredMetadata, x => x.NodeUid, y => y.NodeUid, (a, b) => a).ToList(); } else if (metadataTest.Operator.Equals("FreeText", StringComparison.InvariantCultureIgnoreCase)) { IQueryable<Node> queryableNodes = nodes.AsQueryable(); var filteredMetadata = from dbMetadata in dbContext.udf_SearchMetadataFreeText(metadataTest.Name, metadataTest.Value) select dbMetadata; int counter = filteredMetadata.Count(); filteredNodes = nodes.Join(filteredMetadata, x => x.NodeUid, y => y.NodeUid, (a, b) => a).ToList(); } else { filteredNodes = new List<Node>(); foreach (Node node in nodes) { if (metadataTest.Operator.Equals("Equals", StringComparison.InvariantCultureIgnoreCase)) { if (node.Metadatas.Where(metadata => metadata.MetadataName == metadataTest.Name && metadata.MetadataValue.Contains(metadataTest.Value)).Count() > 0) { filteredNodes.Add(node); } } else if (metadataTest.Operator.Equals("NotEquals", StringComparison.InvariantCultureIgnoreCase)) { if (node.Metadatas.Where(metadata => metadata.MetadataName == metadataTest.Name && metadata.MetadataValue != metadataTest.Value).Count() > 0) { filteredNodes.Add(node); } } } } return filteredNodes; }
private IEnumerable <Node> CheckMetadataStringOperator(MappingToolDatabaseDataContext dbContext, IEnumerable <Node> nodes, GraphQueryMetadata metadataTest) { List <Node> filteredNodes = null; if (metadataTest.Operator.Equals("Contains", StringComparison.InvariantCultureIgnoreCase)) { IQueryable <Node> queryableNodes = nodes.AsQueryable(); var filteredMetadata = from dbMetadata in dbContext.udf_SearchMetadataContains(metadataTest.Name, metadataTest.Value) select dbMetadata; int counter = filteredMetadata.Count(); filteredNodes = nodes.Join(filteredMetadata, x => x.NodeUid, y => y.NodeUid, (a, b) => a).ToList(); } else if (metadataTest.Operator.Equals("FreeText", StringComparison.InvariantCultureIgnoreCase)) { IQueryable <Node> queryableNodes = nodes.AsQueryable(); var filteredMetadata = from dbMetadata in dbContext.udf_SearchMetadataFreeText(metadataTest.Name, metadataTest.Value) select dbMetadata; int counter = filteredMetadata.Count(); filteredNodes = nodes.Join(filteredMetadata, x => x.NodeUid, y => y.NodeUid, (a, b) => a).ToList(); } else { filteredNodes = new List <Node>(); foreach (Node node in nodes) { if (metadataTest.Operator.Equals("Equals", StringComparison.InvariantCultureIgnoreCase)) { if (node.Metadatas.Where(metadata => metadata.MetadataName == metadataTest.Name && metadata.MetadataValue.Contains(metadataTest.Value)).Count() > 0) { filteredNodes.Add(node); } } else if (metadataTest.Operator.Equals("NotEquals", StringComparison.InvariantCultureIgnoreCase)) { if (node.Metadatas.Where(metadata => metadata.MetadataName == metadataTest.Name && metadata.MetadataValue != metadataTest.Value).Count() > 0) { filteredNodes.Add(node); } } } } return(filteredNodes); }
private List <Model.Domain> GetDomainsByName(MappingToolDatabaseDataContext dataContext, string domainName) { var dbDomainNodes = from qDomainNode in dataContext.Nodes where qDomainNode.NodeTypeUid == DomainNodeType select qDomainNode; var dbMatchingNodes = from qMetadata in dataContext.Metadatas join qDomainNode in dbDomainNodes on qMetadata.NodeUid equals qDomainNode.NodeUid where qMetadata.MetadataName == "Name" && qMetadata.MetadataValue == domainName select qDomainNode; List <Model.Domain> matchingDomains = new List <Model.Domain>(); if (dbMatchingNodes == null || dbMatchingNodes.Count() == 0) { return(matchingDomains); } foreach (var dbDomainNode in dbMatchingNodes) { if (!dbDomainNode.DomainUid.HasValue || dbDomainNode.DomainUid.Value == Guid.Empty) { continue; } Model.Domain domain = new Model.Domain(); domain.DomainId = dbDomainNode.DomainUid.Value; domain.NodeId = dbDomainNode.NodeUid; domain.Name = domainName; Model.IDatabaseInfo dbInfo = domain; dbInfo.DatabaseServer = DatabaseServer; dbInfo.DatabaseName = DatabaseName; matchingDomains.Add(domain); } return(matchingDomains); }
public SoapNode AddNode(Guid domainId, SoapNodeType nodeType, string originalId) { SoapNode soapNode = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var domains = from dbDomain in mappingDb.Domains where dbDomain.DomainUid == domainId select dbDomain; Domain domain; if (domains.Count() > 0) { domain = domains.First(); } else { domain = new Domain(); domain.DomainUid = domainId; domain.DomainOriginalId = domainId.ToString(); mappingDb.Domains.InsertOnSubmit(domain); mappingDb.SubmitChanges(); } Node node = CreateNode(nodeType.Id, originalId); domain.Nodes.Add(node); mappingDb.SubmitChanges(); soapNode = new SoapNode(); soapNode.Domain = domainId; soapNode.Id = node.NodeUid; soapNode.NodeType = nodeType; } }); return soapNode; }
private List <Model.Domain> GetAllDomains(MappingToolDatabaseDataContext dataContext) { var dbAllDomainNodes = from qDomainNode in dataContext.Nodes where qDomainNode.NodeTypeUid == DomainNodeType select qDomainNode; var dbAllDomainNodesAndNames = from qMetadata in dataContext.Metadatas join qDomainNode in dbAllDomainNodes on qMetadata.NodeUid equals qDomainNode.NodeUid where qMetadata.MetadataName == "Name" select new { qDomainNode.NodeUid, qDomainNode.DomainUid.Value, qMetadata.MetadataValue }; List <Model.Domain> allDomains = new List <Model.Domain>(); if (dbAllDomainNodesAndNames == null || dbAllDomainNodesAndNames.Count() == 0) { return(allDomains); } foreach (var domainNodeAndName in dbAllDomainNodesAndNames) { if (domainNodeAndName.Value != Guid.Empty) { Model.Domain domain = new Model.Domain(); domain.DomainId = domainNodeAndName.Value; domain.NodeId = domainNodeAndName.NodeUid; domain.Name = domainNodeAndName.MetadataValue; Model.IDatabaseInfo dbInfo = domain; dbInfo.DatabaseServer = DatabaseServer; dbInfo.DatabaseName = DatabaseName; allDomains.Add(domain); } } return(allDomains); }
public SoapNode CreateNewDomain(string domainName) { SoapNode soapDomainNode = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var nodeTypes = from dbNodeTypes in mappingDb.NodeTypes where dbNodeTypes.NodeTypeName == "DomainNode" select dbNodeTypes; var metadataTypes = from dbMetadataTypes in mappingDb.MetadataTypes where dbMetadataTypes.MetadataTypeName == "string" select dbMetadataTypes; NodeType nodeType = nodeTypes.First(); MetadataType metadataType = metadataTypes.First(); Domain domain = new Domain(); domain.DomainUid = Guid.NewGuid(); mappingDb.Domains.InsertOnSubmit(domain); mappingDb.SubmitChanges(); Node domainNode = new Node(); domainNode.DomainUid = domain.DomainUid; domainNode.NodeUid = Guid.NewGuid(); domainNode.NodeType = nodeType; domainNode.NodeTypeUid = nodeType.NodeTypeUid; mappingDb.Nodes.InsertOnSubmit(domainNode); mappingDb.SubmitChanges(); SoapMetadataType soapMetadataType = new SoapMetadataType(); soapMetadataType.Id = metadataType.MetadataTypeUid; soapMetadataType.Name = metadataType.MetadataTypeName; soapDomainNode = UpdateNodeMetadata(domain.DomainUid, domainNode.NodeUid, Guid.Empty, null, "Name", domainName, soapMetadataType); } }); return soapDomainNode; }
private Model.Domain GetDomainById(MappingToolDatabaseDataContext dataContext, Guid domainId) { var dbDomainNodes = from qDomainNode in dataContext.Nodes where qDomainNode.DomainUid == domainId && qDomainNode.NodeTypeUid == DomainNodeType select qDomainNode; if (dbDomainNodes == null || dbDomainNodes.Count() == 0) { return null; } var dbDomainNode = dbDomainNodes.First(); var dbMatchingMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbDomainNode.NodeUid && qMetadata.MetadataName == "Name" select qMetadata; string domainName = string.Empty; if (dbMatchingMetadata != null && dbMatchingMetadata.Count() > 0) { var domainMetadata = dbMatchingMetadata.First(); domainName = domainMetadata.MetadataValue; } Model.Domain domain = new Model.Domain(); domain.DomainId = domainId; domain.NodeId = dbDomainNode.NodeUid; domain.Name = domainName; Model.IDatabaseInfo dbInfo = domain; dbInfo.DatabaseServer = DatabaseServer; dbInfo.DatabaseName = DatabaseName; return domain; }
private Model.Domain GetDomainById(MappingToolDatabaseDataContext dataContext, Guid domainId) { var dbDomainNodes = from qDomainNode in dataContext.Nodes where qDomainNode.DomainUid == domainId && qDomainNode.NodeTypeUid == DomainNodeType select qDomainNode; if (dbDomainNodes == null || dbDomainNodes.Count() == 0) { return(null); } var dbDomainNode = dbDomainNodes.First(); var dbMatchingMetadata = from qMetadata in dataContext.Metadatas where qMetadata.NodeUid == dbDomainNode.NodeUid && qMetadata.MetadataName == "Name" select qMetadata; string domainName = string.Empty; if (dbMatchingMetadata != null && dbMatchingMetadata.Count() > 0) { var domainMetadata = dbMatchingMetadata.First(); domainName = domainMetadata.MetadataValue; } Model.Domain domain = new Model.Domain(); domain.DomainId = domainId; domain.NodeId = dbDomainNode.NodeUid; domain.Name = domainName; Model.IDatabaseInfo dbInfo = domain; dbInfo.DatabaseServer = DatabaseServer; dbInfo.DatabaseName = DatabaseName; return(domain); }
public DeleteResult DeleteNodePromoteTransclusion(Guid domainId, Guid mapIdToDeleteFrom, Guid nodeIdToDelete) { lock (deleteLock) { DeleteResult result = new DeleteResult() { DeleteSuccessful = true }; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { Dictionary<string, SoapNodeType> soapNodeTypes; Dictionary<string, SoapRelationshipType> soapRelTypes; Dictionary<string, SoapMetadataType> soapMetaTypes; Dictionary<string, SoapDescriptorType> soapDescTypes; GetSoapTypes(out soapNodeTypes, out soapRelTypes, out soapMetaTypes, out soapDescTypes); var deleteNodes = from nodes in mappingDb.Nodes where nodes.NodeUid == nodeIdToDelete && nodes.DomainUid == domainId select nodes; //if the node existed it'll be the only one and delete just the transclusion relationship if (deleteNodes.Count() > 0) { DescriptorType fromDescriptorType = null; var fromDecriptorTypes = from dbDescriptorTypes in mappingDb.DescriptorTypes where dbDescriptorTypes.DescriptorTypeName.ToLower() == "from" select dbDescriptorTypes; if (fromDecriptorTypes.Count() != 1) { result.DeleteSuccessful = false; } else { fromDescriptorType = fromDecriptorTypes.First(); bool promotionCompleted = false; bool deletedOriginalMapContainer = false; // Delete the appropriate relationships from the node and promote a transclusion relationship var deletedNodesDescriptors = from descriptors in mappingDb.Descriptors where descriptors.NodeUid == nodeIdToDelete select descriptors; foreach (var descriptor in deletedNodesDescriptors) { if (descriptor.Relationship != null) { //Delete the Map Container Relationship if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "MapContainerRelationship" && !deletedOriginalMapContainer) { foreach (Descriptor relDescriptor in descriptor.Relationship.Descriptors) { if (relDescriptor.DescriptorType.DescriptorTypeName == "To") { if (mapIdToDeleteFrom == relDescriptor.NodeUid) { //Delete the map container relationship and all associated metadata DeleteResult relationshipDeleteResult = DeleteRelationship(domainId, descriptor.RelationshipUid.Value); if (!relationshipDeleteResult.DeleteSuccessful) { result.DeleteSuccessful = false; } } break; } } deletedOriginalMapContainer = true; } else if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "TransclusionRelationship" && !promotionCompleted) { string xPos = null; string yPos = null; foreach (Descriptor d1 in descriptor.Relationship.Descriptors) { if (d1.NodeUid == nodeIdToDelete) { foreach (Metadata metadata in d1.Node.Metadatas) { if (metadata.MetadataName == "XPosition" && metadata.RelationshipUid == descriptor.RelationshipUid) { xPos = metadata.MetadataValue; } else if (metadata.MetadataName == "YPosition" && metadata.RelationshipUid == descriptor.RelationshipUid) { yPos = metadata.MetadataValue; } if (xPos != null && yPos != null) { //found both values break; } } break; } } Guid newRootMapId = Guid.Empty; foreach (Descriptor altDescriptor in descriptor.Relationship.Descriptors) { if (altDescriptor.DescriptorType.DescriptorTypeName == "TransclusionMap") { newRootMapId = altDescriptor.NodeUid.Value; break; } } //Delete the transclusion relationship and all associated metadata DeleteResult relationshipDeleteResult = DeleteRelationship(domainId, descriptor.RelationshipUid.Value); if (!relationshipDeleteResult.DeleteSuccessful) { result.DeleteSuccessful = false; } if (xPos != null && yPos != null) { //Connect the Map Container Relationship between what was the transclusion map and the transcluded node (promotion to original map and original node) if (newRootMapId != Guid.Empty) { ConnectedNodesResult connectResult = ConnectToMap(domainId, newRootMapId, nodeIdToDelete, soapDescTypes, soapRelTypes); if (connectResult != null) { UpdateNodeMetadata(domainId, nodeIdToDelete, connectResult.Relationship.Id, soapDescTypes["From"], "XPosition", xPos, soapMetaTypes["double"]); UpdateNodeMetadata(domainId, nodeIdToDelete, connectResult.Relationship.Id, soapDescTypes["From"], "YPosition", yPos, soapMetaTypes["double"]); SoapNode promotedNode = connectResult.Nodes[nodeIdToDelete]; List<Guid> relationshipsToConvert = new List<Guid>(); foreach (SoapRelationship relationship in promotedNode.Relationships.Values) { //find all Transclusion relationships for the promotoed node on the transclusion map if (relationship.RelationshipType.Name == "TransclusionRelationship") { Guid mapNodeId = relationship.Nodes.Where(d => d.Key.Name == "TransclusionMap").First().Value; if (mapNodeId == newRootMapId) { relationshipsToConvert.Add(relationship.Id); } } } foreach (Guid relationshipId in relationshipsToConvert) { if (promotedNode.Relationships[relationshipId].Nodes.Where(pair => pair.Key.Name == "From").Count() > 0) { Guid fromNodeId = promotedNode.Relationships[relationshipId].Nodes.Where(pair => pair.Key.Name == "From").First().Value; Guid toNodeId = promotedNode.Relationships[relationshipId].Nodes.Where(pair => pair.Key.Name == "To").First().Value; Dictionary<SoapDescriptorType, Guid> nodes = new Dictionary<SoapDescriptorType, Guid>(); nodes.Add(soapDescTypes["From"], fromNodeId); nodes.Add(soapDescTypes["To"], toNodeId); ConnectNodes(domainId, nodes, soapRelTypes["FromToRelationship"], relationshipId.ToString()); DeleteRelationship(domainId, relationshipId); } } } promotionCompleted = true; } } } else if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "FromToRelationship") { DeleteRelationship(domainId, descriptor.RelationshipUid.Value); } } } } } } }); result.DeletedId = nodeIdToDelete; return result; } }
private bool IsNodeInMap(Guid domainId, Guid mapId, Guid nodeId) { bool result = false; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var mapContainerRelationships = Queryable.Where(Queryable.Where(mappingDb.Relationships, (r1) => r1.DomainUid == domainId), (r) => r.RelationshipType.RelationshipTypeName == "MapContainerRelationship"); var transclusionRelationships = Queryable.Where(Queryable.Where(mappingDb.Relationships, (r1) => r1.DomainUid == domainId), (r) => r.RelationshipType.RelationshipTypeName == "TransclusionRelationship"); var relationships = Queryable.Union(mapContainerRelationships, transclusionRelationships); //test if the node existed if (relationships.Count() > 0) { foreach (Relationship relationship in relationships) { if (result) { break; } if (relationship.RelationshipType.RelationshipTypeName == "MapContainerRelationship") { foreach (Descriptor descriptor in relationship.Descriptors.Where( d => d.DescriptorType.DescriptorTypeName == "To").Where(n => n.NodeUid == mapId)) { if (result) { break; } foreach (Descriptor altDesc in descriptor.Relationship.Descriptors.Where(d => d.DescriptorUid != descriptor.DescriptorUid)) { if (altDesc.NodeUid == nodeId) { result = true; break; } } } } else if (relationship.RelationshipType.RelationshipTypeName == "TransclusionRelationship") { foreach (Descriptor descriptor in relationship.Descriptors.Where( d => d.DescriptorType.DescriptorTypeName == "TransclusionMap").Where(n => n.NodeUid == mapId)) { if (result) { break; } foreach (Descriptor altDesc in descriptor.Relationship.Descriptors.Where(d => d.DescriptorUid != descriptor.DescriptorUid)) { if (altDesc.NodeUid == nodeId) { result = true; break; } } } } } } } }); return result; }
public DeleteResult DeleteNodeTransclusion(Guid domainId, Guid mapIdToDeleteFrom, Guid nodeIdToDelete) { lock (deleteLock) { DeleteResult result = new DeleteResult() { DeleteSuccessful = true }; Guid transclusionRelationshipDeleted = Guid.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var deleteNodes = from nodes in mappingDb.Nodes where nodes.NodeUid == nodeIdToDelete && nodes.DomainUid == domainId select nodes; //if the node existed it'll be the only one and delete just the transclusion relationship if (deleteNodes.Count() > 0) { // Delete the descriptors that have the node to be deleted associated with them directly var deleteDescriptors = from descriptors in mappingDb.Descriptors where descriptors.NodeUid == nodeIdToDelete select descriptors; foreach (var descriptor in deleteDescriptors) { //Delete the Transclusion Relationships if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "TransclusionRelationship") { foreach (Descriptor relDescriptor in descriptor.Relationship.Descriptors) { if (relDescriptor.DescriptorType.DescriptorTypeName == "TransclusionMap") { if (mapIdToDeleteFrom == relDescriptor.NodeUid) { //Delete the transclusion relationship and all associated metadata DeleteResult relationshipDeleteResult = DeleteRelationship(domainId, descriptor.RelationshipUid.Value); if (!relationshipDeleteResult.DeleteSuccessful) { result.DeleteSuccessful = false; } } break; } } } } } } }); result.DeletedId = nodeIdToDelete; return result; } }
public IEnumerable<Node> ApplySearchConditions(MappingToolDatabaseDataContext dbContext, IEnumerable<Node> nodes) { //Dictionary<Guid, Node> nodes = node.GetConnectedNodes().ToDictionary(connectedNode => connectedNode.NodeUid); Dictionary<Guid, int> nodeUniquenessCount = new Dictionary<Guid, int>(); Dictionary<Guid, Node> nodesById = nodes.Distinct().ToDictionary<Node, Guid>(node => node.NodeUid); Dictionary<Guid, int> capturedNodes = new Dictionary<Guid, int>(); int numOfTests = 0; if (Match.SchemaSet != null) { foreach (GraphQuerySchema schemaTest in Match.SchemaSet) { numOfTests++; IEnumerable<Node> filteredNodes = null; if (schemaTest.BaseType.Equals("Node", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckNodeOperator(nodes, schemaTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } if (Match.TypeSet != null) { foreach (GraphQueryType typeTest in Match.TypeSet) { numOfTests++; IEnumerable<Node> filteredNodes = null; if (typeTest.BaseType.Equals("NodeType", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckNodeTypeOperator(nodes, typeTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } if (Match.MetadataSet != null) { foreach (GraphQueryMetadata metadataTest in Match.MetadataSet) { numOfTests++; IEnumerable<Node> filteredNodes = null; if (!string.IsNullOrEmpty(metadataTest.BaseType)) { if (metadataTest.BaseType.Equals("String", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataStringOperator(dbContext, nodes, metadataTest); } else if (metadataTest.BaseType.Equals("Int", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataIntOperator(nodes, metadataTest); } else if (metadataTest.BaseType.Equals("Double", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataDoubleOperator(nodes, metadataTest); } else if (metadataTest.BaseType.Equals("DateTime", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataDateTimeOperator(nodes, metadataTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } } List<Node> allFilteredNodes = new List<Node>(); foreach (KeyValuePair<Guid, int> capturedNode in capturedNodes) { if (capturedNode.Value == numOfTests) { allFilteredNodes.Add(nodesById[capturedNode.Key]); } } return allFilteredNodes; }
public Guid GetContainerMapNodeId(Guid domainId, Guid nodeId) { Guid result = Guid.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var mapNodes = from dbNode in mappingDb.Nodes where dbNode.NodeType.NodeTypeName == "CompendiumMapNode" && dbNode.DomainUid == domainId select dbNode; Node containerMap = null; var nodes = mapNodes.Where(d => d.NodeUid == nodeId); if (nodes.Count() == 1) { containerMap = nodes.First(); result = containerMap.NodeUid; } else { foreach (Node mapNode in mapNodes) { foreach (Descriptor descriptor in mapNode.Descriptors) { if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "MapContainerRelationship" && descriptor.DescriptorType.DescriptorTypeName == "To") { foreach (Descriptor altDescriptor in descriptor.Relationship.Descriptors.Where(de => de.DescriptorUid != descriptor.DescriptorUid)) { if (altDescriptor.NodeUid == nodeId) { containerMap = mapNode; break; } } if (containerMap != null) { break; } } } if (containerMap != null) { break; } } } if (containerMap != null) { result = containerMap.NodeUid; } } }); return result; }
public Guid GetDomainNodeId(Guid domainId) { Guid domainNodeId = Guid.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var matchingDomainNodes = from dbNode in mappingDb.Nodes where dbNode.NodeType.NodeTypeName == "DomainNode" && dbNode.DomainUid == domainId select dbNode; if (matchingDomainNodes.Count() > 0) { Node domainNode = matchingDomainNodes.First(); if (domainNode != null) { domainNodeId = domainNode.NodeUid; } } } }); return domainNodeId; }
public bool RenameNodeMetadata(Guid domainId, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string originalMetadataName, string newMetadataName) { bool success = false; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { try { var nodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == soapNodeId select dbNode; Node node = nodes.Single(); foreach (Metadata metadatum in node.Metadatas.Where(x => x.MetadataName == originalMetadataName)) { if (soapNodeId != Guid.Empty) { if (metadatum.NodeUid != soapNodeId) { continue; //this should never happen since it's the node's metadata } } if (soapRelationshipId != Guid.Empty) { if (metadatum.RelationshipUid != soapRelationshipId) { continue; } } if (soapDescriptorType != null) { if (metadatum.DescriptorTypeUid != soapDescriptorType.Id) { continue; } } //same context so we can rename it metadatum.MetadataName = newMetadataName; mappingDb.SubmitChanges(); } } catch (Exception ex) { LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "An error occurred renaming the metadata entry {0}, exception={1}", originalMetadataName, ex.Message); } finally { success = true; LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Verbose, "Metadata property on Node with Id: {0} with name: {1} was renamed to: {2}", soapNodeId.ToString(), originalMetadataName, newMetadataName); } } }); return success; }
private static SoapMetadata UpdateMetadata(MappingToolDatabaseDataContext mappingDb, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string metadataName, string metadataValue, SoapMetadataType soapMetadataType, Node node) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = metadataName; soapMetadata.MetadataValue = metadataValue; soapMetadata.MetadataType = soapMetadataType; bool existingMetaData = false; foreach (Metadata metadatum in node.Metadatas.Where(x => x.MetadataName == metadataName)) { if (soapNodeId != Guid.Empty) { if (metadatum.NodeUid != soapNodeId) { continue; } } if (soapRelationshipId != Guid.Empty) { if (metadatum.RelationshipUid != soapRelationshipId) { continue; } } if (soapDescriptorType != null) { if (metadatum.DescriptorTypeUid != soapDescriptorType.Id) { continue; } } existingMetaData = true; if (metadatum.MetadataTypeUid != soapMetadataType.Id) { //change in MetadataType metadatum.MetadataType = mappingDb.MetadataTypes.Single(mdt => mdt.MetadataTypeUid == soapMetadataType.Id); } metadatum.MetadataValue = metadataValue; break; } if (!existingMetaData) { Metadata metadata = new Metadata(); metadata.MetadataId = Guid.NewGuid(); metadata.MetadataTypeUid = soapMetadataType.Id; if (soapNodeId != Guid.Empty) { metadata.NodeUid = soapNodeId; } if (soapRelationshipId != Guid.Empty) { metadata.RelationshipUid = soapRelationshipId; } if (soapDescriptorType != null) { metadata.DescriptorTypeUid = soapDescriptorType.Id; } metadata.MetadataName = metadataName; metadata.MetadataValue = metadataValue; node.Metadatas.Add(metadata); } return soapMetadata; }
public RelatedNodesSearchResult GetNodesWithConditions(Guid domainId, Guid nodeId, int maxDepth, List<Condition> conditions) { RelatedNodesSearchResult result = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var matchingFocusedNodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == nodeId select dbNode; Dictionary<Guid, SoapNode> nodes = new Dictionary<Guid, SoapNode>(); if (matchingFocusedNodes.Count() > 0) { var focusedNode = matchingFocusedNodes.First(); RecurseThroughLevels(nodes, domainId, focusedNode, focusedNode, maxDepth, conditions); evaluatedNodes.Clear(); excludedNodes.Clear(); } result = new RelatedNodesSearchResult() { Nodes = nodes, SearchedNode = nodeId }; } }); return result; }
public RelatedNodesSearchResult GetNodesXmlQuery(string graphQueryXml) { GraphQuery graphQuery = null; try { XmlSerializer graphQueryXmlSerializer = new XmlSerializer(typeof(GraphQuery)); StringReader graphQueryXmlReader = new StringReader(graphQueryXml); graphQuery = graphQueryXmlSerializer.Deserialize(graphQueryXmlReader) as GraphQuery; } finally { if (graphQuery == null) { LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "Graph Query XML is not in the correct format."); throw new NotSupportedException("XML is not in the correct format."); } } RelatedNodesSearchResult nodesSearchResult = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { Guid startingNodeId; List<Node> capturedNodes; if (graphQuery.Context.NodeId == Guid.Empty) { var allMapNodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == graphQuery.Context.DomainId select dbNode; capturedNodes = allMapNodes.ToList(); startingNodeId = Guid.Empty; } else { var startingNodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == graphQuery.Context.DomainId && dbNode.NodeUid == graphQuery.Context.NodeId select dbNode; if (startingNodes.Count() <= 0) { throw new ArgumentOutOfRangeException("The given node context doesn't exist."); } var startingNode = startingNodes.First(); startingNodeId = startingNode.NodeUid; capturedNodes = RecurseThroughGraph(graphQuery, startingNode, 1); capturedNodes.Add(startingNode); } IEnumerable<Node> filteredNodes = graphQuery.Filters.ApplyFilters(mappingDb, capturedNodes); Dictionary<Guid, SoapNode> soapNodes = new Dictionary<Guid, SoapNode>(); int count = 0; foreach (Node node in filteredNodes) { count++; if (count > graphQuery.Items && graphQuery.Items > 0) { break; } if (!soapNodes.ContainsKey(node.NodeUid)) { SoapNode soapNode = node.ToSoapObject(); soapNodes.Add(soapNode.Id, soapNode); } } nodesSearchResult = new RelatedNodesSearchResult(); nodesSearchResult.Nodes = soapNodes; nodesSearchResult.SearchedNode = startingNodeId; } }); return nodesSearchResult; }
public RelatedNodesSearchResult GetMapsNodes(Guid domainId, Guid mapNodeId) { RelatedNodesSearchResult result = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var matchingMapId = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == mapNodeId select dbNode; Dictionary<Guid, SoapNode> nodes = new Dictionary<Guid, SoapNode>(); if (matchingMapId.Count() > 0) { var mapNode = matchingMapId.First(); IEnumerable<Node> relatedNodes = mapNode.GetConnectedNodes( (Descriptor localDescriptor) => (localDescriptor.DescriptorType.DescriptorTypeName == "To") || (localDescriptor.DescriptorType.DescriptorTypeName == "TransclusionMap"), (Relationship relationship) => relationship.RelationshipType.RelationshipTypeName != "FromToRelationship"); foreach (Node relatedNode in relatedNodes) { SoapNode soapNode = relatedNode.ToSoapObject(); if (ContainsMetadataKeyName(soapNode, "XPosition") && ContainsMetadataKeyName(soapNode, "YPosition")) { if (soapNode.NodeType.Name != "DomainNode") { nodes.Add(soapNode.Id, soapNode); } } } } result = new RelatedNodesSearchResult() { Nodes = nodes, SearchedNode = mapNodeId }; } }); return result; }
public DeleteResult DeleteMetadata(MetadataContext context) { DeleteResult result = new DeleteResult() { DeleteSuccessful = false, DeletedId = Guid.Empty }; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { if ((context.RelationshipUid != null && context.RelationshipUid.HasValue) && (context.DescriptorTypeUid != null && context.DescriptorTypeUid.HasValue)) { var deleteMetadatas = from metadata in mappingDb.Metadatas where metadata.NodeUid.Value == context.NodeUid.Value && metadata.DescriptorTypeUid.Value == context.DescriptorTypeUid.Value && metadata.RelationshipUid.Value == context.RelationshipUid.Value && metadata.MetadataName == context.MetadataName select metadata; DeleteMetadata(context, result, mappingDb, deleteMetadatas); } else if ((context.RelationshipUid == null || !context.RelationshipUid.HasValue) && (context.DescriptorTypeUid != null || context.DescriptorTypeUid.HasValue)) { var deleteMetadatas = from metadata in mappingDb.Metadatas where metadata.NodeUid.Value == context.NodeUid.Value && metadata.DescriptorTypeUid.Value == context.DescriptorTypeUid.Value && metadata.MetadataName == context.MetadataName select metadata; DeleteMetadata(context, result, mappingDb, deleteMetadatas); } else if ((context.RelationshipUid != null || context.RelationshipUid.HasValue) && (context.DescriptorTypeUid == null || !context.DescriptorTypeUid.HasValue)) { var deleteMetadatas = from metadata in mappingDb.Metadatas where metadata.NodeUid.Value == context.NodeUid.Value && metadata.RelationshipUid.Value == context.RelationshipUid.Value && metadata.MetadataName == context.MetadataName select metadata; DeleteMetadata(context, result, mappingDb, deleteMetadatas); } else { var deleteMetadatas = from metadata in mappingDb.Metadatas where metadata.NodeUid.Value == context.NodeUid.Value && metadata.MetadataName == context.MetadataName select metadata; DeleteMetadata(context, result, mappingDb, deleteMetadatas); } } }); return result; }
public RelatedNodesSearchResult GetDomainMapNodes(Guid domainId, int page, int pageSize) { RelatedNodesSearchResult mapNodesResult = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { Guid domainNodesId = GetDomainNodeId(domainId); var mapNodes = from dbNode in mappingDb.Nodes where dbNode.NodeType.NodeTypeName == "CompendiumMapNode" && dbNode.DomainUid == domainId select dbNode; List<Node> mapNodeResults = new List<Node>(); foreach (Node mapNode in mapNodes) { foreach (Descriptor descriptor in mapNode.Descriptors) { if (descriptor.Relationship.RelationshipType.RelationshipTypeName == "MapContainerRelationship" && descriptor.DescriptorType.DescriptorTypeName == "From") { foreach (Descriptor altDescriptor in descriptor.Relationship.Descriptors.Where(de => de.DescriptorUid != descriptor.DescriptorUid)) { if (altDescriptor.NodeUid == domainNodesId && !mapNodeResults.Contains(descriptor.Node)) { mapNodeResults.Add(descriptor.Node); } } } } } var mapNodes1 = mapNodeResults.Skip((page - 1) * pageSize).Take(pageSize); mapNodesResult = new RelatedNodesSearchResult(domainId, mapNodes1); } }); return mapNodesResult; }
public ConnectedNodesResult ConnectNodes(Guid domainId, Dictionary<SoapDescriptorType, Guid> nodes, SoapRelationshipType relationshipType, string originalId) { ConnectedNodesResult connectedNodesResult = null; if (nodes.Values.Distinct().Count() > 1) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { List<SoapNode> updatedNodes = new List<SoapNode>(); var domains = from dbDomain in mappingDb.Domains where dbDomain.DomainUid == domainId select dbDomain; var domain = domains.First(); Relationship relationship = new Relationship(); relationship.RelationshipUid = Guid.NewGuid(); relationship.RelationshipOriginalId = originalId; relationship.RelationshipTypeUid = relationshipType.Id; SoapRelationship soapRelationship = new SoapRelationship(); soapRelationship.Id = relationship.RelationshipUid; soapRelationship.RelationshipType = relationshipType; foreach (KeyValuePair<SoapDescriptorType, Guid> keyValuePair in nodes) { Descriptor descriptor = new Descriptor(); descriptor.DescriptorUid = Guid.NewGuid(); descriptor.RelationshipUid = relationship.RelationshipUid; descriptor.DescriptorTypeUid = keyValuePair.Key.Id; Node node = domain.Nodes.Single(x => x.NodeUid == keyValuePair.Value); node.Domain = domain; node.Descriptors.Add(descriptor); soapRelationship.Nodes.Add(keyValuePair.Key, node.NodeUid); SoapNode soapNode = node.ToSoapObject(); soapNode.Relationships.Add(soapRelationship.Id, soapRelationship); updatedNodes.Add(soapNode); domain.Relationships.Add(relationship); } mappingDb.SubmitChanges(); connectedNodesResult = new ConnectedNodesResult(); connectedNodesResult.Relationship = soapRelationship; connectedNodesResult.Nodes = new Dictionary<Guid, SoapNode>(); foreach (SoapNode soapNode in updatedNodes) { if (!connectedNodesResult.Nodes.ContainsKey(soapNode.Id)) { connectedNodesResult.Nodes.Add(soapNode.Id, soapNode); } } } }); } else { LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "ConnectNodes() failed: There must be at least 2 distinct nodes connected."); //This will cause an error to be returned on the WFC event, over SOAP it won't contain the fault contract. throw new FaultException<ConnectNodesFailureFault>(new ConnectNodesFailureFault(), "There must be at least 2 distinct nodes connected."); } return connectedNodesResult; }
public Dictionary<Guid, SoapNode> GetAllNodes(Guid domainId) { Dictionary<Guid, SoapNode> nodes = new Dictionary<Guid, SoapNode>(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var matchingNodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId select dbNode; foreach (var node in matchingNodes) { SoapNode soapNode = new SoapNode(); soapNode.Domain = domainId; soapNode.Id = node.NodeUid; soapNode.NodeType = (SoapNodeType)SoapTypeFactory.GetSoapType<SoapNodeType>(node.NodeTypeUid.Value); /// Get the relationships for the node /// foreach (var originatingDescriptor in node.Descriptors) { Relationship relationship = originatingDescriptor.Relationship; var relationshipMetadata = from dbDatum in relationship.Metadatas where !dbDatum.NodeUid.HasValue && !dbDatum.DescriptorTypeUid.HasValue select dbDatum; SoapRelationship soapRelationship = new SoapRelationship(); soapRelationship.Id = relationship.RelationshipUid; soapRelationship.RelationshipType = (SoapRelationshipType)SoapTypeFactory.GetSoapType<SoapRelationshipType>(relationship.RelationshipTypeUid.Value); foreach (var datum in relationshipMetadata) { SoapMetadata soapDatum = new SoapMetadata(); soapDatum.MetadataName = datum.MetadataName; soapDatum.MetadataValue = datum.MetadataValue; if (datum.MetadataTypeUid.HasValue) { soapDatum.MetadataType = (SoapMetadataType)SoapTypeFactory.GetSoapType<SoapMetadataType>(datum.MetadataTypeUid.Value); } soapRelationship.Metadata.Add(datum.MetadataName, soapDatum); } foreach (var destinationDescriptor in relationship.Descriptors) { if (destinationDescriptor.DescriptorUid == originatingDescriptor.DescriptorUid) { continue; } if (nodes.ContainsKey(destinationDescriptor.Node.NodeUid)) { continue; } Node childNode = destinationDescriptor.Node; /// Connect the node to the relationships. /// if (!destinationDescriptor.DescriptorTypeUid.HasValue) { throw new NotSupportedException("The descriptor doesn't have a type ID."); } SoapDescriptorType soapDescriptorType = (SoapDescriptorType)SoapTypeFactory.GetSoapType<SoapDescriptorType>(destinationDescriptor.DescriptorTypeUid.Value); soapRelationship.Nodes.Add(soapDescriptorType, childNode.NodeUid); } soapNode.Relationships.Add(soapRelationship.Id, soapRelationship); } /// Get the metadata for the node according to the current context. /// var metadata = from dbDatum in node.Metadatas select dbDatum; foreach (var datum in metadata.OrderBy(x => (x.RelationshipUid != null) ? x.RelationshipUid : Guid.Empty).OrderBy(x => (x.DescriptorTypeUid != null) ? x.DescriptorTypeUid : Guid.Empty)) { MetadataContext key = new MetadataContext() { MetadataName = datum.MetadataName, NodeUid = datum.NodeUid, RelationshipUid = datum.RelationshipUid, DescriptorTypeUid = datum.DescriptorTypeUid }; SoapMetadata soapDatum = new SoapMetadata(); soapDatum.MetadataName = datum.MetadataName; soapDatum.MetadataValue = datum.MetadataValue; if (datum.MetadataTypeUid.HasValue) { soapDatum.MetadataType = (SoapMetadataType)SoapTypeFactory.GetSoapType<SoapMetadataType>(datum.MetadataTypeUid.Value); } soapNode.Metadata.Add(key, soapDatum); } /// End getting metadata. /// nodes.Add(soapNode.Id, soapNode); } } }); return nodes; }
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."); } }
public IEnumerable <Node> ApplySearchConditions(MappingToolDatabaseDataContext dbContext, IEnumerable <Node> nodes) { //Dictionary<Guid, Node> nodes = node.GetConnectedNodes().ToDictionary(connectedNode => connectedNode.NodeUid); Dictionary <Guid, int> nodeUniquenessCount = new Dictionary <Guid, int>(); Dictionary <Guid, Node> nodesById = nodes.Distinct().ToDictionary <Node, Guid>(node => node.NodeUid); Dictionary <Guid, int> capturedNodes = new Dictionary <Guid, int>(); int numOfTests = 0; if (Match.SchemaSet != null) { foreach (GraphQuerySchema schemaTest in Match.SchemaSet) { numOfTests++; IEnumerable <Node> filteredNodes = null; if (schemaTest.BaseType.Equals("Node", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckNodeOperator(nodes, schemaTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } if (Match.TypeSet != null) { foreach (GraphQueryType typeTest in Match.TypeSet) { numOfTests++; IEnumerable <Node> filteredNodes = null; if (typeTest.BaseType.Equals("NodeType", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckNodeTypeOperator(nodes, typeTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } if (Match.MetadataSet != null) { foreach (GraphQueryMetadata metadataTest in Match.MetadataSet) { numOfTests++; IEnumerable <Node> filteredNodes = null; if (!string.IsNullOrEmpty(metadataTest.BaseType)) { if (metadataTest.BaseType.Equals("String", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataStringOperator(dbContext, nodes, metadataTest); } else if (metadataTest.BaseType.Equals("Int", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataIntOperator(nodes, metadataTest); } else if (metadataTest.BaseType.Equals("Double", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataDoubleOperator(nodes, metadataTest); } else if (metadataTest.BaseType.Equals("DateTime", StringComparison.InvariantCultureIgnoreCase)) { filteredNodes = CheckMetadataDateTimeOperator(nodes, metadataTest); } if (filteredNodes != null) { foreach (Node filteredNode in filteredNodes) { if (capturedNodes.ContainsKey(filteredNode.NodeUid)) { capturedNodes[filteredNode.NodeUid] += 1; } else { capturedNodes[filteredNode.NodeUid] = 1; } } } } } } List <Node> allFilteredNodes = new List <Node>(); foreach (KeyValuePair <Guid, int> capturedNode in capturedNodes) { if (capturedNode.Value == numOfTests) { allFilteredNodes.Add(nodesById[capturedNode.Key]); } } return(allFilteredNodes); }
public SoapNode UpdateNodeMetadata(Guid domainId, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string metadataName, string metadataValue, SoapMetadataType soapMetadataType) { SoapNode soapNode = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var nodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == soapNodeId select dbNode; var node = nodes.First(); SoapMetadata soapMetadata = UpdateMetadata(mappingDb, soapNodeId, soapRelationshipId, soapDescriptorType, metadataName, metadataValue, soapMetadataType, node); soapNode = node.ToSoapObject(); mappingDb.SubmitChanges(); } }); return soapNode; }
public Dictionary<string, Guid> GetDomainNodeIds() { Dictionary<string, Guid> result = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var domainNodes = from dbNode in mappingDb.Nodes where dbNode.NodeType.NodeTypeName == "DomainNode" select dbNode; Dictionary<string, Guid> domainNodeIds = new Dictionary<string, Guid>(); foreach (var domainNode in domainNodes) { IEnumerable<string> key = from dbMetadata in domainNode.Metadatas where dbMetadata.MetadataName == "Name" select dbMetadata.MetadataValue; if (!domainNodeIds.ContainsKey(key.First()) && domainNode.DomainUid.HasValue) { domainNodeIds[key.First()] = domainNode.DomainUid.Value; } } result = domainNodeIds; } }); return result; }
public List<SoapTypeElement> GetAllSoapTypes() { List<SoapTypeElement> soapTypes = new List<SoapTypeElement>(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var metadataTypes = from dbMetadataTypes in mappingDb.MetadataTypes select dbMetadataTypes; var nodeTypes = from dbNodeTypes in mappingDb.NodeTypes select dbNodeTypes; var descriptorTypes = from dbDescriptorTypes in mappingDb.DescriptorTypes select dbDescriptorTypes; var relationshipTypes = from dbRelationshipTypes in mappingDb.RelationshipTypes select dbRelationshipTypes; foreach (var metadataType in metadataTypes) { SoapMetadataType soapMetadataType = new SoapMetadataType(); soapMetadataType.Id = metadataType.MetadataTypeUid; soapMetadataType.Name = metadataType.MetadataTypeName; soapTypes.Add(soapMetadataType); } foreach (var nodeType in nodeTypes) { SoapNodeType soapNodeType = new SoapNodeType(); soapNodeType.Id = nodeType.NodeTypeUid; soapNodeType.Name = nodeType.NodeTypeName; soapTypes.Add(soapNodeType); } foreach (var descriptorType in descriptorTypes) { SoapDescriptorType soapDescriptorType = new SoapDescriptorType(); soapDescriptorType.Id = descriptorType.DescriptorTypeUid; soapDescriptorType.Name = descriptorType.DescriptorTypeName; soapTypes.Add(soapDescriptorType); } foreach (var relationshipType in relationshipTypes) { SoapRelationshipType soapRelationshipType = new SoapRelationshipType(); soapRelationshipType.Id = relationshipType.RelationshipTypeUid; soapRelationshipType.Name = relationshipType.RelationshipTypeName; soapTypes.Add(soapRelationshipType); } } }); return soapTypes; }
public Guid CreateNewMap(Guid domainId, string mapName) { Guid newMapUid = Guid.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { Node mapNode = null; using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var mapNodeTypes = from dbNodeTypes in mappingDb.NodeTypes where dbNodeTypes.NodeTypeName == "CompendiumMapNode" select dbNodeTypes; var metadataTypes = from dbMetaDataTypes in mappingDb.MetadataTypes where dbMetaDataTypes.MetadataTypeName == "string" select dbMetaDataTypes; var domains = from dbDomain in mappingDb.Domains where dbDomain.DomainUid == domainId select dbDomain; if (mapNodeTypes.Count() == 1 && metadataTypes.Count() == 1 && domains.Count() == 1) //there should only be one { Domain domain = domains.First(); NodeType nodeType = mapNodeTypes.First(); MetadataType metadataType = metadataTypes.First(); SoapMetadataType soapMetadataType = new SoapMetadataType(); soapMetadataType.Id = metadataType.MetadataTypeUid; soapMetadataType.Name = metadataType.MetadataTypeName; mapNode = CreateNode(nodeType.NodeTypeUid, mapName); UpdateMetadata(mappingDb, mapNode.NodeUid, Guid.Empty, null, "Name", mapName, soapMetadataType, mapNode); domain.Nodes.Add(mapNode); mappingDb.SubmitChanges(); } if (mapNode != null) { newMapUid = mapNode.NodeUid; Dictionary<string, SoapNodeType> soapNodeTypes; Dictionary<string, SoapRelationshipType> soapRelTypes; Dictionary<string, SoapMetadataType> soapMetaTypes; Dictionary<string, SoapDescriptorType> soapDescTypes; GetSoapTypes(out soapNodeTypes, out soapRelTypes, out soapMetaTypes, out soapDescTypes); Guid domainNodeId = GetDomainNodeId(domainId); ConnectToMap(domainId, domainNodeId, newMapUid, soapDescTypes, soapRelTypes); } } }); return newMapUid; }
private List <Model.Map> GetAllMaps(MappingToolDatabaseDataContext dataContext) { return(GetMapsByName(dataContext, "*")); }
public DeleteResult DeleteRelationship(Guid domainId, Guid relationshipId) { lock (deleteLock) { DeleteResult result = new DeleteResult() { DeleteSuccessful = false, DeletedId = relationshipId }; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var deleteRelationships = from relationships in mappingDb.Relationships where relationships.RelationshipUid == relationshipId && relationships.DomainUid == domainId select relationships; //if the relationship existed it'll be the only one and can delete all the descriptors and metadatum if (deleteRelationships.Count() > 0) { var relationship = deleteRelationships.First(); var deleteDescriptors = from descriptors in mappingDb.Descriptors where descriptors.RelationshipUid == relationshipId select descriptors; foreach (var descriptor in deleteDescriptors) { mappingDb.Descriptors.DeleteOnSubmit(descriptor); } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } // Delete metadata associated with the relationship just deleted var deleteRelationshipMetadatum = from metadatum in mappingDb.Metadatas where metadatum.RelationshipUid == relationshipId select metadatum; foreach (var relationshipMetadatum in deleteRelationshipMetadatum) { mappingDb.Metadatas.DeleteOnSubmit(relationshipMetadatum); } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } mappingDb.Relationships.DeleteOnSubmit(relationship); try { mappingDb.SubmitChanges(); result.DeleteSuccessful = true; } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } } } }); return result; } }
public void ExecuteCmdletBase(PSCmdlet callingCmdlet) { HashSet <Guid> validMaps = new HashSet <Guid>(); HashSet <Guid> orphanedNodes = new HashSet <Guid>(); HashSet <Guid> orphanedRelationships = new HashSet <Guid>(); if (RootMap == null || !RootMap.CheckIsValid()) { callingCmdlet.WriteWarning("An invalid source map has been provided."); return; } Model.IDatabaseInfo mapDbInfo = RootMap.Domain; using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(mapDbInfo.ConnectionString)) { dataContext.CommandTimeout = 180; var dbRootMapNodes = from dbNode in dataContext.Nodes where dbNode.NodeUid == RootMap.NodeId select dbNode; var dbRootMapNode = dbRootMapNodes.FirstOrDefault(); if (dbRootMapNode == null) { throw new KeyNotFoundException("The specified root map doesn't exist."); } if (dbRootMapNode.NodeUid != dbRootMapNode.RootMapUid) { throw new NotSupportedException("The provided root map isn't a root map."); } /// We need to find all the valid children maps, starting at the root map. We'll do this recursively. #region Find valid maps validMaps.Add(dbRootMapNode.NodeUid); RecusivelyFindValidMaps(ref validMaps, dbRootMapNode); #endregion #region Find all nodes that aren't part of a valid map var allNodesInMap = from dbNode in dataContext.Nodes where dbNode.RootMapUid == RootMap.NodeId select dbNode; foreach (var node in allNodesInMap) { if (validMaps.Contains(node.NodeUid)) { continue; } bool isNodeValid = CheckIsValid(ref validMaps, node); if (!isNodeValid) { /// If the orphaned nodes list doesn't contain the node, then add the node to the list. if (!orphanedNodes.Contains(node.NodeUid)) { orphanedNodes.Add(node.NodeUid); } /// Find all the orphaned relationships. FindOrphanedRelationships(ref orphanedRelationships, node); } } #endregion int orphanedNodesCount = 0; int orphanedMetadataCount = 0; int orphanedDescriptorsCount = 0; int orphanedRelationshipsCount = 0; foreach (Guid nodeId in orphanedNodes) { var orphanedDescriptors = from dbDescriptor in dataContext.Descriptors where dbDescriptor.NodeUid == nodeId select dbDescriptor; foreach (var orphanedDescriptor in orphanedDescriptors) { dataContext.Descriptors.DeleteOnSubmit(orphanedDescriptor); orphanedDescriptorsCount++; } var orphanedMetadata = from dbMetadata in dataContext.Metadatas where dbMetadata.NodeUid == nodeId select dbMetadata; foreach (var orphanedMetadatum in orphanedMetadata) { dataContext.Metadatas.DeleteOnSubmit(orphanedMetadatum); orphanedMetadataCount++; } } dataContext.SubmitChanges(); foreach (Guid relationshipId in orphanedRelationships) { var orphanedDescriptors = from dbDescriptor in dataContext.Descriptors where dbDescriptor.RelationshipUid == relationshipId select dbDescriptor; foreach (var orphanedDescriptor in orphanedDescriptors) { dataContext.Descriptors.DeleteOnSubmit(orphanedDescriptor); orphanedDescriptorsCount++; } var orphanedMetadata = from dbMetadata in dataContext.Metadatas where dbMetadata.RelationshipUid == relationshipId select dbMetadata; foreach (var orphanedMetadatum in orphanedMetadata) { dataContext.Metadatas.DeleteOnSubmit(orphanedMetadatum); orphanedMetadataCount++; } } dataContext.SubmitChanges(); foreach (Guid nodeId in orphanedNodes) { var orphanedDbNodes = from dbNode in dataContext.Nodes where dbNode.NodeUid == nodeId select dbNode; foreach (var orphanedNode in orphanedDbNodes) { dataContext.Nodes.DeleteOnSubmit(orphanedNode); orphanedNodesCount++; } } dataContext.SubmitChanges(); foreach (Guid relationshipId in orphanedRelationships) { var orphanedDbRelationships = from dbRelationship in dataContext.Relationships where dbRelationship.RelationshipUid == relationshipId select dbRelationship; foreach (var orphanedRelationship in orphanedDbRelationships) { dataContext.Relationships.DeleteOnSubmit(orphanedRelationship); orphanedRelationshipsCount++; } } dataContext.SubmitChanges(); callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned node/s.", orphanedNodesCount)); callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned relationship/s.", orphanedRelationshipsCount)); callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned metadata/s.", orphanedMetadataCount)); callingCmdlet.WriteVerbose(string.Format("Deleted {0} orphaned descriptor/s.", orphanedDescriptorsCount)); } }
public DeleteResult DeleteNode(Guid domainId, Guid nodeId) { lock (deleteLock) { List<Guid> relationshipIds = new List<Guid>(); List<Guid> deletedDescriptors = new List<Guid>(); DeleteResult result = new DeleteResult() { DeleteSuccessful = false, DeletedId = nodeId }; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var deleteNodes = from nodes in mappingDb.Nodes where nodes.NodeUid == nodeId && nodes.DomainUid == domainId select nodes; //if the node existed it'll be the only one and delete all associated relationships/descriptors and metadatum if (deleteNodes.Count() > 0) { // Delete the descriptors that have the node to be deleted associated with them directly var deleteDescriptors = from descriptors in mappingDb.Descriptors where descriptors.NodeUid == nodeId select descriptors; foreach (var descriptor in deleteDescriptors) { relationshipIds.Add(descriptor.RelationshipUid.Value); deletedDescriptors.Add(descriptor.DescriptorUid); mappingDb.Descriptors.DeleteOnSubmit(descriptor); } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } foreach (Guid relationshipId in relationshipIds) { var deleteRelationships = from relationships in mappingDb.Relationships where relationships.RelationshipUid == relationshipId select relationships; if (deleteRelationships.Count() > 0) { var relationship = deleteRelationships.First(); // Delete the descriptors that dangle off the other side of the relationship just deleted var deleteAltDescriptors = from descriptors2 in mappingDb.Descriptors where descriptors2.RelationshipUid == relationshipId select descriptors2; foreach (var altDescriptor in deleteAltDescriptors) { if (!deletedDescriptors.Contains(altDescriptor.DescriptorUid)) { mappingDb.Descriptors.DeleteOnSubmit(altDescriptor); } } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } // Delete metadata associated with the relationship just deleted var deleteRelationshipMetadatum = from metadatum in mappingDb.Metadatas where metadatum.RelationshipUid == relationshipId select metadatum; foreach (var relationshipMetadatum in deleteRelationshipMetadatum) { mappingDb.Metadatas.DeleteOnSubmit(relationshipMetadatum); } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } mappingDb.Relationships.DeleteOnSubmit(relationship); try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } } } var nodeToDelete = deleteNodes.First(); var deleteNodeMetadatum = from metadatum in mappingDb.Metadatas where metadatum.NodeUid == nodeToDelete.NodeUid select metadatum; foreach (var metadatum in deleteNodeMetadatum) { mappingDb.Metadatas.DeleteOnSubmit(metadatum); } try { mappingDb.SubmitChanges(); } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } // Delete the actual node, it will only be one mappingDb.Nodes.DeleteOnSubmit(nodeToDelete); try { mappingDb.SubmitChanges(); result.DeleteSuccessful = true; } catch (Exception) { //Debug.WriteLine("An exception occurred of type: {0}\r\n{1}", e.Message, e); } } } }); return result; } }
public SoapNode PasteNodeClone(Guid domainId, Guid copiedNodeId) { SoapNode result = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext()) { var domains = from dbDomain in mappingDb.Domains where dbDomain.DomainUid == domainId select dbDomain; Domain domain; if (domains.Count() > 0) { domain = domains.First(); var originalNode = from dbNode in mappingDb.Nodes where dbNode.NodeUid == copiedNodeId && dbNode.DomainUid == domainId select dbNode; if (originalNode.Count() > 0) { var origNode = originalNode.First(); Node node = CreateNode(origNode.NodeTypeUid.Value, origNode.NodeUid.ToString()); node.Metadatas = new EntitySet<Metadata>(); foreach (Metadata metadata in origNode.Metadatas) { if (!(metadata.MetadataName == "XPosition" || metadata.MetadataName == "YPosition")) { Metadata metaCopy = new Metadata(); metaCopy.MetadataId = Guid.NewGuid(); metaCopy.MetadataName = metadata.MetadataName; metaCopy.MetadataType = metadata.MetadataType; metaCopy.MetadataTypeUid = metadata.MetadataTypeUid; metaCopy.MetadataValue = metadata.MetadataValue; metaCopy.NodeUid = node.NodeUid; metaCopy.Node = node; metaCopy.DescriptorTypeUid = metadata.DescriptorTypeUid; metaCopy.RelationshipUid = metadata.RelationshipUid; metaCopy.Relationship = metadata.Relationship; node.Metadatas.Add(metaCopy); } } domain.Nodes.Add(node); mappingDb.SubmitChanges(); SoapNode soapNode = node.ToSoapObject(); result = soapNode; } } } }); return result; }
public void ExecuteCmdletBase(PSCmdlet callingCmdlet) { if (Domain == null) { callingCmdlet.WriteWarning("No valid domain has been provided."); return; } if (!Domain.CheckIsValid()) { callingCmdlet.WriteWarning("An invalid domain object has been provided."); return; } Model.IDatabaseInfo dbInfo = Domain; using (MappingToolDatabaseDataContext dataContext = new MappingToolDatabaseDataContext(dbInfo.ConnectionString)) { dataContext.CommandTimeout = 180; if (MapId != Guid.Empty) { /// Find maps by ID. /// Model.Map map = GetMapById(dataContext, MapId); callingCmdlet.WriteObject(map); } else if (!string.IsNullOrEmpty(MapName)) { /// Find maps by name. /// List<Model.Map> maps = GetMapsByName(dataContext, MapName); callingCmdlet.WriteObject(maps, true); } else { /// Fine all maps. /// List<Model.Map> maps = GetAllMaps(dataContext); callingCmdlet.WriteObject(maps, true); } } }
private static void DeleteMetadata(MetadataContext context, DeleteResult result, MappingToolDatabaseDataContext mappingDb, IQueryable<Metadata> deleteMetadatas) { if (deleteMetadatas.Count() == 1) { Metadata metadata = deleteMetadatas.First(); if (metadata != null) { mappingDb.Metadatas.DeleteOnSubmit(metadata); try { mappingDb.SubmitChanges(); result.DeleteSuccessful = true; result.DeletedId = metadata.MetadataId; LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Verbose, "Deleted metadata with ID: {0} the value was: '{1}'", metadata.MetadataId.ToString(), metadata.MetadataValue); } catch (Exception e) { LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "There was an error deleting the metadata with ID: {0} due to {1}: {2}", metadata.MetadataId.ToString(), e.GetType().ToString(), e.Message); } } } else { LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "There was an error deleting the metadata with the name {0} from the NodeUid: {1}", context.MetadataName, context.NodeUid); } }
public static IEnumerable <Node> ApplyFilters(this GraphQueryFilter[] filters, MappingToolDatabaseDataContext dbContext, IEnumerable <Node> nodes) { IEnumerable <Node> filteredNodes = new List <Node>(); if (filters != null) { foreach (GraphQueryFilter filter in filters) { filteredNodes = filteredNodes.Union(filter.ApplySearchConditions(dbContext, nodes)); } } else { filteredNodes = nodes; //no filters so send back unfiltered } return(filteredNodes); }