Ejemplo n.º 1
0
        void PopulateForEachXmlElement(XmlNodeList children, IDictionary <string, int> indexCache)
        {
            foreach (XmlNode c in children)
            {
                var hasCorrectIoDirection      = true;
                var columnIoDirectionAttribute = c.Attributes?["ColumnIODirection"];
                if (columnIoDirectionAttribute != null)
                {
                    var columnIoDirectionValue             = columnIoDirectionAttribute.Value;
                    var hasCorrectIoDirectionFromAttribute = columnIoDirectionValue == enDev2ColumnArgumentDirection.Output.ToString() || columnIoDirectionValue == enDev2ColumnArgumentDirection.Both.ToString();
                    hasCorrectIoDirection = hasCorrectIoDirectionFromAttribute;
                }

                if (DataListUtil.IsSystemTag(c.Name) && !hasCorrectIoDirection)
                {
                    continue;
                }
                var recSet        = RecordSets.FirstOrDefault(set => set.Name == c.Name);
                var shapeRecSet   = ShapeRecordSets.FirstOrDefault(set => set.Name == c.Name);
                var scalar        = Scalars.FirstOrDefault(scalar1 => scalar1.Name == c.Name);
                var complexObject = ComplexObjects.FirstOrDefault(o => o.Name == "@" + c.Name);
                if (complexObject != null)
                {
                    SetComplexObjectValue(c, complexObject);
                }
                else
                {
                    SetScalarOrEcordsetValue(indexCache, c, recSet, shapeRecSet, scalar);
                }
            }
        }
