Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Sources/EventViewerX/EventObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,37 @@ private Dictionary<string, string> ParseMessage(string message) {
return data;
}

/// <summary>
/// Parses lines containing colon separated key/value pairs.
/// </summary>
/// <param name="text">Text to parse</param>
/// <returns>Dictionary with parsed key value pairs</returns>
private static Dictionary<string, string> ParseColonSeparatedLines(string text) {
Dictionary<string, string> data = new Dictionary<string, string>();
if (string.IsNullOrEmpty(text)) {
return data;
}

string[] lines = Regex.Split(text, "\r?\n");
foreach (string rawLine in lines) {
string line = rawLine.Trim();
if (string.IsNullOrEmpty(line)) {
continue;
}

int index = line.IndexOf(':');
if (index > -1) {
string key = line.Substring(0, index).Trim();
string value = line.Substring(index + 1).Trim();
if (!string.IsNullOrEmpty(key)) {
data[key] = value;
}
}
}

return data;
}

/// <summary>
/// Parses the XML data of the event record into a dictionary converting it into a key value pair
/// </summary>
Expand Down Expand Up @@ -243,6 +274,11 @@ private Dictionary<string, string> ParseXML(string xmlData) {
}
}
data[name] = value;
foreach (var kv in ParseColonSeparatedLines(value)) {
if (!data.ContainsKey(kv.Key)) {
data[kv.Key] = kv.Value;
}
}
}
}
return data;
Expand Down
Loading