Пример #1
0
        public virtual void WriteXml(XmlWriter writer)
        {
            try
            {
                writer.WriteAttributeString("Type", GetType().AssemblyQualifiedName);
                writer.WriteAttributeString("Guid", Guid.ToString());
                writer.WriteAttributeString("StateCount", Store.Count.ToString());
                writer.WriteAttributeString("InputCount", InputNodes.Count.ToString());
                writer.WriteAttributeString("OutputCount", OutputNodes.Count.ToString());
                writer.WriteAttributeString("ParameterCount", ParameterCount.ToString());

                if (InputNodes.Count > 0)
                {
                    writer.WriteStartElement("InputNodes");
                    foreach (var inputNode in InputNodes)
                    {
                        InputNode item = inputNode as InputNode;
                        var       ext  = string.Join(",", item.GetSupportedExtensions());

                        writer.WriteStartElement("InputNode");

                        writer.WriteAttributeString("Identifier", item.Identity.ToString());
                        writer.WriteAttributeString("DisplayName", item.DisplayName);
                        writer.WriteAttributeString("Extension", ext);

                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
                if (OutputNodes.Count > 0)
                {
                    writer.WriteStartElement("OutputNodes");

                    foreach (var item in OutputNodes)
                    {
                        var ext = string.Join(",", item.GetSupportedExtensions());

                        writer.WriteStartElement("OutputNode");

                        writer.WriteAttributeString("Identifier", item.Identity.ToString());
                        writer.WriteAttributeString("DisplayName", item.DisplayName);
                        writer.WriteAttributeString("Extension", ext);

                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }


                if (Store.Count > 0)
                {
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <Guid, ModuleState>));
                    keySerializer.Serialize(writer, Store);
                }

                if (StateInfo.Count > 0)
                {
                    writer.WriteStartElement("StateInfo");
                    writer.WriteAttributeString("Count", StateInfo.Count.ToString());
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <string, string>));
                    keySerializer.Serialize(writer, StateInfo);
                    writer.WriteEndElement();
                }

                WriteParameter(writer);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Пример #2
0
        public virtual void ReadXml(XmlReader reader)
        {
            if (!reader.IsStartElement("BaseModule"))
            {
                logger.Error("Cannot load base module as <BaseModule> is missing from xml");
                throw new XmlException("Cannot load base module as <BaseModule> is missing from xml");
            }

            XElement bmnode = XElement.ReadFrom(reader) as XElement;


            int attrCount = reader.AttributeCount;

            _Guid = Guid.Parse(bmnode.Attribute("Guid").Value);
            var inputCount  = Int32.Parse(bmnode.Attribute("InputCount").Value);
            var outputCount = Int32.Parse(bmnode.Attribute("OutputCount").Value);
            var stateCount  = Int32.Parse(bmnode.Attribute("StateCount").Value);


            var attrib = bmnode.Attribute("ParameterCount");

            if (attrib != null)
            {
                this.ParameterCount = Int32.Parse(attrib.Value);
            }



            if (stateCount > 0)
            {
                var dict = bmnode.XPathSelectElement("dictionary");
                if (dict != null)
                {
                    var           dictReader    = dict.CreateReader();
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <Guid, ModuleState>));
                    Store = (SerializableDictionary <Guid, ModuleState>)keySerializer.Deserialize(dictReader);
                }
            }

            var stateInfo = bmnode.XPathSelectElement("StateInfo");

            if (stateInfo != null)
            {
                var dict = stateInfo.XPathSelectElement("dictionary");
                if (dict != null)
                {
                    var           dictReader    = dict.CreateReader();
                    XmlSerializer keySerializer = new XmlSerializer(typeof(SerializableDictionary <string, string>));
                    StateInfo = (SerializableDictionary <string, string>)keySerializer.Deserialize(dictReader);
                }
            }

            InputNodes.Clear();
            foreach (var ioNode in bmnode.XPathSelectElements("//InputNodes/InputNode"))
            {
                var identifier  = Guid.Parse(ioNode.Attribute("Identifier").Value);
                var displayName = ioNode.Attribute("DisplayName").Value;
                var ext         = ioNode.Attribute("Extension").Value;

                var moduleNode = new InputNode(this, this.DisplayName, ext);
                moduleNode.Identity = identifier;

                if (Store.ContainsKey(identifier))
                {
                    moduleNode.State = Store[identifier];
                }
                else
                {
                    moduleNode.State = new ModuleState();
                }

                AddInputNode(moduleNode);
            }

            OutputNodes.Clear();
            foreach (var ioNode in bmnode.XPathSelectElements("//OutputNodes/OutputNode"))
            {
                var identifier  = Guid.Parse(ioNode.Attribute("Identifier").Value);
                var displayName = ioNode.Attribute("DisplayName").Value;
                var ext         = ioNode.Attribute("Extension").Value;

                var moduleNode = new OutputNode(this, this.DisplayName, ext);
                moduleNode.Identity = identifier;

                if (Store.ContainsKey(identifier))
                {
                    moduleNode.State = Store[identifier];
                }
                else
                {
                    moduleNode.State = new ModuleState();
                }
                AddOutputNode(moduleNode);
            }

            ReadParameter(bmnode);
        }