public static List <Uirule> ImportVersionRules(DBBuffer _buffer, Paths Paths, string log) { List <Uirule> result = new List <Uirule>(); var filename = "REQUIREMENTS.txt"; Provider.WriteImportLogFormat(log, filename); try { var file = Provider.CreateFile(Paths.importFilePath + "\\" + filename); // first line contains column names foreach (List <string> riga in file.Skip(1)) { var tmpRule = new Uirule(); tmpRule.Allow = AllowModes.No; tmpRule.RuleOrigin = ruleOrigins.Requirements; if (!string.IsNullOrEmpty(riga[0])) { tmpRule.Version = ComparableFields.GetStringVersion(ComparableFields.GetNumericVersionFromMajor(Convert.ToDouble(riga[0]))); } FillRuleFromFile(tmpRule, 1, riga, _buffer); IsOkToAddRule(tmpRule, _buffer); result.Add(tmpRule); } } catch (Exception ex) { throw new ParsingException(filename, ex); } return(result); }
// import probes from probelists of different settings families public static List <ProbeBind> Import(DBBuffer _buffer, Paths Paths, string LogXml2DB) { Provider.WriteLogFormat(LogXml2DB, "Import Probes from probelist"); List <ProbeBind> result = new List <ProbeBind>(); List <ProbeBind> validProbesBinds, newProbes, oldProbes; try { foreach (var setting in _buffer.p_settingsFamilies) { var swpackName = _buffer.p_swPacks.SingleOrDefault(swp => swp.Id == setting.SwpackId).Name; var probeLst = Provider.readProbeList(swpackName, setting, Paths); validProbesBinds = probeLst.Descendants("elemento").Where(x => x.Element("sSaleName").Value != "NULLSTRING") .Select(p => FromXElement2ProbeBind(p, setting)).ToList(); // select old probes from previously inserted probes oldProbes = result.Where(x => validProbesBinds.Select(p => p.probe.SaleName.ToLowerInvariant()).Contains(x.probe.SaleName.ToLowerInvariant())).ToList(); updateProbes(oldProbes, validProbesBinds, setting); // select new probes from the new probeList newProbes = validProbesBinds.Where(p => !result.Select(x => x.probe.SaleName.ToLowerInvariant()).Contains(p.probe.SaleName.ToLowerInvariant())).ToList(); completeNewProbes(newProbes); result.AddRange(newProbes); } return(result); } catch (Exception ex) { throw new ParsingException("Probelist", ex); } }
public static List <RegulatoryFeature> Import(DBBuffer _buffer, Paths paths, string LogXml2DB) { var fileName = "REGULATORY-FEATURES.txt"; Provider.WriteImportLogFormat(LogXml2DB, fileName); List <List <String> > file = Provider.CreateFile(paths.importFilePath + "\\" + fileName); var result = new List <RegulatoryFeature>(); int RowIndex = -2, ColumnIndex = -2; try { var FeatureNames = file[0]; for (RowIndex = 1; RowIndex < file.Count; RowIndex++) { for (ColumnIndex = 0; ColumnIndex < FeatureNames.Count; ColumnIndex++) { if (!string.IsNullOrEmpty(file[RowIndex][ColumnIndex])) { var Feature = _buffer.GetFeatureFromName(file[RowIndex][ColumnIndex]); result.Add(new RegulatoryFeature { Name = FeatureNames[ColumnIndex], FeatureId = Feature.Id }); } } } return(result); } catch (Exception ex) { throw new ParsingException(fileName + " at row " + (RowIndex + 1).ToString() + " column " + (ColumnIndex + 1).ToString(), ex); } }
public static List <CountryDistributor> Import(DBBuffer _buffer, Paths Paths, string log) { var fileName = "Country_Distributor.txt"; Provider.WriteImportLogFormat(log, fileName); List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); var result = new List <CountryDistributor>(); try { // first line contains column names foreach (List <string> riga in file.Skip(1)) { result.Add(new CountryDistributor { CountryId = _buffer.p_countries.Single(c => c.Code == riga[0].Trim()).Id, DistributorId = _buffer.p_Distributors.Single(c => c.Code == riga[1].Trim()).Id }); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
public static List <Country> Import(DBBuffer _buffer, Paths paths, string LogXml2DB) { List <Country> countries = new List <Country>(); var fileName = "Countries.txt"; Provider.WriteImportLogFormat(LogXml2DB, fileName); try { List <List <String> > CountryFile = Provider.CreateFile(paths.importFilePath + "\\" + fileName); // import countries foreach (List <string> riga in CountryFile.Skip(1)) { countries.Add(new Country { Code = riga[0], Name = riga[1], IsObsolete = Convert.ToBoolean(riga[2].Trim().ToLowerInvariant()) }); } SetCertifier(countries, "CE", paths.importFilePath + "\\CE.txt", _buffer, LogXml2DB); SetCertifier(countries, "APA", paths.importFilePath + "\\ANY-PRODUCT-ALLOWED.txt", _buffer, LogXml2DB); SetCertifier(countries, "STA", paths.importFilePath + "\\STALLING.txt", _buffer, LogXml2DB); return(countries); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
/// Clone rule for each child of the Option bundle private List <NormalRule> cloneFromParentOption(NormalRule nr, DBBuffer _buffer) { if (this.OptionId.HasValue) { var childOptionId = _buffer.p_bundles.Where(x => x.ParentFeatureId == _buffer.p_option.Single(o => o.Id == this.OptionId).FeatureId). Join(_buffer.p_option, b => b.FeatureId, o => o.FeatureId, (b, o) => o.Id).ToList(); if (childOptionId.Count > 0) { List <NormalRule> cloni = new List <NormalRule>(); cloni.Add(nr); // add the rule for the parent foreach (var kidId in childOptionId) { NormalRule tmpRule = new NormalRule(nr); tmpRule.OptionId = kidId; cloni.Add(tmpRule); } return(cloni); } } // if nothing was to be done, retunr the input rule itself return(new List <NormalRule> { nr }); }
/// <summary> /// Import UIRules from file /// /// *THIS CODE SHOULD BE AUTOMATICALLY GENERATED BY THE TEXT TEMPLATE* /// /// </summary> public static List <Uirule> Import(String fileName, DBBuffer _buffer, ruleOrigins _rOrigin, Paths Paths) { List <Uirule> result = new List <Uirule>(); try { List <List <String> > file = Provider.CreateFile(Paths.importFilePath + fileName); Dictionary <string, AllowModes> dictAllowModes = new Dictionary <string, AllowModes> { { "A", AllowModes.A }, { "Def", AllowModes.Def }, { "No", AllowModes.No }, }; // first line contains column names foreach (List <string> riga in file.Skip(1)) { result.Add(new Uirule { Allow = dictAllowModes[riga[0]], RuleName = String.IsNullOrEmpty(riga[1]) ? null : riga[1], PhysicalModelId = String.IsNullOrEmpty(riga[2]) ? null : (Int32?)_buffer.p_physicalModels.Single(pm => pm.Description == riga[2]).Id, LogicalModelId = String.IsNullOrEmpty(riga[3]) ? null : (Int32?)_buffer.p_logicalModels.Single(lm => lm.Name == riga[3]).Id, ApplicationId = String.IsNullOrEmpty(riga[4]) ? null : (Int32?)_buffer.p_applications .ToList() .Join(_buffer.p_features, o => o.FeatureId, f => f.Id, (o, f) => new { app = o, feature = f }) .Single(fo => fo.feature.NameInCode == riga[4]).app.Id, OptionId = String.IsNullOrEmpty(riga[5]) ? null : (Int32?)_buffer.p_option .ToList() .Join(_buffer.p_features, o => o.FeatureId, f => f.Id, (o, f) => new { option = o, feature = f }) .Single(fo => fo.feature.NameInCode == riga[5]).option.Id, UserLevel = String.IsNullOrEmpty(riga[6]) ? null : (UserLevel?)Convert.ToInt16(riga[6]), Version = String.IsNullOrEmpty(riga[7]) ? null : riga[7], ProbeId = String.IsNullOrEmpty(riga[8]) ? null : (Int32?)_buffer.p_probes.Single(p => p.SaleName == riga[8]).Id, CertifierId = String.IsNullOrEmpty(riga[9]) ? null : (Int32?)_buffer.p_certifiers.Single(ce => ce.Name == riga[9]).Id, CountryId = String.IsNullOrEmpty(riga[10]) ? null : (Int32?)_buffer.p_countries.Single(c => c.Name == riga[10]).Id, KitId = String.IsNullOrEmpty(riga[11]) ? null : (Int32?)_buffer.p_biospyKits.Single(k => k.Name == riga[11]).Id, TransducerType = String.IsNullOrEmpty(riga[12]) ? null : (ProbeType?)Convert.ToInt16(riga[12]), DistributorId = String.IsNullOrEmpty(riga[13]) ? null : (Int32?)_buffer.p_Distributors.Single(k => k.Name == riga[13]).Id, RuleOrigin = _rOrigin }); } } catch (Exception ex) { throw new ApplicationException("error while reading UIRules: " + ex.Message); } return(result); }
public static List <Uirule> ImportProbeAppRules(FeaturesContext _db, DBBuffer _buffer, Paths Paths, string LogXml2DB) { Provider.WriteImportLogFormat(LogXml2DB, "Read Probe-Applications relations"); string settingsName = "", ProbeName = ""; try { // ANTO DB _buffer.p_probe_SettingsFamily = _db.ProbeSettingsFamily.ToList(); var num_sf = _buffer.p_settingsFamilies.Count; var resultProbeApp = new List <ProbePreset> [num_sf]; Parallel.For(0, num_sf, sfindex => { settingsName = _buffer.p_settingsFamilies[sfindex].Name; String swPackName = _buffer.p_swPacks.Single(s => s.Id == _buffer.p_settingsFamilies[sfindex].SwpackId).Name; // select current probeList and join it with probeBind and probe Id already inserted in the DB List <ProbeBind> currentProbeList = _buffer.p_probe_SettingsFamily.Where(x => x.SettingsFamilyId == _buffer.p_settingsFamilies[sfindex].Id). Join(_buffer.p_probes, ps => ps.ProbeId, p => p.Id, (ps, p) => p).ToList(). Join(_buffer.probeBindLst, p => p.SaleName, x => x.probe.SaleName, (p, x) => new ProbeBind(p, x.probeInfoLst)).ToList(); resultProbeApp[sfindex] = new List <ProbePreset>(); foreach (ProbeBind probeBind in currentProbeList) // loop probes in probelist to complete probe and add probeApplication association { var currentProbeSetting = _buffer.p_probe_SettingsFamily.Single(x => x.ProbeId == probeBind.probe.Id && x.SettingsFamilyId == _buffer.p_settingsFamilies[sfindex].Id); var probeDescEquip = (Provider.readProbeDescr(swPackName, currentProbeSetting, Paths)).Descendants("equipment").First(); ProbeName = probeBind.probe.SaleName; probeBind.probe.Biplane = Convert.ToBoolean(probeDescEquip.Element("fBiplane").Value); // complete probe field currentProbeSetting.ProbeDataFileNameFrontal = probeDescEquip.Element("sProbeDataFileNameFrontal").Value.ToString(); currentProbeSetting.ProbeDataFileNameLateral = probeDescEquip.Element("sProbeDataFileNameLateral").Value.ToString() == "NULLFILE" ? null : probeDescEquip.Element("sProbeDataFileNameLateral").Value.ToString(); // fill appNode for the current settings family in the current probe var currentProbeInfo = probeBind.getProbeInfo(_buffer.p_settingsFamilies[sfindex]); currentProbeInfo.appNodes = probeDescEquip.Element("sApplicationDesc").Elements("element") .Where(a => a.Element("eApplication").Value.ToString() != "APPL_INVALID_PD").ToList(); resultProbeApp[sfindex].AddRange(createProbeApps(probeBind, currentProbeInfo, _buffer)); } }); return(finalizeImport(resultProbeApp.SelectMany(rp => rp).ToList(), _db, _buffer)); } catch (Exception ex) { throw new ParsingException("Probe-Applications relations for settings family " + settingsName + " probe " + ProbeName, ex); } }
// generate rules for options associated to probes (and related forbidden probes) public static List <Uirule> ImportOptionProbes(DBBuffer _buffer, Paths Paths, string log) { List <Uirule> result = new List <Uirule>(); var filename = "OptionProbeRules.txt"; Provider.WriteImportLogFormat(log, filename); try { List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + filename); var Options = file.Skip(1).GroupBy(r => r[0]); // first line contains column names foreach (var OptionGroup in Options) { var OptionId = _buffer.p_option.Single(o => o.Name == OptionGroup.Key).Id; var AvailableProbes = OptionGroup.ToList().Join(_buffer.p_probes, r => r[1], p => p.SaleName, (r, p) => p).ToList(); var ForbiddenProbes = _buffer.p_probes.Except(AvailableProbes).ToList(); // allow for all listed probes foreach (var AvailableProbe in AvailableProbes) { result.Add(new Uirule() { Allow = AllowModes.Def, OptionId = OptionId, ProbeId = AvailableProbe.Id, RuleOrigin = ruleOrigins.InputOptionProbeRule }); } // forbid the missing probes foreach (var forbiddenProbe in ForbiddenProbes) { result.Add(new Uirule() { Allow = AllowModes.No, OptionId = OptionId, ProbeId = forbiddenProbe.Id, RuleOrigin = ruleOrigins.InputOptionProbeRule }); } } } catch (Exception ex) { throw new ParsingException(filename, ex); } return(result); }
/// converts the UIRule to the list of corresponding normalized rules public List <NormalRule> ToNormalRule(DBBuffer _buffer) { List <NormalRule> nrules = new List <NormalRule>(); nrules.Add(ToSingleNormalRule()); var functionList = new List <Func <NormalRule, List <NormalRule> > > { nr => { return(cloneFromPhysModel(nr, _buffer)); }, nr => { return(cloneFromCertifier(nr, _buffer)); }, nr => { return(cloneFromParentApplication(nr, _buffer)); }, nr => { return(cloneFromParentOption(nr, _buffer)); } }; nrules = ToNormalRule(functionList, nrules); return(nrules); }
public static List <LicenseRelationException> Import(DBBuffer buffer, Paths Paths, string log) { var fileName = "LicenseRelationExceptions.txt"; Provider.WriteImportLogFormat(log, fileName); var file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); var result = new List <LicenseRelationException>(); try { foreach (List <string> riga in file.Skip(1)) // first line contains column names { var l_LicenseRelation = LicenseRelation.ReadLicenseRelation(buffer, riga); var currentLr = buffer.p_LicenseRelation.Single(lr => lr.ParentFeatureId == l_LicenseRelation.ParentFeatureId && lr.FeatureId == l_LicenseRelation.FeatureId && lr.ParentType == l_LicenseRelation.ParentType && lr.HiderType == l_LicenseRelation.HiderType); if (currentLr != null) { var lmodel = buffer.p_logicalModels.Single(lm => lm.Name == riga[4].Trim()); if (lmodel != null) { result.Add(new LicenseRelationException { LicenseRelationId = currentLr.Id, LogicalModelId = buffer.p_logicalModels.Single(lm => lm.Name == riga[4].Trim()).Id }); } else { throw new Exception(Provider.WriteErrorLogFormat("Model " + riga[4] + " was not recognized.")); } } else { throw new Exception(Provider.WriteErrorLogFormat("License Relation " + riga[0] + " - " + riga[1] + " - " + riga[2] + " - " + riga[3] + " does not exist")); } } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
public static LicenseRelation ReadLicenseRelation(DBBuffer buffer, List <string> riga) { var ParentFeature = buffer.p_features.SingleOrDefault(fl => fl.Name == riga[0].Trim()); var Feature = buffer.p_features.SingleOrDefault(fl => fl.Name == riga[1].Trim()); if (ParentFeature != null && Feature != null && ParentFeature.LicenseId != null && Feature.LicenseId != null) { return(new LicenseRelation { FeatureId = Feature.Id, ParentFeatureId = ParentFeature.Id, ParentType = dictParenTypes[riga[2].Trim()], HiderType = dictHiderTypes[riga[3].Trim()] }); } else { throw new Exception(Provider.WriteErrorLogFormat("Check License Relation " + riga[0] + " - " + riga[1] + ": all features should be under license.")); } }
public static List <LicenseRelation> Import(DBBuffer buffer, Paths Paths, string log) { var fileName = "LicenseRelations.txt"; Provider.WriteImportLogFormat(log, fileName); List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); List <LicenseRelation> result = new List <LicenseRelation>(); var LicensedFeatures = buffer.p_features.Join(buffer.p_licenses, f => f.LicenseId, l => l.Id, (f, l) => f).ToList(); try { foreach (List <string> riga in file.Skip(1)) // first line contains column names { result.Add(ReadLicenseRelation(buffer, riga)); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
public static List <CountryLicense> Import(DBBuffer _buffer, Paths Paths, string log) { var fileName = "CountryLicenses.txt"; Provider.WriteImportLogFormat(log, fileName); List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); var result = new List <CountryLicense>(); try { // first line contains column names foreach (List <string> riga in file.Skip(1)) { var country = _buffer.p_countries.Single(c => c.Code == riga[0].Trim()); int?distributorId = null; if (!string.IsNullOrEmpty(riga[1].Trim())) { var distributor = _buffer.p_Distributors.Single(d => d.Code == riga[1].Trim()); distributorId = distributor.Id; if (!_buffer.p_Country_Distributors.Any(cd => cd.CountryId == country.Id && cd.DistributorId == distributor.Id)) { throw new Exception("Countruy_Distributor table does not contain associatio between " + country.Name + " and " + distributor.Name); } } result.Add(new CountryLicense { CountryId = country.Id, DistributorId = distributorId, LicenseId = _buffer.p_licenses.Single(l => l.Name == riga[2].Trim()).Id }); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
/// Clone Normalized Rules for each logical model included in the physical model private List <NormalRule> cloneFromPhysModel(NormalRule nr, DBBuffer _buffer) { if (this.PhysicalModelId.HasValue) { var logicalModelsId = _buffer.p_logicalModels.Where(lm => lm.PhModId == this.PhysicalModelId).Select(x => x.Id).ToList(); if (logicalModelsId.Count > 0) { List <NormalRule> cloni = new List <NormalRule>(); foreach (var lmodel in logicalModelsId) { NormalRule tmpRule = new NormalRule(nr); tmpRule.LogicalModelId = lmodel; cloni.Add(tmpRule); } return(cloni); } } // if nothing was to be done, return the input rule itself return(new List <NormalRule> { nr }); }
/// Clone Normalized Rules for each country associated with the certifier private List <NormalRule> cloneFromCertifier(NormalRule nr, DBBuffer _buffer) { if (this.CertifierId.HasValue) { var CountriesId = _buffer.p_countries.Where(c => c.CertifierId == this.CertifierId).Select(x => x.Id).ToList(); if (CountriesId.Count > 0) { List <NormalRule> cloni = new List <NormalRule>(); foreach (var country in CountriesId) { NormalRule tmpRule = new NormalRule(nr); tmpRule.CountryId = country; cloni.Add(tmpRule); } return(cloni); } } // if nothing was to be done, retunr the input rule itself return(new List <NormalRule> { nr }); }
// Gibiino [RTC 12169] private static void IsOkToAddRule(Uirule uirule, DBBuffer buffer) { // Make sure the AlwaysPresent features are not blocked by the version FeatureRegister.FeatureType FeatureType; var feature = uirule.GetFeature(buffer, out FeatureType); if (feature.AlwaysPresent == true) { var tmpNormalRules = uirule.ToNormalRule(buffer); var dummyRule = new NormalRule(); dummyRule.SetFieldFromType(FeatureType, uirule); dummyRule.Version = 0; // Checks if the only specified fields are feature and version foreach (var trule in tmpNormalRules) { if (ComparableFields.isContained(dummyRule, trule)) { throw new Exception(buffer.p_features.Single(o => o.Id == feature.Id).Name + " feature cannot be blocked unti version " + uirule.Version); } } } }
private static List <Uirule> finalizeImport(List <ProbePreset> resultProbeApp, FeaturesContext _db, DBBuffer _buffer) { // ANTO DB // for the changes in the probe table //_db.SubmitChanges(); _db.SaveChanges(); // insert probe_applications and create UIRules for them // _db.BulkInsert(resultProbeApp); // _db.ProbePreset.AddRange(resultProbeApp); _db.BulkInsert(resultProbeApp); var result = _db.createProbeAppRules(resultProbeApp, _buffer); _buffer.p_probe_Apps = resultProbeApp.Join(_buffer.p_applications, x => x.ApplicationId, a => a.Id, (x, a) => new ProbeApp(x.ProbeId, x.SettingsFamilyId, a)).ToList(); return(result); }
//@PD Added default parameter for program ManualsZipper where Db is not necessary public static List <LogicalModel> Import(Dictionary <String, Int32> dictPhysMod, Dictionary <String, Int32> dictLicense, DBBuffer buffer, Paths Paths, string log, bool p_Db = true) { var fileName = "LogicalModel.txt"; Provider.WriteImportLogFormat(log, fileName); List <List <String> > file = new List <List <string> >(); if (p_Db) { file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); } else { file = Provider.CreateFile(Paths.RootPath + "\\" + fileName); } List <LogicalModel> result = new List <LogicalModel>(); Dictionary <string, SystemEnvironment> dictTipi = new Dictionary <string, SystemEnvironment> { { "HUMAN", SystemEnvironment.Human }, { "VET", SystemEnvironment.Veterinary }, }; Dictionary <string, PhysicalSubModel> PhysModDice = new Dictionary <string, PhysicalSubModel> { { "Model_00", PhysicalSubModel.Model_00 }, { "Model_01", PhysicalSubModel.Model_01 }, { "Model_02", PhysicalSubModel.Model_02 }, { "Model_03", PhysicalSubModel.Model_03 }, { "Model_04", PhysicalSubModel.Model_04 } }; try { // first line contains column names foreach (List <string> riga in file.Skip(1)) { int?settfamid = null; if (p_Db) { var swpk = buffer.p_swPacks.SingleOrDefault(sw => sw.Name == riga[10].Trim()); if (swpk != null) { settfamid = buffer.p_settingsFamilies.Single(sf => sf.Name == riga[3].Trim() && sf.SwpackId == swpk.Id).Id; } } result.Add(new LogicalModel { Name = riga[0].Trim(), ModelFamily = riga[1].Trim(), PhModId = Provider.GetValueOrDefault_Stuct(dictPhysMod, riga[2].Trim()), SettingsFamilyId = settfamid, SubPhysModel = PhysModDice[riga[4].Trim()], // ANTO CAST Type = Provider.GetValueOrDefault_Stuct(dictTipi, riga[5].Trim()), // ANTO CAST IsDefault = Convert.ToBoolean(riga[6].Trim().ToLowerInvariant()), LicenseId = Provider.GetValueOrDefault_Stuct(dictLicense, riga[7].Trim()), StyleName = riga[8].Trim(), ContexVisionModule = Provider.FromStringToEnum <CVModule>(riga[9].Trim(), CVModule.DSPModule), // ANTO CAST ModelID = riga[7].Trim(), SwPack = riga[10].Trim() }); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }
// reads probe preset name and location for the current application private static List <ProbePreset> createProbeApps(ProbeBind probeBind, probeInfo currentProbeInfo, DBBuffer _buffer) { List <ProbePreset> resultProbeApp = new List <ProbePreset>(); foreach (var app in currentProbeInfo.appNodes) { Application application = _buffer.p_applications.SingleOrDefault(a => a.ProbeDescrName == app.Element("eApplication").Value.ToString()); ProbePreset baseProbeApp = new ProbePreset() { ProbeId = probeBind.probe.Id, ApplicationId = application.Id, SettingsFamilyId = currentProbeInfo.settingsFam.Id }; resultProbeApp.AddRange(createPresetProbeApps(baseProbeApp, app)); } return(resultProbeApp); }
public static List <PartNumbersAssociations> Import(Paths Paths, DBBuffer buffer, string log) { var result = new List <PartNumbersAssociations>(); var fileName = "PartNumbers.txt"; Provider.WriteImportLogFormat(log, fileName); List <string> currentrow = null; try { List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); foreach (List <string> riga in file.Skip(1)) { currentrow = riga; var LogModIndexex = new List <int?>(); int?FeatureId = null; if (!string.IsNullOrEmpty(riga[1])) { FeatureId = buffer.p_features.Single(f => f.NameInCode == riga[1].Trim()).Id; } if (!string.IsNullOrEmpty(riga[3]) && !string.IsNullOrEmpty(riga[4].Trim())) { throw new Exception(riga[3] + " and " + riga[4] + " cannot be specified in the same line, pick only one."); } else { if (!string.IsNullOrEmpty(riga[3])) { LogModIndexex.Add(buffer.p_logicalModels.Single(l => l.Name == riga[3].Trim()).Id); } else if (!string.IsNullOrEmpty(riga[4])) { var pmid = buffer.p_physicalModels.Single(m => m.Description == riga[4].Trim()).Id; LogModIndexex = buffer.p_logicalModels.Where(l => l.PhModId == pmid).Select(l => (int? )l.Id).ToList(); } else { LogModIndexex.Add(null); } } foreach (var modelindex in LogModIndexex) { result.Add(new PartNumbersAssociations { PartNumber = riga[0].Trim(), FeatureId = FeatureId, FeatureBosname = riga[2].Trim(), LogicalModelId = modelindex, ToExport = Convert.ToBoolean(riga[5].Trim().ToLowerInvariant()), ModeTypeToExport = riga[6].Trim() == "" ? null : riga[6].Trim() }); } } var DuplicateAssociations = result.GroupBy(r => new { pn = r.PartNumber, fid = r.FeatureId, lmid = r.LogicalModelId, toe = r.ToExport }).Where(y => y.Count() > 1).ToList(); if (DuplicateAssociations.Count > 1) { throw new ApplicationException("Found duplicates in PartNumbers: \r\n" + DuplicateAssociations.Select(x => x.Key.pn + " " + buffer.p_features.Single(f => f.Id == x.Key.fid).Name + " " + buffer.p_logicalModels.Single(l => l.Id == x.Key.lmid).Name) .Aggregate((i, j) => i + "; \r\n" + j)); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex, currentrow); } }
public static List <Uirule> ImportRegulatoryRules(DBBuffer _buffer, Paths Paths, string log) { var result = new List <Uirule>(); var fileName = "RegulatoryExceptionsMatrix.txt"; Provider.WriteImportLogFormat(log, fileName); try { var file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); // first line contains column names foreach (List <string> riga in file.Skip(2)) { var tmpRule = new Uirule(); tmpRule.Allow = AllowModes.No; tmpRule.RuleOrigin = ruleOrigins.Regulatory; // parse rule only for recognized model (avoid MRI models) var stringmodel = riga[1].Trim(); var model = _buffer.p_logicalModels.SingleOrDefault(l => l.Name == stringmodel); if (model != null) { tmpRule.LogicalModelId = model.Id; } else { continue; } var countrycode = riga[0].Trim(); var country = _buffer.p_countries.SingleOrDefault(x => x.Code == countrycode); if (country != null) { tmpRule.CountryId = country.Id; } var stringfeature = riga[3].Trim(); var feature = _buffer.p_features.SingleOrDefault(f => f.Name == stringfeature); if (feature != null) { var application = _buffer.p_applications.SingleOrDefault(x => x.FeatureId == feature.Id); var option = _buffer.p_option.SingleOrDefault(x => x.FeatureId == feature.Id); var kit = _buffer.p_biospyKits.SingleOrDefault(x => x.FeatureId == feature.Id); if (application != null) { tmpRule.ApplicationId = application.Id; } if (option != null) { tmpRule.OptionId = option.Id; } if (kit != null) { tmpRule.KitId = kit.Id; } } var probename = riga[4].Trim(); var probe = _buffer.p_probes.SingleOrDefault(p => p.SaleName == probename); if (probe != null) { tmpRule.ProbeId = probe.Id; } result.Add(tmpRule); } } catch (Exception ex) { throw new ParsingException(fileName, ex); } return(result); }
// this file is tipically used to block some features in countries where a patent is protecting them public static List <Uirule> ImportRDBlockingRules(DBBuffer _buffer, Paths Paths, string log) { var result = new List <Uirule>(); var fileName = "BLOCKED_FEATURES-COUNTRIES_RD.txt"; Provider.WriteImportLogFormat(log, fileName); List <string> CurrentRow = null; try { var file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); // first line contains column names foreach (List <string> riga in file.Skip(1)) { CurrentRow = riga; var tmpRule = new Uirule(); tmpRule.Allow = AllowModes.No; tmpRule.RuleOrigin = ruleOrigins.RDCountryBlock; FillRuleFromFile(tmpRule, 0, riga, _buffer); var l_Country = riga[6]; var l_Distributor = riga[7]; var l_Certifier = riga[8]; var IsCountryPresent = !string.IsNullOrEmpty(riga[6]); var IsCertifierPresent = !string.IsNullOrEmpty(riga[8]); var IsUserPresent = !string.IsNullOrEmpty(riga[9]); if (IsCountryPresent && IsCertifierPresent) { throw new Exception("Cannot specify both cerifier and country: " + l_Country + ", " + l_Certifier); } if (IsCountryPresent) { tmpRule.CountryId = _buffer.p_countries.Single(c => c.Code == l_Country).Id; } if (!string.IsNullOrEmpty(l_Distributor)) { tmpRule.DistributorId = _buffer.p_Distributors.Single(c => c.Code == l_Distributor).Id; } if (IsCertifierPresent) { tmpRule.CertifierId = _buffer.p_certifiers.Single(c => c.Code == l_Certifier).Id; } if (IsUserPresent) { tmpRule.UserLevel = Provider.FromStringToEnum <UserLevel>(riga[9], Xml2DbMapper.Core.Porting.Contract.Enums.UserLevel.Unknown); } result.Add(tmpRule); } } catch (Exception ex) { throw new ParsingException(fileName, ex, CurrentRow); } return(result); }
//private static List<UIRule> GetRegulatoryRules(List<UIRule> BaseRules, string RegulatoryFeatureName, DBBuffer _buffer) //{ // var result = new List<UIRule>(); // var ChildFeatureIDs = _buffer.p_RegualtoryFeatures.Where(rf => rf.Name == RegulatoryFeatureName).Select(x => x.FeatureId).ToList(); // foreach (var BaseRule in BaseRules) // { // foreach (var ChildFeatureID in ChildFeatureIDs) // { // var tmpRule = new UIRule(BaseRule); // _buffer.SetRuleFeatureField(tmpRule, ChildFeatureID); // result.Add(tmpRule); // } // } // return result; //} private static void FillRuleFromFile(Uirule tmpRule, int StartingIndex, List <string> riga, DBBuffer _buffer) { if (!string.IsNullOrEmpty(riga[StartingIndex])) { tmpRule.OptionId = _buffer.p_option.Single(p => p.Name == riga[StartingIndex]).Id; } if (!string.IsNullOrEmpty(riga[StartingIndex + 1])) { tmpRule.ApplicationId = _buffer.p_applications.Single(p => p.Name == riga[StartingIndex + 1]).Id; } if (!string.IsNullOrEmpty(riga[StartingIndex + 2])) { tmpRule.ProbeId = _buffer.p_probes.Single(p => p.SaleName == riga[StartingIndex + 2]).Id; } if (!string.IsNullOrEmpty(riga[StartingIndex + 3])) { tmpRule.KitId = _buffer.p_biospyKits.Single(p => p.Name == riga[StartingIndex + 3]).Id; } if (!string.IsNullOrEmpty(riga[StartingIndex + 4])) { tmpRule.LogicalModelId = _buffer.p_logicalModels.Single(p => p.Name == riga[StartingIndex + 4]).Id; } if (!string.IsNullOrEmpty(riga[StartingIndex + 5])) { tmpRule.PhysicalModelId = _buffer.p_physicalModels.Single(p => p.Description == riga[StartingIndex + 5]).Id; } }
private static void SetCertifier(List <Country> countries, string CertifierCode, string CertifierAssociatonFileName, DBBuffer _buffer, string LogXml2DB) { Provider.WriteImportLogFormat(LogXml2DB, "Certifier countries for " + CertifierCode); try { List <List <String> > CEFile = Provider.CreateFile(CertifierAssociatonFileName); var CECertifierID = _buffer.p_certifiers.Single(ce => ce.Code == CertifierCode).Id; foreach (List <string> CErow in CEFile) { countries.Single(c => c.Code == CErow[0].Trim() && c.Name == CErow[1].Trim()).CertifierId = CECertifierID; } } catch (Exception ex) { throw new ParsingException("countries for certifier code " + CertifierCode, ex); } }
public static List <FeatureRelation> Import(Dictionary <String, int> dictFeat, Paths Paths, string log, DBBuffer buffer) { var fileName = "FeatureRelations.txt"; Provider.WriteImportLogFormat(log, fileName); List <List <String> > file = Provider.CreateFile(Paths.importFilePath + "\\" + fileName); var result = new List <FeatureRelation>(); try { // first line contains column names foreach (List <string> riga in file.Skip(1)) { var parentfeatureid = dictFeat[riga[0].Trim()]; var parentfeature = buffer.p_features.Single(f => f.Id == parentfeatureid); if (parentfeature.LicenseId == null) { throw new ApplicationException(parentfeature.Name + " is not associated with any license."); } result.Add(new FeatureRelation { FeatureId = dictFeat[riga[1].Trim()], ParentFeatureId = parentfeatureid }); } return(result); } catch (Exception ex) { throw new ParsingException(fileName, ex); } }