To do this, you can write a little method to merge EventConfig data into the ServerReports data by looping over the data in the dictionary associated with EventConfig and checking whether it already exists in the dictionary associated with ServerReport. Assuming that the XML files have been read into two dictionaries
Dictionary<string, List<string>> eventSource = new Dictionary<string,List<string>>();
Dictionary<string, List<string>> serverReports = new Dictionary<string, List<string>>();
the following routine merges the contents of eventSource into serverReports. The comments should hopefully explain what is going on.
private void MergeDictionaries()
{
// Loop through the eventSource dictionary
foreach (KeyValuePair<string, List<string>> item in eventSource)
{
if (serverReports.ContainsKey(item.Key))
{
// The serverReports dictionary already contains the server,
// now check whether all of the EventSources are present
foreach (string source in item.Value)
{
if (serverReports[item.Key].Contains(source))
{
// EventSource is already in the serverReports dictionary
}
else
{
// Add the EventSource to the serverReports dictionary
serverReports[item.Key].Add(source);
}
}
}
else
{
// The serverReports dictionary doesn't contain the server,
// so add the server and the corresponding EventSource entries
serverReports.Add(item.Key, new List<string>(item.Value));
}
}
}
Hope this helps!
- HomeGrownCoder My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!
No comments:
Post a Comment