예제 #1
0
        public static SoapNode ToSoapObject(this Node node)
        {
            SoapNode soapNode = new SoapNode();

            if (node.DomainUid == null || !node.DomainUid.HasValue)
            {
                throw new NullReferenceException("There is no Domain ID for this node.");
            }

            soapNode.Domain = node.DomainUid.Value;
            soapNode.Id     = node.NodeUid;

            if (node.NodeTypeUid == null || !node.NodeTypeUid.HasValue)
            {
                throw new NullReferenceException("There is no Node Type for this node.");
            }

            soapNode.NodeType = (SoapNodeType)SoapTypeFactory.GetSoapType <SoapNodeType>(node.NodeTypeUid.Value);
            soapNode.Node     = node;

            var allMetadata = node.Metadatas.OrderBy(x => (x.RelationshipUid != null) ? x.RelationshipUid : Guid.Empty).OrderBy(x => (x.DescriptorTypeUid != null) ? x.DescriptorTypeUid : Guid.Empty);

            foreach (var datum in allMetadata)
            {
                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[key] = soapDatum;
            }

            foreach (Descriptor localDescriptor in node.Descriptors)
            {
                SoapRelationship relationship = localDescriptor.Relationship.ToSoapObject();

                if (relationship != null && !soapNode.Relationships.ContainsKey(relationship.Id))
                {
                    soapNode.Relationships.Add(relationship.Id, relationship);
                }
            }

            return(soapNode);
        }
        public static SoapNode ToSoapObject(this Node node)
        {
            SoapNode soapNode = new SoapNode();

            if (node.DomainUid == null || !node.DomainUid.HasValue)
            {
                throw new NullReferenceException("There is no Domain ID for this node.");
            }

            soapNode.Domain = node.DomainUid.Value;
            soapNode.Id = node.NodeUid;

            if (node.NodeTypeUid == null || !node.NodeTypeUid.HasValue)
            {
                throw new NullReferenceException("There is no Node Type for this node.");
            }

            soapNode.NodeType = (SoapNodeType)SoapTypeFactory.GetSoapType<SoapNodeType>(node.NodeTypeUid.Value);
            soapNode.Node = node;

            var allMetadata = node.Metadatas.OrderBy(x => (x.RelationshipUid != null) ? x.RelationshipUid : Guid.Empty).OrderBy(x => (x.DescriptorTypeUid != null) ? x.DescriptorTypeUid : Guid.Empty);

            foreach (var datum in allMetadata)
            {
                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[key] = soapDatum;
            }

            foreach (Descriptor localDescriptor in node.Descriptors)
            {
                SoapRelationship relationship = localDescriptor.Relationship.ToSoapObject();

                if (relationship != null && !soapNode.Relationships.ContainsKey(relationship.Id))
                {
                    soapNode.Relationships.Add(relationship.Id, relationship);
                }
            }

            return soapNode;
        }
예제 #3
0
        public static IEnumerable <SoapNode> ToSoapObject(this IEnumerable <Node> nodes)
        {
            List <SoapNode> soapNodes = new List <SoapNode>();

            foreach (Node node in nodes)
            {
                SoapNode soapNode = node.ToSoapObject();

                soapNodes.Add(soapNode);
            }

            return(soapNodes);
        }
예제 #4
0
        public RelatedNodesSearchResult(Guid nodeId, IEnumerable <Node> nodes)
        {
            Nodes = new Dictionary <Guid, SoapNode>();

            foreach (Node relatedNode in nodes)
            {
                SoapNode soapNode = relatedNode.ToSoapObject();

                if (soapNode.NodeType.Name != "DomainNode")
                {
                    Nodes.Add(soapNode.Id, soapNode);
                }
            }
        }
예제 #5
0
        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;
        }
예제 #6
0
        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;
        }
예제 #7
0
 /// <summary>
 /// Tests for the existence of the metadata key name in all the metadata for a node. This is useful to work out if a node has any coordinates stored in the metadata for the context it is in.
 /// </summary>
 /// <param name="soapNode">The SoapNode to check</param>
 /// <param name="keyName">The metadata key name</param>
 /// <returns>True if in the current context of the node it has the metadata</returns>
 private bool ContainsMetadataKeyName(SoapNode soapNode, string keyName)
 {
     bool result = false;
     if (soapNode != null && soapNode.Metadata != null)
     {
         foreach (MetadataContext mdc in soapNode.Metadata.Keys)
         {
             if (mdc.MetadataName == keyName)
             {
                 result = true;
                 break;
             }
         }
     }
     return result;
 }
