private static void StartProtocolGenerate(DistanceGroupAmount amnt, StartTimer timer, List <string> lHeaders = null) { //all distances List <Distance> lDistances = База.DbList; //get all protocol variants Dictionary <DistanceLevels, List <DistanceGroupType> > lVariants = new Dictionary <DistanceLevels, List <DistanceGroupType> >(); foreach (Distance d in lDistances) { DistanceLevels level = d.Level; if (!lVariants.ContainsKey(level)) { lVariants.Add(level, new List <DistanceGroupType>()); } foreach (KeyValuePair <Structs.GroupIndexAmountStruct, DistanceGroup> kvPair in d.Groups) { if (!lVariants[level].Contains(kvPair.Value.Type)) { lVariants[level].Add(kvPair.Value.Type); } } } //generate protocol for each distance type foreach (KeyValuePair <DistanceLevels, List <DistanceGroupType> > kvPair in lVariants) { foreach (DistanceGroupType type in kvPair.Value) { Distance distance = База.GetOneDistance(amnt, kvPair.Key, type); if (distance.Groups.Count > 0) { string nameSuffix = kvPair.Key.ToString() + "_" + EnumCasters.GroupTypeStringRepresent(type); StartProtocolGenerator generator = new StartProtocolGenerator(amnt, timer); if (lHeaders != null) { generator.LHeaders = lHeaders; } generator.Create(distance, suffix: nameSuffix); timer.Reset(); } } } }
public Distance(DistanceLevels level) { _Groups = new Dictionary <GroupIndexAmountStruct, DistanceGroup>(); _Level = level; }
private static void ConvertDataToModels() { //Check if data got if (lData is null) { #pragma warning disable CA1303 // Не передавать литералы в качестве локализованных параметров throw new InvalidOperationException("Data is not set"); #pragma warning restore CA1303 // Не передавать литералы в качестве локализованных параметров } // Dictionary contains groups. Keys are group's index entered by user Dictionary <GroupIndexAmountStruct, DistanceGroup> DictGroups = new Dictionary <GroupIndexAmountStruct, DistanceGroup>(); int iRow = 0; lData.ForEach((row) => { try { Person person = new Person( name: Utils.ReadStringValue(row, iName), birth: Utils.ReadDateTimeValue(row, iBirth), region: Utils.ReadStringValue(row, iRegion), delegation: Utils.ReadStringValue(row, iDelegation), rang: EnumCasters.CastToRangs(Utils.ReadStringValue(row, iRang)), sex: EnumCasters.CastToSex(Utils.ReadStringValue(row, iSex)) ); bool b1 = Utils.ReadBoolValue(row, iGroupPersonIndex); int i2 = Utils.ReadIntValue(row, iGroupDoubleIndex); int i4 = Utils.ReadIntValue(row, iGroupFourIndex); string manager = Utils.ReadStringValue(row, iManager); DistanceLevels level = EnumCasters.NumberToDistanceLevelType(Utils.ReadIntValue(row, iDistanceLevel)); if (b1) { linkPersonWithDistances(person, new GroupIndexAmountStruct(-1, DistanceGroupAmount.One), level, manager); } if (i2 != 0) { linkPersonWithDistances(person, new GroupIndexAmountStruct(i2, DistanceGroupAmount.Two), level, manager); } if (i4 != 0) { linkPersonWithDistances(person, new GroupIndexAmountStruct(i4, DistanceGroupAmount.Four), level, manager); } } catch (InvalidFieldTypeException e) { e.IRow = iRow; #pragma warning disable CA2200 // Повторно порождайте исключения для сохранения сведений стека. throw e; #pragma warning restore CA2200 // Повторно порождайте исключения для сохранения сведений стека. } iRow++; }); checkIfEachGroupIsFull(); //add persons in groups and then to distance entity void linkPersonWithDistances(Person prsn, GroupIndexAmountStruct groupIndexAmountData, DistanceLevels level, string manager) { try { if (existDistance(level, out Distance distance)) { linkPerson(distance); } else { Distance tmpDistance = new Distance(level); linkPerson(tmpDistance); lDistances.Add(tmpDistance); } } catch (GroupFullException) { throw new GroupFullException(groupIndexAmountData); } void linkPerson(Distance dist) { if (groupIndexAmountData.Amnt == DistanceGroupAmount.One) { newGroup(); } else { // If group already exists then just add to it new member. Else create new group if (dist.Groups.TryGetValue(key: groupIndexAmountData, value: out DistanceGroup foundGroup)) { foundGroup.AddMember(prsn); }