0

I am sorry if the title is misleading.
I have integer id's in such a way so that for particular pair of Id's, I have to execute a separate process in the application, while for other pair of ID's, other execution should be followed.

How can I put these id's in enum so that I can use Flags and on the basis of those flags, I can execute the process further.

e.g

For  ID's (1000040, 1000049)---> ProcessBellBochumImport()
For  ID's (1000039,1000048) ---> ProcessAbrahamImport()
For  ID's (1000042,1000052) ---> ProcessTransthermoImport()

Moreover, I have idea to have Dictionary<int,IProcess> dictionary so that, as soon as I pass id, I should dynamically execute the corresponding process.

A possible implementation can be :

public enum ClientSubsidiaries
{
   BellBochum : 000040 | 1000049,
   Abraham : 1000039|1000048,  don't know | or &
   Transthermo : 1000042|1000052 | or & ..?
}

In other words, above stretegy is just the registration of a single process against couple of Id's.

class Import
{
  Dictionary<int, IProcess> dictionary  = new  Dictionary<int, IProcess>();

  public Import(int Id)
  {
      // something similar ......
      (dictionary[Id]).ExecuteProcess();
  }
}

I cahanged snum with the following, it seems this can be done somehow!!

[Flags]
public enum BellClientSubsidiaryGroup
{
    BellBochum = 1000039 | 1000048,
    Abraham = 1000040 | 1000049,
    Transthermo = 1000042 | 1000050
}

I also initialize the dictionary in the following way .

IDictionary<BellClientSubsidiaryGroup, IConsignmentBuilder<Bell>> BellCsIdToImportMap { get; set; }  

public void initMap()
{    
   BellCsIdToImportMap[BellClientSubsidiaryGroup.BellBochum] = new BellBochumImport(importLookupData, forwarderId);
   BellCsIdToImportMap[BellClientSubsidiaryGroup.Abraham] = new AbrahamImport(importLookupData, forwarderId);
   BellCsIdToImportMap[BellClientSubsidiaryGroup.Transthermo] = new TransthermoImport(importLookupData, forwarderId);
}

public void Process(int ClientSubsidiaryId)
{
  // here I need help... how can incoming id ( clientSubsidiaryId ) be  mapped to Group of Ids
  if ((ClientSubsidiaryId& BellClientSubsidiaryGroup.BellBochum) != 0)
  {

  }
}
Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
Usman
  • 2,742
  • 4
  • 44
  • 82
  • Your dictionary is keyed by single int, but you say you have pairs of ints. How's that? – Evk Dec 06 '16 at 10:00
  • nops, that's just an idea, I want that if incoming id is found in any pair , e.g from gui user passed ( 1000049 or 1000040 ), then BellBochum Process should be executed, similarly, if user passed, 1000042 then Transthermo process should be started. So, in coming Id would be single at a time, could be any one from the pairs. – Usman Dec 06 '16 at 10:06
  • Sample test could be : Input = 1000039. Process Abraham Input = 1000048 -> Process Abraham again. 1000042 -> Process Transthermo and so on – Usman Dec 06 '16 at 10:09
  • Well, you cannot do that with enum, so you have to just map ids to IProcesses in a different way. – Evk Dec 06 '16 at 10:20

0 Answers0