示例#1
0
        public void ElmahXmlParser_ParseScriptName_GetList()
        {
            // arrange
            var expectedList = new Dictionary<Guid, string>() { { _guid1, "/folder1/test1.aspx" }, { _guid2, "/folder2/test2.aspx" }, };
            var helper = new Mock<IFileHelper>();
            var errorsXmlFileName = "errors.xml";
            helper.Setup(x => x.ReadAllLines(errorsXmlFileName)).Returns(new[] {
                string.Format("{{{0}}},<item\r\n name=\"URL\">\r\n<value\r\nstring=\"/folder1/test1.aspx\" />", _guid1.ToString()),
                string.Format("{{{0}}},<item\r\n name=\"URL\">\r\n<value\r\nstring=\"/folder2/test2.aspx\" />", _guid2.ToString()),
            });
            var parser = new ElmahXmlParser(helper.Object);

            // act
            var actualList = parser.GetScriptNameList(errorsXmlFileName);

            // assert
            Assert.That(actualList, Is.Not.Empty, "Empty List");
            Assert.That(actualList, Is.EquivalentTo(expectedList), "Wrong List");
            Assert.That(_guid1, Is.Not.EqualTo(_guid2), "GUIDs are equal?!?");
        }
示例#2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting parser engine ...");

            var parser = new ElmahXmlParser(new FileHelper());
            parser.FlattenFileContents("errors.xml");
            var scriptNameList = parser.GetScriptNameList("flatErrors.xml");
            var stackTraceList = parser.GetStackTraceList("flatErrors.xml");
            var userAgentList = parser.GetUserAgentList("flatErrors.xml");
            var outputLines = new StringBuilder("ID\tPage\tStackTrace\tUserAgent\r\n");
            var count = scriptNameList.Count;
            Console.WriteLine("Page Count: {0}\r\nStack Trace Count: {1}\r\nUser Agent Count: {2}", count, stackTraceList.Count, userAgentList.Count);
            foreach (var item in scriptNameList)
            {
                if (stackTraceList.ContainsKey(item.Key) && userAgentList.ContainsKey(item.Key))
                    outputLines.AppendFormat("{0}\t{1}\t{2}\t{3}\r\n", item.Key, item.Value, stackTraceList[item.Key], userAgentList[item.Key]);
                else
                    Console.WriteLine("Missing key: " + item.Key);
            }
            File.WriteAllText("formattedErrors.txt", outputLines.ToString());

            Console.WriteLine("Parsing Complete.");
        }