Example #1
0
 public MetadataViewModel(MetadataContext context, SoapMetadata metadata)
 {
     if (context == null)
     {
         throw new ArgumentException("The metadata context was null.", "context");
     }
     if (metadata == null)
     {
         throw new ArgumentException("The metadata was null.", "metadata");
     }
     if (context.MetadataName != metadata.MetadataName)
     {
         throw new ArgumentException("The MetadataContext.MetadataName did not match the SoapMetadata.MetadataName, the context was not for this metadata.");
     }
     this._metadataName = context.MetadataName;
     this._originalMetadataName = context.MetadataName;
     if (context.NodeUid.HasValue)
     {
         this._nodeUid = context.NodeUid.Value;
     }
     if (context.RelationshipUid.HasValue)
     {
         this._relationshipUid = context.RelationshipUid.Value;
     }
     if (context.DescriptorTypeUid.HasValue)
     {
         this._descriptorTypeUid = context.DescriptorTypeUid.Value;
     }
     this._metadataTypeUid = metadata.MetadataType.Id;
     this._metadataValue = metadata.MetadataValue;
 }
Example #2
0
 public MetadataViewModel(MetadataContext context, SoapMetadata metadata)
 {
     if (context == null)
     {
         throw new ArgumentException("The metadata context was null.", "context");
     }
     if (metadata == null)
     {
         throw new ArgumentException("The metadata was null.", "metadata");
     }
     if (context.MetadataName != metadata.MetadataName)
     {
         throw new ArgumentException("The MetadataContext.MetadataName did not match the SoapMetadata.MetadataName, the context was not for this metadata.");
     }
     this._metadataName         = context.MetadataName;
     this._originalMetadataName = context.MetadataName;
     if (context.NodeUid.HasValue)
     {
         this._nodeUid = context.NodeUid.Value;
     }
     if (context.RelationshipUid.HasValue)
     {
         this._relationshipUid = context.RelationshipUid.Value;
     }
     if (context.DescriptorTypeUid.HasValue)
     {
         this._descriptorTypeUid = context.DescriptorTypeUid.Value;
     }
     this._metadataTypeUid = metadata.MetadataType.Id;
     this._metadataValue   = metadata.MetadataValue;
 }
        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;
        }