예제 #8
0
        private void RecurseThroughLevels(Dictionary<Guid, SoapNode> nodes, Guid domainId, Node currentNode, Node initialSearchNode, int depth, List<Condition> conditions)
        {
            SoapNode currentSoapNode;

            if (!nodes.ContainsKey(currentNode.NodeUid))
            {
                currentSoapNode = new SoapNode();
                currentSoapNode.Id = currentNode.NodeUid;
                currentSoapNode.Domain = domainId;

                if (!currentNode.NodeTypeUid.HasValue)
                {
                    throw new NotSupportedException("The node doesn't have a type ID.");
                }

                currentSoapNode.NodeType = (SoapNodeType)SoapTypeFactory.GetSoapType<SoapNodeType>(currentNode.NodeTypeUid.Value);

                if (currentSoapNode.NodeType.Name != "DomainNode")
                {
                    /// Get the metadata for the child node according to the current context.
                    var currentNodeMetadata = from dbDatum in currentNode.Metadatas select dbDatum;

                    foreach (var datum in currentNodeMetadata.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);
                        }

                        currentSoapNode.Metadata[key] = soapDatum;
                    }
                    /// End getting metadata.

                    //let the conditions determine if the node is added or not.
                    if (conditions == null)
                    {
                        nodes.Add(currentSoapNode.Id, currentSoapNode);
                    }
                }
            }
            else
            {
                currentSoapNode = nodes[currentNode.NodeUid];
            }

            foreach (var originatingDescriptor in currentNode.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);
                }

                SoapDescriptorType soapOriginatingDescriptorType = (SoapDescriptorType)SoapTypeFactory.GetSoapType<SoapDescriptorType>(originatingDescriptor.DescriptorTypeUid.Value);
                soapRelationship.Nodes.Add(soapOriginatingDescriptorType, currentNode.NodeUid);

                if (!currentSoapNode.Relationships.ContainsKey(soapRelationship.Id))
                {
                    currentSoapNode.Relationships.Add(soapRelationship.Id, soapRelationship);
                }

                foreach (var destinationDescriptor in relationship.Descriptors)
                {
                    if (destinationDescriptor.DescriptorUid == originatingDescriptor.DescriptorUid)
                    {
                        continue; //original end of the relationship
                    }

                    if (nodes.ContainsKey(destinationDescriptor.Node.NodeUid))
                    {
                        continue; //already know about this node
                    }

                    Node childNode = destinationDescriptor.Node;

                    /// Connect the parent node to the relationships.
                    if (!destinationDescriptor.DescriptorTypeUid.HasValue)
                    {
                        throw new NotSupportedException("The descriptor doesn't have a type ID.");
                    }

                    SoapDescriptorType soapDestinationDescriptorType = (SoapDescriptorType)SoapTypeFactory.GetSoapType<SoapDescriptorType>(destinationDescriptor.DescriptorTypeUid.Value);
                    soapRelationship.Nodes.Add(soapDestinationDescriptorType, childNode.NodeUid);

                    SoapNode soapNode = new SoapNode();
                    soapNode.Id = childNode.NodeUid;
                    soapNode.Domain = domainId;

                    if (!soapNode.Relationships.ContainsKey(soapRelationship.Id))
                    {
                        soapNode.Relationships.Add(soapRelationship.Id, soapRelationship);
                    }

                    if (!childNode.NodeTypeUid.HasValue)
                    {
                        throw new NotSupportedException("The node doesn't have a type ID.");
                    }

                    soapNode.NodeType = (SoapNodeType)SoapTypeFactory.GetSoapType<SoapNodeType>(childNode.NodeTypeUid.Value);

                    /// Get the metadata for the child or parent node according to the current context.
                    /// 

                    var metadata = from dbDatum in childNode.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[key] = soapDatum;
                    }

                    /// End getting metadata.
                    /// 

                    if (depth >= 0 && conditions == null)
                    {
                        // Add the child or parent node to the collection
                        nodes.Add(destinationDescriptor.Node.NodeUid, soapNode);

                        if (depth > 0) //don't recurse any further
                        {
                            int nextDepthLevel = depth - 1;

                            RecurseThroughLevels(nodes, domainId, destinationDescriptor.Node, initialSearchNode, nextDepthLevel, conditions);
                        }
                    }
                    else if (conditions != null)
                    {
                        //Map equality test code for debugging - doesn't work correctly
                        //MapEqualityMatch mapMatch = new MapEqualityMatch();
                        //mapMatch.Evaluate(initialSearchNode, destinationDescriptor.Node, destinationDescriptor.Relationship, destinationDescriptor);
                        bool nodeAlreadyAdded = false;
                        bool nodeExcludedAlready = false;
                        if (!evaluatedNodes.Contains(destinationDescriptor.Node.NodeUid.ToString()))
                        {
                            foreach (Condition conditionRule in conditions)
                            {
                                //no need to evaluate already excluded nodes against any conditions
                                if (!excludedNodes.Contains(destinationDescriptor.Node.NodeUid.ToString()))
                                {
                                    ConditionResult conditionResult = conditionRule.Evaluate(initialSearchNode, destinationDescriptor.Node, destinationDescriptor.Relationship, destinationDescriptor);
                                    if (!evaluatedNodes.Contains(destinationDescriptor.Node.NodeUid.ToString()))
                                    {
                                        evaluatedNodes.Add(destinationDescriptor.Node.NodeUid.ToString());
                                    }
                                    if (conditionResult.Value)
                                    {
                                        if (!conditionResult.IncludeNode)
                                        {
                                            //if the node isn't to be included and the rule matches remove it
                                            excludedNodes.Add(destinationDescriptor.Node.NodeUid.ToString());
                                            nodeExcludedAlready = true;
                                            if (nodeAlreadyAdded)
                                            {
                                                nodes.Remove(destinationDescriptor.Node.NodeUid);
                                            }
                                        }
                                        if (conditionResult.IncludeNode && !nodeAlreadyAdded && !nodeExcludedAlready && soapNode.NodeType.Name != "DomainNode")
                                        {
                                            //if the node is to be included, hasn't matched an exclusion rule and isn't the domain node add it
                                            nodes.Add(destinationDescriptor.Node.NodeUid, soapNode);
                                            nodeAlreadyAdded = true;
                                        }
                                        if (conditionResult.Action == Action.Continue)
                                        {
                                            //keep looking through the related nodes
                                            RecurseThroughLevels(nodes, domainId, destinationDescriptor.Node, initialSearchNode, -1, conditions);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }