how to distribute the `packet` to respective `owner` when `Name` and `Rule` matches

  • Thread starter Thread starter Yazdani ISTS
  • Start date Start date
Y

Yazdani ISTS

Guest
I have a complex case where I have to to compare 2 list of data bases on some Rules and Name and then need to distribute the packet to respective owner of the Rule. Please suggest how to approach and on how to match?


  • I have a class NameOwnersBasedOnRule where I have define my different set of Rule\Owner for a Name.

  • Number of Rule and Owner are NOT fixed for each Name.

var nameOwnersBasedOnRule = new List<NameOwnersBasedOnRule>
{
new NameOwnersBasedOnRule
{
Name = "Name1", Owners = new Dictionary<string, string>
{
{"Rule1", "Owner1"}, {"Rule2", "Owner2"}, {"Rule3", "Owner3"}
}
},
new NameOwnersBasedOnRule
{
Name = "Name2", Owners = new Dictionary<string, string>
{
{"Rule2", "Owner2"}
}
},
new NameOwnersBasedOnRule
{
Name = "Name3", Owners = new Dictionary<string, string>
{
{"Rule1", "Owner1"}, {"Rule1", "Owner2"}
}
}
};

  • Now I have list of packet and each packet has some Rule associates with it and the Name is part of nested InstanceData. Here are some packets,

var packets = new List<Packet>
{
new Packet
{
Id = new Guid("2e08bd98-68eb-4358-8efb-9f2adedfb034"),
Rules = new List<string>{"Rule1", "Rule2"},
Results = new Result
{
ResultName = "ResultName1",
Instances = new List<Instance>
{
new Instance
{
InstanceName = "InstanceName1",
InstanceDatas = new List<InstanceData>
{
new InstanceData{Name = "Name1", Value = "V1"},
}
}
}
}
},
new Packet
{
Id = new Guid("260ee32f-0775-49ef-b24c-632cb0b0be1a"),
Rules = new List<string>{"Rule1"},
Results = new Result
{
ResultName = "ResultName2",
Instances = new List<Instance>
{
new Instance
{
InstanceName = "InstanceName2",
InstanceDatas = new List<InstanceData>
{
new InstanceData{Name = "Name2", Value = "V2"},
}
}
}
}
}
};

  • Now I need to match Name and Rules from both list and if match I need to distribute it to the associated Owner. Same Packet will go to each owner based on match.

  • In above example data, I have 2 packets....

  • first packet with name Name1 has to duplicate to owners Owner1 and Owner2 as both rules "Rule1", "Rule2" exist here.

  • second packet does not match anything, so NO distribution.

  • I need to extract list of packets based on number of owners. For above example data, 2 list

    listOfPacketsForOwner1 =.....
    listOfPacketsForOwner2 =.....

Here all the class structure I have,

public class NameOwnersBasedOnRule
{
public string Name { get; set; }
public Dictionary<string, string> Owners{ get; set; }
}

public class Packet
{
public Guid Id { get; set; }
public List<string> Rules { get; set; }
public Result Results { get; set; }
}

public class Result
{
public string ResultName { get; set; }
public List<Instance> Instances { get; set; }
}

public class Instance
{
public string InstanceName { get; set; }
public List<InstanceData> InstanceDatas { get; set; }
}

public class InstanceData
{
public string Name { get; set; }
public string Value { get; set; }
}

Continue reading...
 
Back
Top