public static string ReadUntilBoundaryOrThrow(PeekableStreamReader reader, string boundary)
        {
            //Вычитываем все пустые строки перед контентом
            if (!reader.ReadUntilFirstNonEmptyLine())
            {
                throw new InvalidDataException("Close boundary or content not found");
            }

            //Теперь читаем строки пока не получим боундари
            var  stringBuilder = new StringBuilder();
            bool hasOneLine    = false;

            while (true)
            {
                if (reader.EndOfStream)
                {
                    throw new InvalidDataException("Close boundary not found");
                }

                if (reader.PeekLine().StartsWith(BatchSerializeHelper.GetOpenBoundaryString(boundary)))
                {
                    return(stringBuilder.ToString());
                }
                else
                {
                    stringBuilder.Append((hasOneLine ? "\r\n" : String.Empty) + reader.ReadLine());
                    hasOneLine = true;
                }
            }
        }
Exemple #2
0
        public void ReaderContainsSingleLine_PeekLine_EndOfStreamEqualsFalse()
        {
            var reader = new PeekableStreamReader(AsStream("theLine"));

            reader.PeekLine();
            Assert.IsFalse(reader.EndOfStream);
        }
Exemple #3
0
        public void Dispose_originStreamDisposes()
        {
            var stream = new MemoryStream();
            var reader = new PeekableStreamReader(stream);

            reader.Dispose();

            Assert.Throws <ObjectDisposedException>(() => stream.Write(new byte[3], 0, 3));
        }
        internal DumpImage(PeekableStreamReader fs)
        {
            var line  = fs.ReadLine() ?? "";
            var split = line.Split(' ');

            if (split.Length < 6)
            {
                throw new InvalidOperationException($"Could not create Image out of: \"{line.Trim()}\"");
            }

            Start = int.Parse(split[^ 1]);
Exemple #5
0
        public void TwoLines_TwoPeeksReturnsTheSame()
        {
            var line   = "theLine";
            var reader = new PeekableStreamReader(AsStream(line));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(line, reader.PeekLine());
                Assert.AreEqual(line, reader.PeekLine());
            });
        }
Exemple #6
0
        public void ReaderContainsSingleLine_PeekLineAndReadLineReturnsTheSame()
        {
            var line   = "theLine";
            var reader = new PeekableStreamReader(AsStream(line));

            Assert.Multiple(() =>
            {
                Assert.AreEqual(line, reader.PeekLine());
                Assert.AreEqual(line, reader.ReadLine());
            });
        }
Exemple #7
0
        public void TwoLines_PeeksAndReadsScenario()
        {
            var line1  = "theLine";
            var line2  = "theLine2";
            var reader = new PeekableStreamReader(AsStream(line1 + "\r\n" + line2));

            Assert.AreEqual(line1, reader.PeekLine());
            Assert.AreEqual(line1, reader.PeekLine());
            Assert.AreEqual(line1, reader.ReadLine());

            Assert.AreEqual(line2, reader.PeekLine());
            Assert.AreEqual(line2, reader.PeekLine());
            Assert.AreEqual(line2, reader.ReadLine());

            Assert.IsTrue(reader.EndOfStream);
        }
Exemple #8
0
        private void ParseAttributes(PeekableStreamReader fs)
        {
            var line = fs.PeekLine();

            while (line != null && line.StartsWith("["))
            {
                if (_config.ParseTypeAttributes)
                {
                    Attributes.Add(new DumpAttribute(fs));
                }
                else
                {
                    fs.ReadLine();
                }
                line = fs.PeekLine();
            }
        }
Exemple #9
0
        internal DumpProperty(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            if (split.Length < 5)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Property cannot be created from: \"{line.Trim()}\"");
            }

            // Start at the end (but before the }), count back until we hit a { (or we have gone 3 steps)
            // Keep track of how far back we count
            int i;

            for (i = 0; i < 3; i++)
            {
                var val = split[split.Length - 2 - i];
                if (val == "{")
                {
                    break;
                }
                else if (val == "get;")
                {
                    GetMethod = true;
                }
                else if (val == "set;")
                {
                    SetMethod = true;
                }
            }
            Name = split[split.Length - 3 - i];
            Type = new DumpTypeRef(DumpTypeRef.FromMultiple(split, split.Length - 4 - i, out int adjust, -1, " "));
            for (int j = 0; j < adjust; j++)
            {
                Specifiers.Add(new DumpSpecifier(split[j]));
            }
        }
Exemple #10
0
        internal DumpField(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            // Offset is at the end
            if (split.Length < 4)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Field cannot be created from: \"{line.Trim()}\"");
            }

            Offset = Convert.ToInt32(split[^ 1], 16);
Exemple #11
0
        internal DumpMethod(TypeRef declaring, PeekableStreamReader fs)
        {
            DeclaringType = declaring;
            // Read Attributes
            var line = fs.PeekLine()?.Trim();

            while (line != null && line.StartsWith("["))
            {
                Attributes.Add(new DumpAttribute(fs));
                line = fs.PeekLine()?.Trim();
            }
            // Read prefix comment
            line = fs.ReadLine()?.Trim() ?? "";
            var split = line.Split(' ');

            if (split.Length < 5)
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Method cannot be created from: \"{line.Trim()}\"");
            }

            int start = split.Length - 1;

            if (split[^ 2] == "Slot:")
Exemple #12
0
        internal DumpAttribute(PeekableStreamReader fs)
        {
            var line = fs.ReadLine()?.Trim() ?? "";

            // Line must start with a [ after being trimmed
            if (!line.StartsWith("["))
            {
                throw new InvalidOperationException($"Line {fs.CurrentLineIndex}: Could not create attribute from: \"{line.Trim()}\"");
            }

            var parsed = line.Substring(1);

            Name = parsed.Substring(0, line.LastIndexOf(']') - 1);
            var split = parsed.Split(new string[] { " " }, StringSplitOptions.None);

            if (split.Length != 8)
            {
                return;
            }
            RVA    = Convert.ToInt32(split[3], 16);
            Offset = Convert.ToInt32(split[5], 16);
            VA     = Convert.ToInt32(split[7], 16);
        }
Exemple #13
0
        private void ParseTypeName(string @namespace, PeekableStreamReader fs)
        {
            string line  = fs.ReadLine() ?? throw new InvalidDataException();
            var    split = line.Split(' ');

            TypeDefIndex = int.Parse(split[^ 1]);
Exemple #14
0
        public void ReaderIsEmpty_ReadLineThrows()
        {
            var reader = new PeekableStreamReader(AsStream(""));

            Assert.IsNull(reader.PeekLine());
        }
Exemple #15
0
        public void ReaderIsEmpty_PeekLineReturnsNull()
        {
            var reader = new PeekableStreamReader(AsStream(""));

            Assert.IsNull(reader.PeekLine());
        }
Exemple #16
0
        public void ReaderIsEmpty_EndOfStreamEqualsTrue()
        {
            var reader = new PeekableStreamReader(AsStream(""));

            Assert.IsTrue(reader.EndOfStream);
        }