Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>();
- private List<Set> SplitBySetId(List<Step> stepList)
- {
- List<Set> outputSetList = new List<Set>();
- using (entityBuilderCore)
- {
- stepList.ForEach(step =>
- {
- // For each step, I find the corrispectives set's ids (one or more).
- // Then, I create the Set
- List<int> setIdList = entityBuilderCore.GetSetIdByStep(step);
- // Create Sets and adding to the output list
- setIdList.ToList().ForEach(id =>
- {
- if (!outputSetList.Any(set => set.Id == id))
- outputSetList.Add((Set)entityBuilderCore.GetEntity(typeof(Set), id));
- });
- });
- }
- return outputSetList;
- }
- private List<Set> SplitBySetId(List<Step> stepList)
- {
- List<Set> outputSetList = new List<Set>();
- using (entityBuilderCore)
- {
- stepList.ForEach(step =>
- {
- // For each step, I find the corrispectives set's ids (one or more).
- // Then, I create the Set
- List<int> setIdList = entityBuilderCore.GetSetIdByStep(step);
- // Create Sets and adding to the output list
- var tempList = setIdList.Distinct()
- .AsParallel()
- .Where(id => !outputSetList.Any(set => set.Id == id))
- .Select(setId => (Set)entityBuilderCore.GetEntity(typeof(Set), setId));
- outputSetList.AddRange(tempList);
- });
- }
- return outputSetList;
- }
- class EntityBuilderCore : CoreBase
- {
- private static EntityRepository Repository;
- protected override string _connectionString
- {
- get { return ConfigurationService.Instance.GetValue("connessione_database_sinistriweb"); }
- }
- private EntityBuilderCore()
- {
- Repository = new EntityRepository() { ConnectionString = _connectionString };
- }
- public BaseEntity GetEntity(Type entityType, int id)
- {
- return EntityBuilder.BuildEntity(entityType, Repository.GetEntity(entityType, id));
- }
- // ...
- public List<int> GetSetIdByStep(Step step)
- {
- return Repository.GetSetIdByStep(step);
- }
- }
- class EntityRepository : RepositoryBase
- {
- public DataRow GetEntity(Type systemType, int id)
- {
- // bla bla
- }
- public List<int> GetSetIdByStep(Step step)
- {
- // bla bla
- }
- // ...
- }
- class EntityBuilder
- {
- public static BaseEntity BuildEntity(Type entityType, DataRow dr)
- {
- if (entityType == typeof(SQL))
- return BuildSQL(dr);
- if (entityType == typeof(Step))
- return BuildStep(dr);
- if (entityType == typeof(Set))
- return BuildSet(dr);
- return null;
- }
- //...
- private static Step BuildStep(DataRow dr)
- {
- using (EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>())
- {
- Step s = new Step()
- {
- Id = Convert.ToInt16(dr["ID"]),
- //... bla bla
- };
- return s;
- }
- }
- private static Set BuildSet(DataRow dr)
- {
- using (EntityBuilderCore entityBuilderCore = ServiceFactory.Create<EntityBuilderCore>())
- {
- Set s = new Set()
- {
- Id = Convert.ToInt16(dr["ID"]),
- //...
- };
- return s;
- }
- }
- }
Add Comment
Please, Sign In to add comment