Guest User

Untitled

a guest
Oct 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. private static EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>();
  2.  
  3. private List<Set> SplitBySetId(List<Step> stepList)
  4. {
  5. List<Set> outputSetList = new List<Set>();
  6.  
  7. using (entityBuilderCore)
  8. {
  9. stepList.ForEach(step =>
  10. {
  11. // For each step, I find the corrispectives set's ids (one or more).
  12. // Then, I create the Set
  13. List<int> setIdList = entityBuilderCore.GetSetIdByStep(step);
  14.  
  15. // Create Sets and adding to the output list
  16. setIdList.ToList().ForEach(id =>
  17. {
  18. if (!outputSetList.Any(set => set.Id == id))
  19. outputSetList.Add((Set)entityBuilderCore.GetEntity(typeof(Set), id));
  20. });
  21. });
  22. }
  23.  
  24. return outputSetList;
  25. }
  26.  
  27. private List<Set> SplitBySetId(List<Step> stepList)
  28. {
  29. List<Set> outputSetList = new List<Set>();
  30.  
  31. using (entityBuilderCore)
  32. {
  33. stepList.ForEach(step =>
  34. {
  35. // For each step, I find the corrispectives set's ids (one or more).
  36. // Then, I create the Set
  37. List<int> setIdList = entityBuilderCore.GetSetIdByStep(step);
  38.  
  39. // Create Sets and adding to the output list
  40. var tempList = setIdList.Distinct()
  41. .AsParallel()
  42. .Where(id => !outputSetList.Any(set => set.Id == id))
  43. .Select(setId => (Set)entityBuilderCore.GetEntity(typeof(Set), setId));
  44.  
  45. outputSetList.AddRange(tempList);
  46. });
  47. }
  48. return outputSetList;
  49. }
  50.  
  51. class EntityBuilderCore : CoreBase
  52. {
  53. private static EntityRepository Repository;
  54.  
  55. protected override string _connectionString
  56. {
  57. get { return ConfigurationService.Instance.GetValue("connessione_database_sinistriweb"); }
  58. }
  59.  
  60. private EntityBuilderCore()
  61. {
  62. Repository = new EntityRepository() { ConnectionString = _connectionString };
  63. }
  64.  
  65. public BaseEntity GetEntity(Type entityType, int id)
  66. {
  67. return EntityBuilder.BuildEntity(entityType, Repository.GetEntity(entityType, id));
  68. }
  69.  
  70. // ...
  71.  
  72. public List<int> GetSetIdByStep(Step step)
  73. {
  74. return Repository.GetSetIdByStep(step);
  75. }
  76.  
  77. }
  78.  
  79.  
  80.  
  81. class EntityRepository : RepositoryBase
  82. {
  83. public DataRow GetEntity(Type systemType, int id)
  84. {
  85. // bla bla
  86. }
  87.  
  88. public List<int> GetSetIdByStep(Step step)
  89. {
  90. // bla bla
  91. }
  92.  
  93. // ...
  94.  
  95. }
  96.  
  97. class EntityBuilder
  98. {
  99. public static BaseEntity BuildEntity(Type entityType, DataRow dr)
  100. {
  101. if (entityType == typeof(SQL))
  102. return BuildSQL(dr);
  103.  
  104. if (entityType == typeof(Step))
  105. return BuildStep(dr);
  106.  
  107. if (entityType == typeof(Set))
  108. return BuildSet(dr);
  109.  
  110. return null;
  111. }
  112.  
  113.  
  114. //...
  115.  
  116. private static Step BuildStep(DataRow dr)
  117. {
  118. using (EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>())
  119. {
  120. Step s = new Step()
  121. {
  122. Id = Convert.ToInt16(dr["ID"]),
  123. //... bla bla
  124. };
  125. return s;
  126. }
  127. }
  128.  
  129. private static Set BuildSet(DataRow dr)
  130. {
  131. using (EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>())
  132. {
  133. Set s = new Set()
  134. {
  135. Id = Convert.ToInt16(dr["ID"]),
  136. //...
  137. };
  138.  
  139. return s;
  140. }
  141. }
  142. }
Add Comment
Please, Sign In to add comment