Esempio n. 1
0
        private void AppendFields(ThingReference ThingReference, List <Field> Fields, ISensorReadout Request, XmlElement Value, string Prefix)
        {
            foreach (XmlAttribute Attribute in Value.Attributes)
            {
                if (string.IsNullOrEmpty(Prefix))
                {
                    this.Add(ThingReference, Fields, Attribute.Name, Attribute.Value, Request);
                }
                else
                {
                    this.Add(ThingReference, Fields, this.Append(Prefix, Attribute.Name), Attribute.Value, Request);
                }
            }

            Dictionary <string, int> Repetitions = null;
            string s;

            foreach (XmlNode N in Value)
            {
                if (N is XmlElement ChildElement)
                {
                    s = ChildElement.LocalName;

                    if (Repetitions == null)
                    {
                        Repetitions = new Dictionary <string, int>();
                    }

                    if (Repetitions.TryGetValue(s, out int i))
                    {
                        Repetitions[s] = i - 1;
                    }
                    else
                    {
                        Repetitions[s] = 0;
                    }
                }
            }

            foreach (XmlNode N in Value)
            {
                if (N is XmlElement ChildElement)
                {
                    s = ChildElement.LocalName;

                    if (Repetitions.TryGetValue(s, out int i))
                    {
                        if (i < 0)
                        {
                            Repetitions[s] = i = 1;
                        }
                        else if (i > 0)
                        {
                            Repetitions[s] = ++i;
                        }

                        if (i != 0)
                        {
                            s += ", #" + i.ToString();
                        }
                    }

                    if (string.IsNullOrEmpty(Prefix))
                    {
                        this.AppendFields(ThingReference, Fields, Request, ChildElement, s);
                    }
                    else
                    {
                        this.AppendFields(ThingReference, Fields, Request, ChildElement, Prefix + ", " + s);
                    }
                }
                else if (N is XmlText XmlText)
                {
                    if (string.IsNullOrEmpty(Prefix))
                    {
                        this.Add(ThingReference, Fields, "Value", XmlText.InnerText, Request);
                    }
                    else
                    {
                        this.Add(ThingReference, Fields, Prefix, XmlText.InnerText, Request);
                    }
                }
            }
        }