Exemple #1
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static CSharpCommonGraph.Edge LoadConnectorsAndAddPortsFromXml(XmlElement connEl, IDictionary <string, CSharpCommonGraph.Node> nodes)
        {
            var helper = new Dynamo.Utilities.XmlElementHelper(connEl);

            var guid       = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart  = helper.ReadGuid("start");
            var guidEnd    = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex   = helper.ReadInteger("end_index");


            //find the elements to connect
            CSharpCommonGraph.Node start;
            if (nodes.TryGetValue(guidStart.ToString(), out start))
            {
                var startport = new CSharpCommonGraph.Port();
                startport.InstanceGuid     = start.InstanceGuid.ToString() + "_OUT" + startIndex.ToString();
                startport.MetaData.Inspect = "start";
                startport.Name             = "a cool port";
                //if we have not seen this port id before add the port, we dont want to duplicate ports
                if (start.Ports.All(x => x.InstanceGuid != startport.InstanceGuid))
                {
                    start.Ports.Add(startport);
                }


                CSharpCommonGraph.Node end;
                if (nodes.TryGetValue(guidEnd.ToString(), out end))
                {
                    var endport = new CSharpCommonGraph.Port();
                    endport.InstanceGuid     = end.InstanceGuid.ToString() + "_IN" + endIndex.ToString();
                    endport.MetaData.Inspect = "end";
                    endport.Name             = "a cool port";
                    if (end.Ports.All(x => x.InstanceGuid != endport.InstanceGuid))
                    {
                        end.Ports.Add(endport);
                    }

                    var edge = new CSharpCommonGraph.Edge();
                    edge.SrcGuid      = startport.InstanceGuid;
                    edge.DestGuid     = endport.InstanceGuid;
                    edge.InstanceGuid = guid.ToString();
                    return(edge);
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        ///     Creates and initializes a ConnectorModel from its Xml representation.
        /// </summary>
        /// <param name="connEl">XmlElement for a ConnectorModel.</param>
        /// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
        /// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
        public static CSharpCommonGraph.Edge LoadConnectorsAndAddPortsFromXml(XmlElement connEl,IDictionary<string, CSharpCommonGraph.Node> nodes)
        {
            var helper = new Dynamo.Utilities.XmlElementHelper(connEl);

            var guid = helper.ReadGuid("guid", Guid.NewGuid());
            var guidStart = helper.ReadGuid("start");
            var guidEnd = helper.ReadGuid("end");
            int startIndex = helper.ReadInteger("start_index");
            int endIndex = helper.ReadInteger("end_index");

             //find the elements to connect
            CSharpCommonGraph.Node start;
            if (nodes.TryGetValue(guidStart.ToString(), out start))
            {
                var startport = new CSharpCommonGraph.Port();
                startport.InstanceGuid = start.InstanceGuid.ToString()+"_OUT"+ startIndex.ToString();
                startport.MetaData.Inspect = "start";
                startport.Name = "a cool port";
                //if we have not seen this port id before add the port, we dont want to duplicate ports
                if (start.Ports.All(x=>x.InstanceGuid != startport.InstanceGuid))
                {
                      start.Ports.Add(startport);
                }

                CSharpCommonGraph.Node end;
                if (nodes.TryGetValue(guidEnd.ToString(), out end))
                {

                    var endport = new CSharpCommonGraph.Port();
                    endport.InstanceGuid = end.InstanceGuid.ToString() + "_IN" + endIndex.ToString();
                    endport.MetaData.Inspect = "end";
                    endport.Name = "a cool port";
                    if (end.Ports.All(x => x.InstanceGuid != endport.InstanceGuid))
                    {
                        end.Ports.Add(endport);
                    }

                    var edge = new CSharpCommonGraph.Edge();
                    edge.SrcGuid = startport.InstanceGuid;
                    edge.DestGuid = endport.InstanceGuid;
                    edge.InstanceGuid = guid.ToString();
                    return edge;
                }
            }

            return null;
        }