Ejemplo n.º 1
0
        internal static ComponentStream FromXml(XNamespace ns, XElement element)
        {
            var cs = new ComponentStream();

            var attr = element.Attribute("component");

            if (attr != null)
            {
                cs.ComponentType = attr.Value;
            }

            attr = element.Attribute("name");
            if (attr != null)
            {
                cs.Name = attr.Value;
            }

            attr = element.Attribute("nativeName");
            if (attr != null)
            {
                cs.NativeName = attr.Value;
            }

            attr = element.Attribute("componentId");
            if (attr != null)
            {
                cs.ID = attr.Value;
            }

            attr = element.Attribute("uuid");
            if (attr != null)
            {
                cs.UUID = attr.Value;
            }

            // <samples>
            var samples        = new List <IDataElement>();
            var samplesElement = element.Element(ns + "Samples");

            if (samplesElement != null)
            {
                foreach (var s in samplesElement.Elements())
                {
                    samples.Add(DataElementFactory.SampleFromXml(ns, s));
                }
            }
            cs.m_elements.AddRange(samples);

            // <events>
            var events        = new List <IDataElement>();
            var eventsElement = element.Element(ns + "Events");

            if (eventsElement != null)
            {
                foreach (var s in eventsElement.Elements())
                {
                    events.Add(DataElementFactory.EventFromXml(ns, s));
                }
            }
            cs.m_elements.AddRange(events);

            // <condition>
            var conditions = new List <IDataElement>();

            foreach (var ce in element.Elements(ns + "Condition"))
            {
                foreach (var c in ce.Elements())
                {
                    conditions.Add(DataElementFactory.ConditionFromXml(ns, c));
                }
            }
            cs.m_elements.AddRange(conditions);

            return(cs);
        }
Ejemplo n.º 2
0
        internal static DeviceStream FromXml(XNamespace ns, XElement element)
        {
            var ds = new DeviceStream();

            var attr = element.Attribute("name");

            if (attr == null)
            {
                throw new Exception("Device Stream missing 'name' attribute");
            }
            ds.Name = attr.Value;

            attr = element.Attribute("uuid");
            if (attr == null)
            {
                throw new Exception("Device Stream missing 'uuid' attribute");
            }
            ds.UUID = attr.Value;

            // <samples>
            var samples        = new List <IDataElement>();
            var samplesElement = element.Element(ns + "Samples");

            if (samplesElement != null)
            {
                foreach (var s in samplesElement.Elements())
                {
                    samples.Add(DataElementFactory.SampleFromXml(ns, s));
                }
            }
            ds.m_elements.AddRange(samples);

            // <events>
            var events        = new List <IDataElement>();
            var eventsElement = element.Element(ns + "Events");

            if (eventsElement != null)
            {
                foreach (var s in eventsElement.Elements())
                {
                    events.Add(DataElementFactory.EventFromXml(ns, s));
                }
            }
            ds.m_elements.AddRange(events);

            // <condition>
            var conditions = new List <IDataElement>();

            foreach (var ce in element.Elements(ns + "Condition"))
            {
                foreach (var c in ce.Elements())
                {
                    conditions.Add(DataElementFactory.ConditionFromXml(ns, c));
                }
            }
            ds.m_elements.AddRange(conditions);

            List <ComponentStream> streams = new List <ComponentStream>();

            foreach (var componentStream in element.Elements(ns + "ComponentStream"))
            {
                streams.Add(ComponentStream.FromXml(ns, componentStream));
            }

            ds.ComponentStreams = streams.ToArray();

            return(ds);
        }