Ejemplo n.º 2
0
        public void PopulateWithData(string data)
        {
            var         toLoad = data;
            XmlDocument xDoc   = new XmlDocument();

            try
            {
                xDoc.LoadXml(toLoad);
            }
            catch
            {
                // Append new root tags ;)
                toLoad = "<root>" + toLoad + "</root>";
                xDoc.LoadXml(toLoad);
            }

            if (!String.IsNullOrEmpty(toLoad))
            {
                if (xDoc.DocumentElement != null)
                {
                    XmlNodeList children = xDoc.DocumentElement.ChildNodes;

                    IDictionary <string, int> indexCache = new Dictionary <string, int>();

                    // spin through each element in the XML
                    foreach (XmlNode c in children)
                    {
                        var hasCorrectIoDirection      = true;
                        var columnIoDirectionAttribute = c.Attributes?["ColumnIODirection"];
                        if (columnIoDirectionAttribute != null)
                        {
                            var columnIoDirectionValue             = columnIoDirectionAttribute.Value;
                            var hasCorrectIoDirectionFromAttribute = columnIoDirectionValue == enDev2ColumnArgumentDirection.Output.ToString() || columnIoDirectionValue == enDev2ColumnArgumentDirection.Both.ToString();
                            hasCorrectIoDirection = hasCorrectIoDirectionFromAttribute;
                        }

                        if (DataListUtil.IsSystemTag(c.Name) && !hasCorrectIoDirection)
                        {
                            continue;
                        }
                        var recSet        = RecordSets.FirstOrDefault(set => set.Name == c.Name);
                        var shapeRecSet   = ShapeRecordSets.FirstOrDefault(set => set.Name == c.Name);
                        var scalar        = Scalars.FirstOrDefault(scalar1 => scalar1.Name == c.Name);
                        var complexObject = ComplexObjects.FirstOrDefault(o => o.Name == "@" + c.Name);
                        if (complexObject != null)
                        {
                            if (!string.IsNullOrEmpty(c.OuterXml))
                            {
                                var jsonData = JsonConvert.SerializeXNode(XDocument.Parse(c.OuterXml), Newtonsoft.Json.Formatting.None, true);
                                var obj      = JsonConvert.DeserializeObject(jsonData.Replace("@", "")) as JObject;
                                if (obj != null)
                                {
                                    var value = obj.ToString();
                                    complexObject.Value = value;
                                }
                            }
                        }
                        else
                        {
                            if (recSet != null && shapeRecSet != null)
                            {
                                // fetch recordset index
                                int fetchIdx;
                                int idx = indexCache.TryGetValue(c.Name, out fetchIdx) ? fetchIdx : 1; // recset index
                                // process recordset
                                var         scalars          = shapeRecSet.Columns[1];
                                var         colToIoDirection = scalars.ToDictionary(scalar1 => scalar1.Name, scalar1 => scalar1.IODirection);
                                XmlNodeList nl = c.ChildNodes;
                                if (!recSet.Columns.ContainsKey(idx))
                                {
                                    recSet.Columns.Add(idx, new List <IScalar>());
                                }
                                else
                                {
                                    recSet.Columns[idx] = new List <IScalar>();
                                }
                                foreach (XmlNode subc in nl)
                                {
                                    if (colToIoDirection.ContainsKey(subc.Name))
                                    {
                                        var column = new Scalar {
                                            Name = subc.Name, Value = subc.InnerText, IODirection = colToIoDirection[subc.Name]
                                        };
                                        recSet.Columns[idx].Add(column);
                                    }
                                }
                                // update this recordset index
                                indexCache[c.Name] = ++idx;
                            }
                            else
                            {
                                if (scalar != null)
                                {
                                    scalar.Value = c.InnerXml;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void PopulateWithData(string data)
        {
            var         toLoad = data;
            XmlDocument xDoc   = new XmlDocument();

            try
            {
                xDoc.LoadXml(toLoad);
            }
            catch
            {
                // Append new root tags ;)
                toLoad = "<root>" + toLoad + "</root>";
                xDoc.LoadXml(toLoad);
            }

            if (!String.IsNullOrEmpty(toLoad))
            {
                if (xDoc.DocumentElement != null)
                {
                    XmlNodeList children = xDoc.DocumentElement.ChildNodes;

                    IDictionary <string, int> indexCache = new Dictionary <string, int>();

                    // spin through each element in the XML
                    foreach (XmlNode c in children)
                    {
                        var hasCorrectIoDirection = true;
                        if (c.Attributes != null)
                        {
                            var columnIoDirectionAttribute = c.Attributes["ColumnIODirection"];
                            if (columnIoDirectionAttribute != null)
                            {
                                var columnIoDirectionValue             = columnIoDirectionAttribute.Value;
                                var hasCorrectIoDirectionFromAttribute = columnIoDirectionValue == enDev2ColumnArgumentDirection.Output.ToString() || columnIoDirectionValue == enDev2ColumnArgumentDirection.Both.ToString();
                                hasCorrectIoDirection = hasCorrectIoDirectionFromAttribute;
                            }
                        }

                        if (DataListUtil.IsSystemTag(c.Name) && !hasCorrectIoDirection)
                        {
                            continue;
                        }
                        var recSet = RecordSets.FirstOrDefault(set => set.Name == c.Name);
                        var scalar = Scalars.FirstOrDefault(scalar1 => scalar1.Name == c.Name);
                        // scalars and recordset fetch
                        {
                            if (recSet != null)
                            {
                                // fetch recordset index
                                int fetchIdx;
                                int idx = indexCache.TryGetValue(c.Name, out fetchIdx) ? fetchIdx : 1; // recset index
                                // process recordset
                                var         scalars          = recSet.Columns[1];
                                var         colToIoDirection = scalars.ToDictionary(scalar1 => scalar1.Name, scalar1 => scalar1.IODirection);
                                XmlNodeList nl = c.ChildNodes;
                                if (!recSet.Columns.ContainsKey(idx))
                                {
                                    recSet.Columns.Add(idx, new List <IScalar>());
                                }
                                else
                                {
                                    recSet.Columns[idx] = new List <IScalar>();
                                }
                                foreach (XmlNode subc in nl)
                                {
                                    if (colToIoDirection.ContainsKey(subc.Name))
                                    {
                                        var column = new Scalar {
                                            Name = subc.Name, Value = subc.InnerText, IODirection = colToIoDirection[subc.Name]
                                        };
                                        recSet.Columns[idx].Add(column);
                                    }
                                }
                                // update this recordset index
                                indexCache[c.Name] = ++idx;
                            }
                            else
                            {
                                if (scalar != null)
                                {
                                    scalar.Value = c.InnerXml;
                                }
                            }
                        }
                    }
                }
            }
        }