Esempio 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);
                }
            }
        }
Esempio n. 2
0
        private void AddRecsetShape(ref enDev2ColumnArgumentDirection columnDirection, XmlNode c, ref XmlAttribute descAttribute, ref XmlAttribute columnIoDirection)
        {
            var cols = new List <IScalar>();

            foreach (XmlNode subc in c.ChildNodes)
            {
                // It is possible for the .Attributes property to be null, a check should be added
                AddAttributes(ref columnDirection, ref descAttribute, ref columnIoDirection, cols, subc);
            }
            if (c.Attributes != null)
            {
                descAttribute     = c.Attributes["Description"];
                columnIoDirection = c.Attributes["ColumnIODirection"];
            }

            var descriptionValue = "";

            columnDirection = enDev2ColumnArgumentDirection.None;
            if (descAttribute != null)
            {
                descriptionValue = descAttribute.Value;
            }
            if (columnIoDirection != null)
            {
                Enum.TryParse(columnIoDirection.Value, true, out columnDirection);
            }
            var recSet = new RecordSet {
                Columns = new Dictionary <int, List <IScalar> > {
                    { 1, cols }
                }, Description = descriptionValue, IODirection = columnDirection, IsEditable = false, Name = c.Name
            };

            RecordSets.Add(recSet);
            var shapeRecSet = new RecordSet {
                Columns = new Dictionary <int, List <IScalar> > {
                    { 1, cols }
                }, Description = descriptionValue, IODirection = columnDirection, IsEditable = false, Name = c.Name
            };

            ShapeRecordSets.Add(shapeRecSet);
        }
Esempio 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;
                        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;
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public void CreateShape(string shape)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(shape);
            if (xDoc.DocumentElement != null)
            {
                XmlNodeList children = xDoc.DocumentElement.ChildNodes;

                var columnDirection = enDev2ColumnArgumentDirection.None;
                foreach (XmlNode c in children)
                {
                    XmlAttribute descAttribute     = null;
                    XmlAttribute columnIoDirection = null;
                    if (!DataListUtil.IsSystemTag(c.Name))
                    {
                        if (c.HasChildNodes)
                        {
                            var jsonAttribute = false;
                            var xmlAttribute  = c.Attributes?["IsJson"];
                            if (xmlAttribute != null)
                            {
                                bool.TryParse(xmlAttribute.Value, out jsonAttribute);
                            }
                            if (jsonAttribute)
                            {
                                AddComplexObjectFromXmlNode(c);
                            }
                            else
                            {
                                var cols = new List <IScalar>();
                                foreach (XmlNode subc in c.ChildNodes)
                                {
                                    // It is possible for the .Attributes property to be null, a check should be added
                                    if (subc.Attributes != null)
                                    {
                                        descAttribute     = subc.Attributes["Description"];
                                        columnIoDirection = subc.Attributes["ColumnIODirection"];
                                        if (columnIoDirection != null)
                                        {
                                            Enum.TryParse(columnIoDirection.Value, true, out columnDirection);
                                        }
                                    }
                                    var scalar = new Scalar {
                                        Name = subc.Name, IsEditable = true, IODirection = columnDirection
                                    };
                                    if (descAttribute != null)
                                    {
                                        scalar.Description = descAttribute.Value;
                                    }
                                    cols.Add(scalar);
                                }
                                if (c.Attributes != null)
                                {
                                    descAttribute     = c.Attributes["Description"];
                                    columnIoDirection = c.Attributes["ColumnIODirection"];
                                }

                                var descriptionValue = "";
                                columnDirection = enDev2ColumnArgumentDirection.None;
                                if (descAttribute != null)
                                {
                                    descriptionValue = descAttribute.Value;
                                }
                                if (columnIoDirection != null)
                                {
                                    Enum.TryParse(columnIoDirection.Value, true, out columnDirection);
                                }
                                var recSet = new RecordSet {
                                    Columns = new Dictionary <int, List <IScalar> > {
                                        { 1, cols }
                                    }, Description = descriptionValue, IODirection = columnDirection, IsEditable = false, Name = c.Name
                                };
                                RecordSets.Add(recSet);
                                var shapeRecSet = new RecordSet {
                                    Columns = new Dictionary <int, List <IScalar> > {
                                        { 1, cols }
                                    }, Description = descriptionValue, IODirection = columnDirection, IsEditable = false, Name = c.Name
                                };
                                ShapeRecordSets.Add(shapeRecSet);
                            }
                        }
                        else
                        {
                            if (c.Attributes != null)
                            {
                                descAttribute     = c.Attributes["Description"];
                                columnIoDirection = c.Attributes["ColumnIODirection"];
                            }
                            string descriptionValue = "";
                            columnDirection = enDev2ColumnArgumentDirection.None;
                            if (descAttribute != null)
                            {
                                descriptionValue = descAttribute.Value;
                            }
                            if (columnIoDirection != null)
                            {
                                Enum.TryParse(columnIoDirection.Value, true, out columnDirection);
                            }
                            var scalar = new Scalar {
                                Name = c.Name, Description = descriptionValue, IODirection = columnDirection, IsEditable = true
                            };
                            Scalars.Add(scalar);
                            ShapeScalars.Add(scalar);
                        }
                    }
                }
            }
        }