Example #4
0
        private void NodePropertiesDialog_Loaded(object sender, RoutedEventArgs e)
        {
            NodeProxy = DataContext as INodeProxy;
            if (NodeProxy != null)
            {
                _originalName = NodeProxy.Name;
                _originalNote = Note; //make a copy to restore closing
                if (Note != null)
                {
                    NodeNotesTextBlock.Text = Note;
                }
                NodeNotesTextBlock.Focus();
                NodeNotesTextBlock.SelectionStart = NodeNotesTextBlock.Text.Length;

                if (NodeProxy.Created != DateTime.MinValue)
                {
                    CreatedTimeTextBlock.Text = NodeProxy.Created.ToString("f");
                }
                if (NodeProxy.LastModified != DateTime.MinValue)
                {
                    ModifiedTimeTextBlock.Text = NodeProxy.LastModified.ToString("f");
                }


                if (NodeProxy.NodeType.Name == "CompendiumReferenceNode")
                {
                    MetadataContext context = new MetadataContext()
                    {
                        NodeUid      = NodeProxy.Id,
                        MetadataName = "LinkedFile.Source"
                    };
                    if (NodeProxy.HasMetadata(context))
                    {
                        Height = 480;
                        ReferenceLocationRow.Height       = new GridLength(30);
                        ReferenceNodeInfoPanel.Visibility = System.Windows.Visibility.Visible;

                        SoapMetadata linkedFileMetadata = NodeProxy.GetNodeMetadata(context);
                        ReferenceFileLocationTextBox.Text = linkedFileMetadata.MetadataValue;
                    }
                }
            }
        }
        private void AddMetadataDialog_Closed(object sender, EventArgs e)
        {
            EditMetadataDialog dialog = sender as EditMetadataDialog;

            if (dialog != null && dialog.DialogResult.Value == true)
            {
                //only allow a key to go into the properties once
                if (!_changes.ContainsKey(dialog.MetadataName.ToLower()))
                {
                    MetadataContext newContext = new MetadataContext();
                    newContext.MetadataName = dialog.MetadataName;
                    newContext.NodeUid      = NodeProxy.Id;
                    SoapMetadata metadata = new SoapMetadata();
                    metadata.MetadataName = dialog.MetadataName;
                    TypeManager          typeManager   = IoC.IoCContainer.GetInjectionInstance().GetInstance <TypeManager>();
                    IMetadataTypeProxy[] metaDataTypes = typeManager.GetAllMetadataTypes();
                    foreach (IMetadataTypeProxy metadataType in metaDataTypes)
                    {
                        if (metadataType.Id == dialog.MetadataTypeUid)
                        {
                            SoapMetadataType soapMetadataType = new SoapMetadataType();
                            soapMetadataType.Id   = metadataType.Id;
                            soapMetadataType.Name = metadataType.Name;
                            metadata.MetadataType = soapMetadataType;
                            break;
                        }
                    }
                    metadata.MetadataValue = dialog.Value;

                    MetadataViewModel newData = new MetadataViewModel(newContext, metadata);
                    _changes[newData.OriginalMetadataName.ToLower()] = true;
                    _metadata.Add(newData);
                    _metadataNames.Add(newData.MetadataName);
                    newData.PropertyChanged += new PropertyChangedEventHandler(model_PropertyChanged);
                }
                else
                {
                    MessageBox.Show("Metadata could not be added because the property name already existed", "Error Adding Metadata", MessageBoxButton.OK);
                }
            }
        }
        private void OnConnectNodesCompleted(object sender, ConnectNodesCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                List <INodeProxy> nodes = new List <INodeProxy>();

                ConnectedNodesResult connectResult = e.Result;

                foreach (SoapNode soapNode in connectResult.Nodes.Values)
                {
                    if (_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        _cachedNodes.Remove(soapNode.Id);
                    }

                    NodeProxy node = new NodeProxy(soapNode);
                    _cachedNodes.Add(soapNode.Id, node);
                    nodes.Add(node);
                }

                foreach (INodeProxy nodeProxy in nodes)
                {
                    foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors)
                    {
                        CompleteRelationship(descriptorProxy.Relationship);
                    }
                }

                ConnectedNodesEventArgs connectedNodesEventArgs = new ConnectedNodesEventArgs();
                connectedNodesEventArgs.Nodes        = nodes.ToArray();
                connectedNodesEventArgs.Relationship = new RelationshipProxy(e.Result.Relationship);

                CompleteRelationship(connectedNodesEventArgs.Relationship);

                //When a node is connected via a MapContainerRelationship the UserState will be the location of the new node
                //on the map, it can't be stored in the db until the relationship exists since it's the contectual relationship
                //that determines where it is located in it's view in this map (it may be elsewhere in transclusions)
                if (e.UserState != null)
                {
                    INodeProxy nodeProxy = connectedNodesEventArgs.Nodes[1];
                    Point      location  = (Point)e.UserState;
                    if (location != null)
                    {
                        TypeManager          typeManager    = IoC.IoCContainer.GetInjectionInstance().GetInstance <TypeManager>();
                        IDescriptorTypeProxy descriptorType = null;
                        if (e.Result.Relationship.RelationshipType.Name == "TransclusionRelationship")
                        {
                            descriptorType = typeManager.GetDescriptorType("TransclusionMap");
                        }
                        else
                        {
                            descriptorType = typeManager.GetDescriptorType("From");
                        }

                        MetadataContext xPositionKey = new MetadataContext()
                        {
                            NodeUid           = nodeProxy.Id,
                            RelationshipUid   = e.Result.Relationship.Id,
                            DescriptorTypeUid = descriptorType.Id,
                            MetadataName      = "XPosition"
                        };
                        MetadataContext yPositionKey = new MetadataContext()
                        {
                            NodeUid           = nodeProxy.Id,
                            RelationshipUid   = e.Result.Relationship.Id,
                            DescriptorTypeUid = descriptorType.Id,
                            MetadataName      = "YPosition"
                        };

                        if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(xPositionKey) != null)
                        {
                            nodeProxy.GetNodeMetadata(xPositionKey).MetadataValue = location.X.ToString();
                        }
                        else
                        {
                            MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy;
                            if (metaDataTypeProxy != null)
                            {
                                SoapMetadata soapMetadata = new SoapMetadata();
                                soapMetadata.MetadataName  = "XPosition";
                                soapMetadata.MetadataType  = metaDataTypeProxy.BaseSoapNodeType;
                                soapMetadata.MetadataValue = location.X.ToString();
                                nodeProxy.Metadata.Add(xPositionKey, soapMetadata);
                            }
                        }

                        if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(yPositionKey) != null)
                        {
                            nodeProxy.GetNodeMetadata(yPositionKey).MetadataValue = location.Y.ToString();
                        }
                        else
                        {
                            MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy;
                            if (metaDataTypeProxy != null)
                            {
                                SoapMetadata soapMetadata = new SoapMetadata();
                                soapMetadata.MetadataName  = "YPosition";
                                soapMetadata.MetadataType  = metaDataTypeProxy.BaseSoapNodeType;
                                soapMetadata.MetadataValue = location.Y.ToString();
                                nodeProxy.Metadata.Add(yPositionKey, soapMetadata);
                            }
                        }
                    }
                }

                if (ConnectNodesCompleted != null)
                {
                    ConnectNodesCompleted.Invoke(this, connectedNodesEventArgs);
                }
            }
        }
        private void AddMetadataDialog_Closed(object sender, EventArgs e)
        {
            EditMetadataDialog dialog = sender as EditMetadataDialog;
            if (dialog != null && dialog.DialogResult.Value == true)
            {
                //only allow a key to go into the properties once
                if (!_changes.ContainsKey(dialog.MetadataName.ToLower()))
                {
                    MetadataContext newContext = new MetadataContext();
                    newContext.MetadataName = dialog.MetadataName;
                    newContext.NodeUid = NodeProxy.Id;
                    SoapMetadata metadata = new SoapMetadata();
                    metadata.MetadataName = dialog.MetadataName;
                    TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>();
                    IMetadataTypeProxy[] metaDataTypes = typeManager.GetAllMetadataTypes();
                    foreach (IMetadataTypeProxy metadataType in metaDataTypes)
                    {
                        if (metadataType.Id == dialog.MetadataTypeUid)
                        {
                            SoapMetadataType soapMetadataType = new SoapMetadataType();
                            soapMetadataType.Id = metadataType.Id;
                            soapMetadataType.Name = metadataType.Name;
                            metadata.MetadataType = soapMetadataType;
                            break;
                        }
                    }
                    metadata.MetadataValue = dialog.Value;

                    MetadataViewModel newData = new MetadataViewModel(newContext, metadata);
                    _changes[newData.OriginalMetadataName.ToLower()] = true;
                    _metadata.Add(newData);
                    _metadataNames.Add(newData.MetadataName);
                    newData.PropertyChanged += new PropertyChangedEventHandler(model_PropertyChanged);
                }
                else
                {
                    MessageBox.Show("Metadata could not be added because the property name already existed", "Error Adding Metadata", MessageBoxButton.OK);
                }
            }
        }
        public static SoapRelationship ToSoapObject(this Relationship relationship)
        {
            if (relationship != null)
            {
                SoapRelationship soapRelationship = new SoapRelationship();

                soapRelationship.Id = relationship.RelationshipUid;

                if (relationship.RelationshipTypeUid == null || !relationship.RelationshipTypeUid.HasValue)
                {
                    throw new NullReferenceException("There is no Relationship Type for this relationship.");
                }

                soapRelationship.RelationshipType = (SoapRelationshipType)SoapTypeFactory.GetSoapType<SoapRelationshipType>(relationship.RelationshipTypeUid.Value);

                soapRelationship.Relationship = relationship;

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

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

                foreach (var descriptor in relationship.Descriptors)
                {
                    SoapDescriptorType soapDescriptor = (SoapDescriptorType)SoapTypeFactory.GetSoapType<SoapDescriptorType>(descriptor.DescriptorTypeUid.Value);

                    soapRelationship.Nodes.Add(soapDescriptor, descriptor.NodeUid.Value);
                }

                return soapRelationship;
            }
            return null;
        }
        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;
        }
        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;
        }
        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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private void OnConnectNodesCompleted(object sender, ConnectNodesCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                List<INodeProxy> nodes = new List<INodeProxy>();

                ConnectedNodesResult connectResult = e.Result;

                foreach (SoapNode soapNode in connectResult.Nodes.Values)
                {
                    if (_cachedNodes.ContainsKey(soapNode.Id))
                    {
                        _cachedNodes.Remove(soapNode.Id);
                    }

                    NodeProxy node = new NodeProxy(soapNode);
                    _cachedNodes.Add(soapNode.Id, node);
                    nodes.Add(node);
                }

                foreach (INodeProxy nodeProxy in nodes)
                {
                    foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors)
                    {
                        CompleteRelationship(descriptorProxy.Relationship);
                    }
                }

                ConnectedNodesEventArgs connectedNodesEventArgs = new ConnectedNodesEventArgs();
                connectedNodesEventArgs.Nodes = nodes.ToArray();
                connectedNodesEventArgs.Relationship = new RelationshipProxy(e.Result.Relationship);

                CompleteRelationship(connectedNodesEventArgs.Relationship);

                //When a node is connected via a MapContainerRelationship the UserState will be the location of the new node
                //on the map, it can't be stored in the db until the relationship exists since it's the contectual relationship
                //that determines where it is located in it's view in this map (it may be elsewhere in transclusions)
                if (e.UserState != null)
                {
                    INodeProxy nodeProxy = connectedNodesEventArgs.Nodes[1];
                    Point location = (Point)e.UserState;
                    if (location != null)
                    {
                        TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>();
                        IDescriptorTypeProxy descriptorType = null;
                        if (e.Result.Relationship.RelationshipType.Name == "TransclusionRelationship")
                        {
                            descriptorType = typeManager.GetDescriptorType("TransclusionMap");
                        }
                        else
                        {
                            descriptorType = typeManager.GetDescriptorType("From");
                        }
                        
                        MetadataContext xPositionKey = new MetadataContext()
                        {
                            NodeUid = nodeProxy.Id,
                            RelationshipUid = e.Result.Relationship.Id,
                            DescriptorTypeUid = descriptorType.Id,
                            MetadataName = "XPosition"
                        };
                        MetadataContext yPositionKey = new MetadataContext()
                        {
                            NodeUid = nodeProxy.Id,
                            RelationshipUid = e.Result.Relationship.Id,
                            DescriptorTypeUid = descriptorType.Id,
                            MetadataName = "YPosition"
                        };

                        if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(xPositionKey) != null)
                        {
                            nodeProxy.GetNodeMetadata(xPositionKey).MetadataValue = location.X.ToString();
                        }
                        else
                        {
                            MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy;
                            if (metaDataTypeProxy != null)
                            {
                                SoapMetadata soapMetadata = new SoapMetadata();
                                soapMetadata.MetadataName = "XPosition";
                                soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType;
                                soapMetadata.MetadataValue = location.X.ToString();
                                nodeProxy.Metadata.Add(xPositionKey, soapMetadata);
                            }
                        }

                        if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(yPositionKey) != null)
                        {
                            nodeProxy.GetNodeMetadata(yPositionKey).MetadataValue = location.Y.ToString();
                        }
                        else
                        {
                            MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy;
                            if (metaDataTypeProxy != null)
                            {
                                SoapMetadata soapMetadata = new SoapMetadata();
                                soapMetadata.MetadataName = "YPosition";
                                soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType;
                                soapMetadata.MetadataValue = location.Y.ToString();
                                nodeProxy.Metadata.Add(yPositionKey, soapMetadata);
                            }
                        }
                    }
                }

                if (ConnectNodesCompleted != null)
                {
                    ConnectNodesCompleted.Invoke(this, connectedNodesEventArgs);
                }
            }
        }
