예제 #1
0
        internal override IEnumerable <YamlNode> SafeAllNodes(RecursionLevel level)
        {
            level.Increment();
            yield return((YamlNode)this);

            /*Error: Unable to find new state assignment for yield return*/;
        }
예제 #2
0
        /// <summary>
        /// Returns a <see cref="string"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="string"/> that represents this instance.
        /// </returns>
        internal override string ToString(RecursionLevel level)
        {
            if (!level.TryIncrement())
            {
                return(MaximumRecursionLevelReachedToStringValue);
            }

            using var textBuilder = StringBuilderPool.Rent();
            var text = textBuilder.Builder;

            text.Append("[ ");

            foreach (var child in children)
            {
                if (text.Length > 2)
                {
                    text.Append(", ");
                }
                text.Append(child.ToString(level));
            }

            text.Append(" ]");

            level.Decrement();

            return(text.ToString());
        }
예제 #3
0
        /// <summary>
        /// Saves the options to the specified writer.
        /// </summary>
        public void Save(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            StringBuilder sb = new StringBuilder()
                               .AppendLine("[TeleCommand]")
                               .Append("CommandID=").AppendLine(CommandID.ToString())
                               .Append("CreationTime=").AppendLine(CreationTime.ToString(DateTimeFormatInfo.InvariantInfo))
                               .Append("ClientName=").AppendLine(ClientName)
                               .Append("UserID=").AppendLine(UserID.ToString())
                               .Append("CnlNum=").AppendLine(CnlNum.ToString())
                               .Append("ObjNum=").AppendLine(ObjNum.ToString())
                               .Append("DeviceNum=").AppendLine(DeviceNum.ToString())
                               .Append("CmdNum=").AppendLine(CmdNum.ToString())
                               .Append("CmdCode=").AppendLine(CmdCode)
                               .Append("CmdVal=").AppendLine(CmdVal.ToString(NumberFormatInfo.InvariantInfo))
                               .Append("CmdData=").AppendLine(ScadaUtils.BytesToHex(CmdData))
                               .Append("RecursionLevel=").AppendLine(RecursionLevel.ToString())
                               .AppendLine("End=");

            using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8, 1024, true))
            {
                writer.Write(sb.ToString());
            }
        }
예제 #4
0
 internal override string ToJson(RecursionLevel level)
 {
     if ("null".Equals(Value))
     {
         return(Value);
     }
     return("\"" + Value + "\"");
 }
예제 #5
0
        /// <summary>
        /// Recursively enumerates all the nodes from the document, starting on the current node,
        /// and throwing <see cref="MaximumRecursionLevelReachedException"/>
        /// if <see cref="RecursionLevel.Maximum"/> is reached.
        /// </summary>
        internal override IEnumerable <YamlNode> SafeAllNodes(RecursionLevel level)
        {
            level.Increment();
            yield return(this);

            foreach (var child in children)
            {
                foreach (var node in child.SafeAllNodes(level))
                {
                    yield return(node);
                }
            }
            level.Decrement();
        }
예제 #6
0
        internal override string ToString(RecursionLevel level)
        {
            if (!level.TryIncrement())
            {
                return("WARNING! INFINITE RECURSION!");
            }
            StringBuilder stringBuilder = new StringBuilder("[ ");

            foreach (YamlNode child in children)
            {
                if (stringBuilder.Length > 2)
                {
                    stringBuilder.Append(", ");
                }
                stringBuilder.Append(child.ToString(level));
            }
            stringBuilder.Append(" ]");
            level.Decrement();
            return(stringBuilder.ToString());
        }
예제 #7
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        internal override string ToString(RecursionLevel level)
        {
            if (!level.TryIncrement())
            {
                return(MaximumRecursionLevelReachedToStringValue);
            }

            var text = new StringBuilder("{ ");

            foreach (var child in children)
            {
                if (text.Length > 2)
                {
                    text.Append(", ");
                }
                text.Append("{ ").Append(child.Key.ToString(level)).Append(", ").Append(child.Value.ToString(level)).Append(" }");
            }

            text.Append(" }");

            level.Decrement();

            return(text.ToString());
        }
예제 #8
0
 /// <summary>
 /// When implemented, recursively enumerates all the nodes from the document, starting on the current node.
 /// If <see cref="RecursionLevel.Maximum"/> is reached, a <see cref="MaximumRecursionLevelReachedException"/> is thrown
 /// instead of continuing and crashing with a <see cref="StackOverflowException"/>.
 /// </summary>
 internal abstract IEnumerable <YamlNode> SafeAllNodes(RecursionLevel level);
예제 #9
0
 internal abstract string ToString(RecursionLevel level);
예제 #10
0
        public override string ToString()
        {
            var level = new RecursionLevel(MaximumRecursionLevel);

            return(ToString(level));
        }
예제 #11
0
 /// <summary>
 /// Returns a <see cref="System.String"/> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="System.String"/> that represents this instance.
 /// </returns>
 internal override string ToString(RecursionLevel level)
 {
     return("*" + Anchor);
 }
예제 #12
0
 /// <summary>
 /// Recursively enumerates all the nodes from the document, starting on the current node,
 /// and throwing <see cref="MaximumRecursionLevelReachedException"/>
 /// if <see cref="RecursionLevel.Maximum"/> is reached.
 /// </summary>
 internal override IEnumerable <YamlNode> SafeAllNodes(RecursionLevel level)
 {
     yield return(this);
 }
예제 #13
0
 /// <summary>
 /// Returns a <see cref="string"/> that represents this instance.
 /// </summary>
 /// <returns>
 /// A <see cref="string"/> that represents this instance.
 /// </returns>
 internal override string ToString(RecursionLevel level)
 {
     return(Value ?? string.Empty);
 }
예제 #14
0
        public override string ToString()
        {
            RecursionLevel level = new RecursionLevel(1000);

            return(ToString(level));
        }
예제 #15
0
 internal abstract string ToJson(RecursionLevel level);
예제 #16
0
        public string ToJson()
        {
            var level = new RecursionLevel(MaximumRecursionLevel);

            return(ToJson(level));
        }