Exemplo n.º 1
0
        /// <summary>
        ///     Determine if all descendants are constant.
        /// </summary>
        /// <returns>True if all descendants are constant.</returns>
        public bool AllConstDescendants()
        {
            if (IsVariable)
            {
                return(false);
            }

            if (IsLeaf)
            {
                return(true);
            }

            return(ChildNodes.Cast <ProgramNode>().All(childNode => childNode.AllConstDescendants()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the cached Document and property flags.
        /// </summary>
        ///
        /// <param name="document">
        /// A reference to the owning document. This is also the topmost node in the tree.
        /// </param>

        protected void UpdateDocumentFlags(IDomDocument document)
        {
            _Document = document;
            SetDocFlags();
            // I think we can get away without resetting children. When removing something from a document,
            // you are exclusively going to be adding it to something else. We only need to update the parents
            // during the add operation.

            if (HasChildren && _Document != null)
            {
                foreach (var item in ChildNodes.Cast <DomObject>())
                {
                    item.UpdateDocumentFlags(_Document);
                }
            }
        }
Exemplo n.º 3
0
        public override void ToPrecedenceFreeEPL(TextWriter writer)
        {
            var delimiter = "";

            IEnumerator <ExprNode> it = ChildNodes.Cast <ExprNode>().GetEnumerator();

            it.MoveNext();
            it.Current.ToEPL(writer, Precedence);
            writer.Write(_isNotIn ? " not in (" : " in (");

            while (it.MoveNext())
            {
                ExprNode inSetValueExpr = it.Current;
                writer.Write(delimiter);
                inSetValueExpr.ToEPL(writer, Precedence);
                delimiter = ",";
            }

            writer.Write(')');
        }
Exemplo n.º 4
0
 public virtual IEnumerable <DirectiveTriviaSyntax> GetDirectives()
 {
     return(ChildNodes.Cast <SyntaxNode>().SelectMany(x => x.GetDirectives()));
 }
        public void RegisterPatch_RemoveComments_FirstNodeRootComment()
        {
            // Arrange
            const string MovieName       = "TestMovieName";
            const string XPath           = "descendant::OptionsScreenWidget[@Id='Options']/Children";
            XmlDocument  patchedDocument = new();

            patchedDocument.LoadXml("<DiscardedRoot><!--Root Comment--><ValidRoot><SomeChild/></ValidRoot></DiscardedRoot>");
            var patch = PatchCreator.ConstructInsertPatch(InsertType.Child, patchedDocument !.DocumentElement !.ChildNodes.Cast <XmlNode>());

            PrefabComponent prefabComponent = new("TestModule");
            var             movieDocument   = GetBaseDocument();

            // Act
            prefabComponent.RegisterPatch(MovieName, XPath, patch);
            prefabComponent.ProcessMovieIfNeeded(MovieName, movieDocument);

            // Assert
            Assert.AreEqual(0, movieDocument.SelectNodes("//comment()")?.Count, $"Remaining comments count: {movieDocument.SelectNodes("//comment()")?.Count}");

            // Validate that every node we did want inserted are actually inserted.
            var validRootNode = movieDocument.SelectSingleNode("descendant::ValidRoot");

            Assert.IsNotNull(validRootNode);
            Assert.AreEqual("Children", validRootNode !.ParentNode !.Name);
            Assert.AreEqual("SomeChild", validRootNode.FirstChild.Name);
            Assert.AreEqual(validRootNode, validRootNode.ParentNode.FirstChild, $"First child should be ValidRoot. Was {validRootNode.ParentNode.FirstChild.Name}");
        }
        public void RegisterPatch_XmlNodes_InsertMultipleChildren()
        {
            // Arrange
            const string MovieName       = "TestMovieName";
            const string XPath           = "descendant::OptionsScreenWidget[@Id='Options']/Children";
            XmlDocument  patchedDocument = new();

            patchedDocument.LoadXml("<DiscardedRoot><Child1><InnerChild/></Child1><Child2/><Child3/></DiscardedRoot>");
            var patch = PatchCreator.ConstructInsertPatch(InsertType.Child, patchedDocument !.DocumentElement !.ChildNodes.Cast <XmlNode>());

            PrefabComponent prefabComponent = new("TestModule");
            var             movieDocument   = GetBaseDocument();

            // Act
            prefabComponent.RegisterPatch(MovieName, XPath, patch);
            prefabComponent.ProcessMovieIfNeeded(MovieName, movieDocument);

            // Assert
            var child1Node = movieDocument.SelectSingleNode("descendant::Child1");

            Assert.IsNotNull(child1Node);
            Assert.AreEqual("Children", child1Node !.ParentNode !.Name);
            Assert.AreEqual("InnerChild", child1Node.FirstChild.Name);
            Assert.AreEqual("Child1", child1Node.ParentNode.ChildNodes[0].Name, $"First child should be Child1. Was {child1Node.ParentNode.FirstChild.Name}");
            Assert.AreEqual("Child2", child1Node.ParentNode.ChildNodes[1].Name, $"Second child should be Child2. Was {child1Node.ParentNode.FirstChild.Name}");
            Assert.AreEqual("Child3", child1Node.ParentNode.ChildNodes[2].Name, $"Third child should be Child3. Was {child1Node.ParentNode.FirstChild.Name}");
        }
Exemplo n.º 7
0
 /// <summary>
 ///     True if all children are constant.
 /// </summary>
 /// <returns>True if all children are constant.</returns>
 public bool AllConstChildren()
 {
     return(ChildNodes.Cast <ProgramNode>().All(node => !node.IsVariable));
 }
Exemplo n.º 8
0
        static XmlRpcValue Parse(XmlNode?value)
        {
            if (value == null)
            {
                throw new ParseException("Expected child node but received null!");
            }

            Assert(value.Name, "value");
            if (!value.HasChildNodes)
            {
                return(new XmlRpcValue(value.InnerText));
            }

            XmlNode?primitive = value.FirstChild;

            if (primitive is XmlText)
            {
                return(new XmlRpcValue(primitive.InnerText));
            }

            switch (primitive?.Name)
            {
            case null:
                throw new ParseException("Expected node name but received null!");

            case "double":
                return(double.TryParse(primitive.InnerText, NumberStyles.Number, Defaults.Culture,
                                       out double @double)
                        ? new XmlRpcValue(@double)
                        : throw new ParseException($"Could not parse '{primitive.InnerText}' as double!"));

            case "i4":
            case "int":
                return(int.TryParse(primitive.InnerText, NumberStyles.Number, Defaults.Culture, out int @int)
                        ? new XmlRpcValue(@int)
                        : throw new ParseException($"Could not parse '{primitive.InnerText}' as integer!"));

            case "boolean":
                return(new XmlRpcValue(primitive.InnerText == "1"));

            case "string":
                return(new XmlRpcValue(primitive.InnerText));

            case "array":
                XmlNode?data = primitive.FirstChild;
                Assert(data?.Name, "data");
                return(new XmlRpcValue(data !.ChildNodes.Cast <XmlNode?>().Select(Parse).ToArray()));

            case "dateTime.iso8601":
                return(DateTime.TryParseExact(primitive.InnerText, "yyyy-MM-ddTHH:mm:ssZ",
                                              CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime dt)
                        ? new XmlRpcValue(dt)
                        : new XmlRpcValue(DateTime.MinValue));

            case "base64":
                try
                {
                    return(new XmlRpcValue(Convert.FromBase64String(primitive.InnerText)));
                }
                catch (FormatException e)
                {
                    throw new ParseException($"Could not parse '{primitive.InnerText}' as base64!", e);
                }

            case "struct":
                var structValue = new List <(string, XmlRpcValue)>();
                foreach (XmlNode?member in primitive.ChildNodes)
                {
                    if (member is not {
                        Name: "member"
                    })
                    {
                        continue;
                    }

                    string?     entryName  = null;
                    XmlRpcValue entryValue = default;
                    foreach (XmlNode?entry in member.ChildNodes)
                    {
                        switch (entry?.Name)
                        {
                        case null:
                            break;

                        case "name":
                            entryName = entry.InnerText;
                            break;

                        case "value":
                            entryValue = Parse(entry);
                            break;
                        }
                    }

                    if (entryName is null || entryValue.IsEmpty)
                    {
                        Logger.Log("XmlRpc.Service: Invalid struct entry");
                        continue;
                    }

                    structValue.Add((entryName, entryValue));
                }