Example #13
0
        public SoapMetadata GetNodeMetadata(MetadataContext key)
        {
            SoapMetadata metadata = null;

            if (HasMetadata(key))
            {
                foreach (MetadataContext contextKey in Metadata.Keys)
                {
                    if (contextKey.MetadataName == key.MetadataName)
                    {
                        if (!key.NodeUid.HasValue && !key.RelationshipUid.HasValue && !key.DescriptorTypeUid.HasValue)
                        {
                            metadata = Metadata[contextKey];
                            break;
                        }
                        if (key.NodeUid.HasValue && key.RelationshipUid.HasValue && key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.NodeUid.Value == key.NodeUid.Value && contextKey.RelationshipUid.Value == key.RelationshipUid.Value &&
                                contextKey.DescriptorTypeUid.Value == key.DescriptorTypeUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (!key.NodeUid.HasValue && key.RelationshipUid.HasValue && key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.RelationshipUid.Value == key.RelationshipUid.Value &&
                                contextKey.DescriptorTypeUid.Value == key.DescriptorTypeUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (key.NodeUid.HasValue && !key.RelationshipUid.HasValue && key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.NodeUid.Value == key.NodeUid.Value &&
                                contextKey.DescriptorTypeUid.Value == key.DescriptorTypeUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (key.NodeUid.HasValue && key.RelationshipUid.HasValue && !key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.NodeUid.Value == key.NodeUid.Value &&
                                contextKey.RelationshipUid.Value == key.RelationshipUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (key.NodeUid.HasValue && !key.RelationshipUid.HasValue && !key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.NodeUid.Value == key.NodeUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (!key.NodeUid.HasValue && key.RelationshipUid.HasValue && !key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.RelationshipUid.Value == key.RelationshipUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                        else if (!key.NodeUid.HasValue && !key.RelationshipUid.HasValue && key.DescriptorTypeUid.HasValue)
                        {
                            if (contextKey.DescriptorTypeUid.Value == key.DescriptorTypeUid.Value)
                            {
                                metadata = Metadata[contextKey];
                                break;
                            }
                        }
                    }
                }
            }

            return(metadata);
        }