Ejemplo n.º 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 ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary <Guid, NodeModel> nodes)
        {
            var helper = new 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");
            bool isHidden   = helper.HasAttribute(nameof(ConnectorModel.IsHidden)) ?
                              helper.ReadBoolean(nameof(ConnectorModel.IsHidden)) :
                              false;

            //find the elements to connect
            NodeModel start;

            if (nodes.TryGetValue(guidStart, out start))
            {
                NodeModel end;
                if (nodes.TryGetValue(guidEnd, out end))
                {
                    var connector = ConnectorModel.Make(start, end, startIndex, endIndex, guid);
                    if (connector != null)
                    {
                        connector.IsHidden = isHidden;
                        return(connector);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
            protected static IEnumerable<Guid> DeserializeGuid(XmlElement element, XmlElementHelper helper)
            {
                // Deserialize old type of commands
                if (helper.HasAttribute("ModelGuid"))
                {
                    Guid modelGuid = helper.ReadGuid("ModelGuid", Guid.Empty);
                    return new[] { modelGuid };
                }

                if (helper.HasAttribute("NodeId"))
                {
                    Guid modelGuid = helper.ReadGuid("NodeId", Guid.Empty);
                    return new[] { modelGuid };
                }

                return (from XmlNode xmlNode in element.ChildNodes
                        where xmlNode.Name.Equals("ModelGuid")
                        select Guid.Parse(xmlNode.InnerText)).ToArray();
            }