Sunday, 1 September 2013

Best way to compare 3 lists with different types of data

Best way to compare 3 lists with different types of data

I'm trying to find the best way to compare 3 lists in C# and then merge
the result into one csv file. My code takes quite a lot of time to process
my data and i want to improve this.
What I do at the moment is comparing 2 lists at a time using LINQ, saving
the result for each comparison into a temporary list and then merge it
before saving it as a csv file.
An example of one of my list tests:
foreach (RemedyAsset remedyAsset in RemedyAssetsList)
{
MIAsset tempMIAsset = null;
tempMIAsset = MIAssetsList.FirstOrDefault(m =>
m.CIName.ToUpper() == remedyAsset.CIName.ToUpper());
if (tempMIAsset == null)
{
TempAssets.Add(new TempAsset
{
Asset = remedyAsset.CIName,
LastMiActivity = string.Empty,
RemedyStatus = remedyAsset.Status,
InMI = false,
InRemedy = true
});
}
else
{
TempAssets.Add(new TempAsset
{
Asset = remedyAsset.CIName,
LastMiActivity = tempMIAsset.LastActiveTime,
RemedyStatus = remedyAsset.Status,
InMI = true,
InRemedy = true
});
}
}
My lists originates from 3 different IT systems(BMC Remedy, Active
Directory, Checkpoint), which has one common variable: An asset number.
My lists look like this:
-(List1)RemedyReport: Asset number - Remedy status.
-(List2)ADReport: Asset number - last logon time - last password change.
-(List3)MIReport: Asset number - last server contact.

When I compare the lists, I also check if an asset number isn't present in
a list and this also needs to be shown in the output csv file. I then
needs to merge data from the lists where a matching asset number is
present and the output will look like this:
Asset number - In Remedy - In MI - In AD - Last server contact - Last
Logon - Last password change
What is the best way to compare 3 lists?
Is there any best practices when doing a compare of 3 or more lists?
This is my first post in here, please let me know if I've done anything
wrong.

No comments:

Post a Comment