Example #1
0
        public static IDictionary <string, object> Deserialize(string eventXml)
        {
            var beforeCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                var sanitizedXmlString = XmlScrubber.VerifyAndRepairXml(eventXml);
                var xe = XElement.Parse(sanitizedXmlString);

                var systemData = xe.Element(ElementNames.System);
                Dictionary <string, object> instance = XmlEventParseHelpers.ConvertSystemPropertiesToDictionary(xe);

                var eventData = xe.Element(ElementNames.EventData);
                var userData  = xe.Element(ElementNames.UserData);

                // Convert the EventData to named properties
                if (eventData != null)
                {
                    instance["EventData"] = XmlEventParseHelpers.ParseEventData(eventData);
                }

                // An event will never have EventData and UserData.
                // If there is UserData, then it should replace EventData.
                if (userData != null)
                {
                    instance["EventData"] = XmlEventParseHelpers.ParseUserData(userData);
                }

                return(instance);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = beforeCulture;
            }
        }
Example #2
0
        public static IDictionary <string, object> Deserialize(this EventLogRecord e, bool includeBookmark = false)
        {
            var beforeCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                var sanitizedXmlString = XmlScrubber.VerifyAndRepairXml(e.ToXml());
                var xe = XElement.Parse(sanitizedXmlString);

                var systemData = xe.Element(ElementNames.System);
                Dictionary <string, object> instance = XmlEventParseHelpers.ConvertSystemPropertiesToDictionary(xe);

                var eventData = xe.Element(ElementNames.EventData);
                var userData  = xe.Element(ElementNames.UserData);

                // Convert the EventData to named properties
                if (eventData != null)
                {
                    instance["EventData"] = XmlEventParseHelpers.ParseEventData(eventData);
                }

                // Convert the EventData to named properties
                if (userData != null)
                {
                    instance["UserData"] = XmlEventParseHelpers.ParseUserData(userData);
                }

                if (includeBookmark)
                {
                    instance.Add("BookmarkChannel", GetBookmarkChannel(e.Bookmark));
                }

                return(instance);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = beforeCulture;
            }
        }
Example #3
0
        public static IDictionary <string, object> OptimizedDeserialize(this EventLogRecord e)
        {
            var beforeCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                string eventXml = e.ToXml();

                var xe        = XElement.Parse(eventXml);
                var eventData = xe.Element(ElementNames.EventData);

                var instance = XmlEventParseHelpers.ConvertSystemPropertiesToDictionary(xe);
                instance.Add("BookmarkChannel", GetBookmarkChannel(e.Bookmark));

                if (eventData != null)
                {
                    var eventDataProperties = XmlEventParseHelpers.ParseEventData(eventData);
                    var namedProperties     = eventDataProperties.ToDictionary(x => x.Key, x => x.Value);
                    instance["EventData"] = namedProperties;
                }
                else
                {
                    instance.Add("EventData", new Dictionary <string, object>());
                }

                return(instance);
            }
            catch
            {
                return(Deserialize(e)); // Scrub only if any error occurs while deserializing.
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = beforeCulture;
            }
        }