/// <summary> /// Stores SETs from a Program in Database. /// </summary> /// <param name="dataSET">SETs from a Specific Program.</param> public void Add(SETS dataSET) { if (dataSET == null) { return; } foreach (var item in dataSET) { if (item is BaseSET) { tableBaseSET.Add(item as BaseSET); } else if (item is NewSET) { tableNewSET.Add(item as NewSET); } else if (item is ReusedSET) { tableReusedSET.Add(item as ReusedSET); } else { continue; } } }
/// <summary> /// Initializes the Data needed to process the Information. /// </summary> /// <param name="data">The data.</param> /// <param name="sets">The sets already generated of the program.</param> /// <param name="probe">The probe of the program.</param> /// <param name="previousPhases">The phases of the previous program.</param> public Phases(Data data, SETS sets, PROBE probe, Phases previousPhases) { this.data = data; this.sets = sets; this.probe = probe; this.previousPhases = previousPhases; //Sets Phases AddRange(new Phase[] { Planning, Design, DesignReview, Code, CodeReview, Compile, Test, Postmortem }); }
/// <summary> /// Gets the SETs Information from the .dat File Data. /// </summary> /// <param name="dataDat">Data (.dat) from the program.</param> /// <returns>Returns the Collection of SETs (Base, New and Reused)</returns> public SETS getSETS(Data dataDat) { var sets = new SETS(dataDat); sets.populate(set => { initialize(set); }); return(sets); }
/// <summary> /// Initializes the Data needed to process the Information. /// </summary> /// <param name="data">The data.</param> /// <param name="previousPhases">The phases of the previous program.</param> /// <param name="sets">The sets already generated of the program.</param> /// <param name="previousSummary">The summary of the previous program.</param> public void initialize(Data data, Phases previousPhases, SETS sets, Summary previousSummary) { this.data = data; this.previousPhases = previousPhases; this.sets = sets; this.previousSummary = previousSummary; ToDateActDef = previousSummary?.ToDateActDef ?? 0; ToDateActLOC = previousSummary?.ToDateActLOC ?? 0; }
/// <summary> /// Gets the Phases Information from the .dat File Data. /// </summary> /// <param name="dataDat">Data (.dat) from the program.</param> /// <param name="sets">SETs Information from the same program.</param> /// <param name="previousPhases">Phases Information from previous program.</param> /// <param name="probe">PROBE Information from the same program.</param> /// <returns>Returns the Phases in the Program.</returns> public IEnumerable <Phase> getPhases(Data dataDat, SETS sets, ref Phases previousPhases, PROBE probe) { //Creates new Phases var phases = new Phases(dataDat, sets, probe, previousPhases); //Populates the Data from SETS, Probe, and the previous Phases phases.populate(phase => initialize(phase)); //Sets phases as the previous for the next time method is invoked previousPhases = phases; return(phases); }
/// <summary> /// Imports a Module/Standard. /// </summary> /// <param name="externalStandard"></param> public static void ProcessStandard(IExternalStandard externalStandard) { log.Info("ModuleImporter.ProcessStandard - basic"); LogManager.Instance.LogDebugMessage("ModuleImporter.ProcessStandard"); SETS_CATEGORY category; int? categoryOrder = 0; var setname = Regex.Replace(externalStandard.ShortName, @"\W", "_"); var documentImporter = new DocumentImporter(); var set = new SETS(); var db = new CSET_Context(); var existingSet = db.SETS.FirstOrDefault(s => s.Set_Name == setname); if (existingSet != null) { // result.LogError("Module already exists. If this is a new version, please change the ShortName field to reflect this."); } category = db.SETS_CATEGORY.FirstOrDefault(s => s.Set_Category_Name.Trim().ToLower() == externalStandard.Category.Trim().ToLower()); if (category == null) { // result.LogError("Module Category is invalid. Please check the spelling and try again."); } else { categoryOrder = category.SETS.Max(s => s.Order_In_Category); } set.Set_Category_Id = category?.Set_Category_Id; set.Order_In_Category = categoryOrder; set.Short_Name = externalStandard.ShortName; set.Set_Name = setname; set.Full_Name = externalStandard.Name; set.Is_Custom = true; set.Is_Question = true; set.Is_Requirement = true; set.Is_Displayed = true; set.IsEncryptedModuleOpen = true; set.IsEncryptedModule = false; set.Is_Deprecated = false; set.Standard_ToolTip = externalStandard.Summary; db.SETS.Add(set); db.SaveChanges(); ProcessRequirements(externalStandard, set); }
/// <summary> /// Gets the Summary Information from Several Sources of Information. /// </summary> /// <param name="dataDat">Data (.dat) from the program.</param> /// <param name="sets">SETs Information from the same program.</param> /// <param name="previousPhases">Phases Information from previous program.</param> /// <param name="previousSummary">Summary Information from previous program.</param> /// <returns>Returns the Summary in the Program.</returns> public Summary getSummary(Data dataDat, SETS sets, ref Phases previousPhases, ref Summary previousSummary) { //Creates a new Summary Summary summary = new Summary(); summary.initialize(dataDat, previousPhases, sets, previousSummary); initialize(summary); //Populates Data from SET, previous Phases and the previous Summary summary.populate(); //Sets summary as the previous for the next time method is invoked previousSummary = summary; return(summary); }
internal void SetFrameworkQuestions(int requirement_ID, CSET_Context controlEntity) { this.FrameworkQuestions.Clear(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); var newQuestionItems = (from nr in controlEntity.NEW_REQUIREMENT from newquestions in nr.NEW_QUESTIONs() join newquestionSets in controlEntity.NEW_QUESTION_SETS on newquestions.Question_Id equals newquestionSets.Question_Id into questionSets join level in controlEntity.UNIVERSAL_SAL_LEVEL on newquestions.Universal_Sal_Level equals level.Universal_Sal_Level1 join subheading in controlEntity.UNIVERSAL_SUB_CATEGORY_HEADINGS on newquestions.Heading_Pair_Id equals subheading.Heading_Pair_Id join questionGroupHeading in controlEntity.QUESTION_GROUP_HEADING on subheading.Question_Group_Heading_Id equals questionGroupHeading.Question_Group_Heading_Id where nr.Requirement_Id == requirement_ID select new { NewRequirement = nr, Question = newquestions, Level = level, QuestionGroupHeading = questionGroupHeading, QuestionSets = questionSets }); foreach (var item in newQuestionItems) { FrameworkQuestionItem questionItem = new FrameworkQuestionItem(); questionItem.QuestionText = item.Question.Simple_Question; questionItem.RequirementID = item.Question.Question_Id; questionItem.SALLevel = item.Level; questionItem.QuestionGroupHeading = item.QuestionGroupHeading; SETS set = item.QuestionSets.OrderBy(x => x.Set_NameNavigation.Order_Framework_Standards).Select(x => x.Set_NameNavigation).FirstOrDefault(); questionItem.Standard = set.Short_Name; questionItem.SetName = set; questionItem.Question = item.Question; questionItem.Reference = "Ref"; this.FrameworkQuestions.Add(questionItem); } stopWatch.Stop(); //CSETLogger.Info("Time to get framework questions Time: " + stopWatch.ElapsedMilliseconds); }
/// <summary> /// Stores SETs from a Program in Data. /// </summary> /// <param name="dataSET">SETs from a Specific Program.</param> public void Add(SETS dataSET) => Add(tableSET, dataSET);
public async Task ProcessCSETAssessmentImport(byte[] zipFileFromDatabase, int currentUserId) { using (CSET_Context context = new CSET_Context()) { //* read from db and set as memory stream here. using (Stream fs = new MemoryStream(zipFileFromDatabase)) { ZipArchive zip = new ZipArchive(fs); StreamReader r = new StreamReader(zip.GetEntry("model.json").Open()); string jsonObject = r.ReadToEnd(); // Apply any data updates to older versions ImportUpgradeManager upgrader = new ImportUpgradeManager(); jsonObject = upgrader.Upgrade(jsonObject); try { UploadAssessmentModel model = (UploadAssessmentModel)JsonConvert.DeserializeObject(jsonObject, new UploadAssessmentModel().GetType()); foreach (var doc in model.CustomStandardDocs) { var genFile = context.GEN_FILE.FirstOrDefault(s => s.File_Name == doc); if (genFile == null) { StreamReader docReader = new StreamReader(zip.GetEntry(doc + ".json").Open()); var docModel = JsonConvert.DeserializeObject <ExternalDocument>(docReader.ReadToEnd()); genFile = docModel.ToGenFile(); var extension = Path.GetExtension(genFile.File_Name).Substring(1); genFile.File_Type_ = context.FILE_TYPE.Where(s => s.File_Type1 == extension).FirstOrDefault(); try { context.FILE_REF_KEYS.Add(new FILE_REF_KEYS { Doc_Num = genFile.Doc_Num }); await context.SaveChangesAsync(); } catch { } context.GEN_FILE.Add(genFile); context.SaveChanges(); } } foreach (var standard in model.CustomStandards) { var sets = context.SETS.Where(s => s.Set_Name.Contains(standard)).ToList(); SETS set = null; StreamReader setReader = new StreamReader(zip.GetEntry(standard + ".json").Open()); var setJson = setReader.ReadToEnd(); var setModel = JsonConvert.DeserializeObject <ExternalStandard>(setJson); var originalSetName = setModel.ShortName; foreach (var testSet in sets) { setModel.ShortName = testSet.Short_Name; var testSetJson = JsonConvert.SerializeObject(testSet.ToExternalStandard(), Formatting.Indented); if (testSetJson == setJson) { set = testSet; break; } else { setModel.ShortName = originalSetName; } } if (set == null) { int incr = 1; while (sets.Any(s => s.Short_Name == setModel.ShortName)) { setModel.ShortName = originalSetName + " " + incr; incr++; } var setResult = await setModel.ToSet(); if (setResult.IsSuccess) { context.SETS.Add(setResult.Result); foreach (var question in setResult.Result.NEW_REQUIREMENT.SelectMany(s => s.NEW_QUESTIONs()).Where(s => s.Question_Id != 0).ToList()) { context.Entry(question).State = EntityState.Unchanged; } try { await context.SaveChangesAsync(); } catch (Exception e) { throw (e); } //Set the GUID at time of export so we are sure it's right!!! model.jANSWER = model.jANSWER.Where(s => s.Is_Requirement).GroupJoin(setResult.Result.NEW_REQUIREMENT, s => s.Custom_Question_Guid, req => new Guid(new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(originalSetName + "|||" + req.Requirement_Title + "|||" + req.Requirement_Text))).ToString(), (erea, s) => { var req = s.FirstOrDefault(); if (req != null) { erea.Question_Or_Requirement_Id = req.Requirement_Id; } return(erea); }).Concat(model.jANSWER.Where(s => !s.Is_Requirement).GroupJoin(setResult.Result.NEW_QUESTION, s => s.Custom_Question_Guid, req => new Guid(new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(req.Simple_Question))).ToString(), (erer, s) => { var req = s.FirstOrDefault(); if (req != null) { erer.Question_Or_Requirement_Id = req.Question_Id; } return(erer); })).ToList(); } } foreach (var availableStandard in model.jAVAILABLE_STANDARDS.Where(s => s.Set_Name == Regex.Replace(originalSetName, @"\W", "_") && s.Selected)) { availableStandard.Set_Name = Regex.Replace(setModel.ShortName, @"\W", "_"); } } string email = context.USERS.Where(x => x.UserId == currentUserId).First().PrimaryEmail; Importer import = new Importer(); int newAssessmentId = import.RunImportManualPortion(model, currentUserId, email, context); import.RunImportAutomatic(newAssessmentId, jsonObject, context); //NOTE THAT THIS ENTRY WILL ONLY COME FROM A OLD .cset file //IMPORT ZipArchiveEntry importLegacyDiagram = zip.GetEntry("Diagram.csetd"); if (importLegacyDiagram != null) { StreamReader ldr = new StreamReader(importLegacyDiagram.Open()); string oldXml = ldr.ReadToEnd(); DiagramManager dm = new DiagramManager(context); dm.ImportOldCSETDFile(oldXml, newAssessmentId); } } catch (Exception e) { throw e; } } } }
private NEW_QUESTION BuildFromNewQuestion(BaseQuestionInfoData infoData, SETS set, CSET_Context controlContext) { NEW_QUESTION question = infoData.Question; NEW_REQUIREMENT requirement = null; RequirementTabData tabData = new RequirementTabData(); string shortStandardName = set.Short_Name; HeaderName = shortStandardName; Question_or_Requirement_Id = infoData.QuestionID; this.LevelName = (from a in controlContext.NEW_QUESTION_SETS.Where(t => t.Question_Id == infoData.QuestionID && t.Set_Name == infoData.Set.Set_Name) join l in controlContext.NEW_QUESTION_LEVELS on a.New_Question_Set_Id equals l.New_Question_Set_Id join u in controlContext.UNIVERSAL_SAL_LEVEL on l.Universal_Sal_Level equals u.Universal_Sal_Level1 orderby u.Sal_Level_Order select u.Full_Name_Sal).FirstOrDefault(); // Gets requirements for the current standard (Set) IEnumerable <NEW_REQUIREMENT> requires = null; if (set.Is_Custom) { //Legacy only var tempRequires = new List <NEW_REQUIREMENT>(); foreach (var setName in set.CUSTOM_STANDARD_BASE_STANDARDBase_StandardNavigation.Select(s => s.Base_Standard).ToList()) { tempRequires = tempRequires.Concat(question.NEW_REQUIREMENTs().Where(t => t.REQUIREMENT_SETS.Select(s => s.Set_Name).Contains(setName)).ToList()).ToList(); } requires = tempRequires; } if (requires == null || !requires.Any()) { requires = from a in controlContext.NEW_REQUIREMENT join b in controlContext.REQUIREMENT_QUESTIONS_SETS on a.Requirement_Id equals b.Requirement_Id where b.Question_Id == infoData.QuestionID && b.Set_Name == set.Set_Name select a; } requirement = requires.FirstOrDefault(); if (requirement != null) { tabData.Set_Name = set.Set_Name; tabData.Text = FormatRequirementText(requirement.Requirement_Text); tabData.RequirementID = requirement.Requirement_Id; if (!IsComponent) { RequirementFrameworkTitle = requirement.Requirement_Title; } RelatedFrameworkCategory = requirement.Standard_Sub_Category; if (RelatedFrameworkCategory == null) { var query = from qgh in controlContext.QUESTION_GROUP_HEADING join usch in controlContext.UNIVERSAL_SUB_CATEGORY_HEADINGS on qgh.Question_Group_Heading_Id equals usch.Question_Group_Heading_Id join q in controlContext.NEW_QUESTION on usch.Heading_Pair_Id equals q.Heading_Pair_Id where q.Question_Id == question.Question_Id select qgh.Question_Group_Heading1; RelatedFrameworkCategory = query.FirstOrDefault(); } tabData.SupplementalInfo = requires.FirstOrDefault(s => !String.IsNullOrEmpty(s.Supplemental_Info))?.Supplemental_Info; tabData.SupplementalInfo = FormatSupplementalInfo(tabData.SupplementalInfo); BuildDocuments(requirement.Requirement_Id, controlContext); } QuestionsVisible = false; ShowRequirementStandards = false; ShowSALLevel = true; RequirementsData = tabData; return(question); }
internal void BuildRelatedQuestionTab(RelatedQuestionInfoData questionInfoData, SETS set, CSET_Context controlContext) { BuildFromNewQuestion(questionInfoData, set, controlContext); ShowRelatedFrameworkCategory = true; ShowRequirementFrameworkTitle = true; RelatedFrameworkCategory = questionInfoData.Category; }
public void BuildQuestionTab(QuestionInfoData infoData, SETS set, CSET_Context controlContext) { ShowRequirementFrameworkTitle = true; BuildFromNewQuestion(infoData, set, controlContext); }
internal void AddSetAndSetStandardName(SETS set) { AddSet(set); SetStandardName(); }
internal void AddSet(SETS set) { this.DictionaryStandards[set.Set_Name] = set; }
public QuestionPoco(ANSWER answer, SETS set, ProfileQuestion profileQuestion) : this(answer) { this.ProfileQuestionData = profileQuestion; this.DictionaryStandards[set.Set_Name] = set; }
/// <summary> /// Clones requirements and their connecting rows into a new Set. /// </summary> /// <param name="copySet"></param> private void CloneRequirements(SETS copySet) { Dictionary <int, int> requirementIdMap = new Dictionary <int, int>(); Dictionary <int, int> questionSetIdMap = new Dictionary <int, int>(); using (var db = new CSET_Context()) { var queryReq = from r in db.NEW_REQUIREMENT from rs in db.REQUIREMENT_SETS.Where(x => x.Requirement_Id == r.Requirement_Id && x.Set_Name == this.origSetName) select new { r, rs }; var originalRequirements = queryReq.ToList(); // Clone NEW_REQUIREMENT and REQUIREMENT_SETS foreach (var origRequirement in originalRequirements) { var newReq = (NEW_REQUIREMENT)db.Entry(origRequirement.r).CurrentValues.ToObject(); newReq.Requirement_Id = 0; db.NEW_REQUIREMENT.Add(newReq); db.SaveChanges(); requirementIdMap.Add(origRequirement.r.Requirement_Id, newReq.Requirement_Id); var copyReqSet = (REQUIREMENT_SETS)db.Entry(origRequirement.rs).CurrentValues.ToObject(); copyReqSet.Requirement_Id = newReq.Requirement_Id; copyReqSet.Set_Name = copySet.Set_Name; db.REQUIREMENT_SETS.Add(copyReqSet); // Clone SAL levels for requirement var dbRL = db.REQUIREMENT_LEVELS .Where(x => x.Requirement_Id == origRequirement.r.Requirement_Id).ToList(); foreach (REQUIREMENT_LEVELS origLevel in dbRL) { var copyLevel = new REQUIREMENT_LEVELS { Requirement_Id = newReq.Requirement_Id, Standard_Level = origLevel.Standard_Level, Level_Type = origLevel.Level_Type, Id = origLevel.Id }; db.REQUIREMENT_LEVELS.Add(copyLevel); } } // Clone REQUIREMENT_QUESTIONS_SETS var dbRQS = db.REQUIREMENT_QUESTIONS_SETS.Where(x => x.Set_Name == origSetName).ToList(); foreach (REQUIREMENT_QUESTIONS_SETS origRQS in dbRQS) { var copyRQS = (REQUIREMENT_QUESTIONS_SETS)db.Entry(origRQS).CurrentValues.ToObject(); copyRQS.Set_Name = copySet.Set_Name; copyRQS.Requirement_Id = requirementIdMap[copyRQS.Requirement_Id]; db.REQUIREMENT_QUESTIONS_SETS.Add(copyRQS); } // Clone NEW_QUESTIONS_SETS var dbQS = db.NEW_QUESTION_SETS.Where(x => x.Set_Name == origSetName).ToList(); foreach (NEW_QUESTION_SETS origQS in dbQS) { var copyQS = (NEW_QUESTION_SETS)db.Entry(origQS).CurrentValues.ToObject(); copyQS.Set_Name = copySet.Set_Name; // default the identity PK copyQS.New_Question_Set_Id = 0; db.NEW_QUESTION_SETS.Add(copyQS); db.SaveChanges(); questionSetIdMap.Add(origQS.New_Question_Set_Id, copyQS.New_Question_Set_Id); } // Clone NEW_QUESTION_LEVELS for the new NEW_QUESTIONS_SETS just created var dbQL = from nql in db.NEW_QUESTION_LEVELS join nqs in db.NEW_QUESTION_SETS on nql.New_Question_Set_Id equals nqs.New_Question_Set_Id where nqs.Set_Name == this.origSetName select nql; var listQL = dbQL.ToList(); foreach (NEW_QUESTION_LEVELS origQL in listQL) { var copyQL = (NEW_QUESTION_LEVELS)db.Entry(origQL).CurrentValues.ToObject(); copyQL.New_Question_Set_Id = questionSetIdMap[origQL.New_Question_Set_Id]; db.NEW_QUESTION_LEVELS.Add(copyQL); } // There is no need to clone UNIVERSAL_SUB_CATEGORY_HEADINGS // because the classification of a Question with a Question Header and a Subcategory // only exists once. The Set it is tied to is the Set where the original // classification was made. // Clone REQUIREMENT_SOURCE_FILES var queryRSF = from rsf in db.REQUIREMENT_SOURCE_FILES join rs in db.REQUIREMENT_SETS on rsf.Requirement_Id equals rs.Requirement_Id where rs.Set_Name == this.origSetName select rsf; var listRSF = queryRSF.ToList(); foreach (var rsf in listRSF) { var newRSF = (REQUIREMENT_SOURCE_FILES)db.Entry(rsf).CurrentValues.ToObject(); newRSF.Requirement_Id = requirementIdMap[newRSF.Requirement_Id]; db.REQUIREMENT_SOURCE_FILES.Add(newRSF); } // Clone REQUIREMENT_REFERENCES var queryRR = from rr in db.REQUIREMENT_REFERENCES join rs in db.REQUIREMENT_SETS on rr.Requirement_Id equals rs.Requirement_Id where rs.Set_Name == this.origSetName select rr; var listRR = queryRR.ToList(); foreach (var rr in listRR) { var newRR = (REQUIREMENT_REFERENCES)db.Entry(rr).CurrentValues.ToObject(); newRR.Requirement_Id = requirementIdMap[newRR.Requirement_Id]; db.REQUIREMENT_REFERENCES.Add(newRR); } db.SaveChanges(); } }
public async Task ProcessCSETAssessmentImport(byte[] zipFileFromDatabase, int currentUserId) { using (CSET_Context web = new CSET_Context()) { //* read from db and set as memory stream here. using (Stream fs = new MemoryStream(zipFileFromDatabase)) { ZipArchive zip = new ZipArchive(fs); StreamReader r = new StreamReader(zip.GetEntry("model.json").Open()); string jsonObject = r.ReadToEnd(); // Apply any data updates to older versions ImportUpgradeManager upgrader = new ImportUpgradeManager(); jsonObject = upgrader.Upgrade(jsonObject); UploadAssessmentModel model = (UploadAssessmentModel)JsonConvert.DeserializeObject(jsonObject, new UploadAssessmentModel().GetType()); foreach (var doc in model.CustomStandardDocs) { var genFile = web.GEN_FILE.FirstOrDefault(s => s.File_Name == doc); if (genFile == null) { StreamReader docReader = new StreamReader(zip.GetEntry(doc + ".json").Open()); var docModel = JsonConvert.DeserializeObject <ExternalDocument>(docReader.ReadToEnd()); genFile = docModel.ToGenFile(); var extension = Path.GetExtension(genFile.File_Name).Substring(1); genFile.File_Type_ = web.FILE_TYPE.Where(s => s.File_Type1 == extension).FirstOrDefault(); try { web.FILE_REF_KEYS.Add(new FILE_REF_KEYS { Doc_Num = genFile.Doc_Num }); await web.SaveChangesAsync(); } catch { } web.GEN_FILE.Add(genFile); web.SaveChanges(); } } foreach (var standard in model.CustomStandards) { var sets = web.SETS.Where(s => s.Set_Name.Contains(standard)).ToList(); SETS set = null; StreamReader setReader = new StreamReader(zip.GetEntry(standard + ".json").Open()); var setJson = setReader.ReadToEnd(); var setModel = JsonConvert.DeserializeObject <ExternalStandard>(setJson); var originalSetName = setModel.ShortName; foreach (var testSet in sets) { setModel.ShortName = testSet.Short_Name; var testSetJson = JsonConvert.SerializeObject(testSet.ToExternalStandard(), Formatting.Indented); if (testSetJson == setJson) { set = testSet; break; } else { setModel.ShortName = originalSetName; } } if (set == null) { int incr = 1; while (sets.Any(s => s.Short_Name == setModel.ShortName)) { setModel.ShortName = originalSetName + " " + incr; incr++; } var setResult = await setModel.ToSet(); if (setResult.IsSuccess) { web.SETS.Add(setResult.Result); foreach (var question in setResult.Result.NEW_REQUIREMENT.SelectMany(s => s.NEW_QUESTIONs()).Where(s => s.Question_Id != 0).ToList()) { web.Entry(question).State = EntityState.Unchanged; } try { await web.SaveChangesAsync(); } catch (Exception e) { throw (e); } //Set the GUID at time of export so we are sure it's right!!! model.jANSWER = model.jANSWER.Where(s => s.Is_Requirement).GroupJoin(setResult.Result.NEW_REQUIREMENT, s => s.Custom_Question_Guid, req => new Guid(new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(originalSetName + "|||" + req.Requirement_Title + "|||" + req.Requirement_Text))).ToString(), (erea, s) => { var req = s.FirstOrDefault(); if (req != null) { erea.Question_Or_Requirement_Id = req.Requirement_Id; } return(erea); }).Concat(model.jANSWER.Where(s => !s.Is_Requirement).GroupJoin(setResult.Result.NEW_QUESTION, s => s.Custom_Question_Guid, req => new Guid(new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(req.Simple_Question))).ToString(), (erer, s) => { var req = s.FirstOrDefault(); if (req != null) { erer.Question_Or_Requirement_Id = req.Question_Id; } return(erer); })).ToList(); } } foreach (var availableStandard in model.jAVAILABLE_STANDARDS.Where(s => s.Set_Name == Regex.Replace(originalSetName, @"\W", "_") && s.Selected)) { availableStandard.Set_Name = Regex.Replace(setModel.ShortName, @"\W", "_"); } } string email = web.USERS.Where(x => x.UserId == currentUserId).First().PrimaryEmail; Importer import = new Importer(); Tuple <int, Dictionary <int, DOCUMENT_FILE> > t = import.RunImport(model, currentUserId, email, web); Dictionary <int, DOCUMENT_FILE> oldIdToNewDocument = t.Item2; foreach (jDOCUMENT_FILE d in model.jDOCUMENT_FILE) { DOCUMENT_FILE docDB = oldIdToNewDocument[d.Document_Id]; string newPath = Path.GetFileName(d.Path);// getPath(d.Path); ZipArchiveEntry entry = zip.GetEntry(newPath); if (entry == null) { entry = zip.GetEntry(d.Path); } if (entry != null) { SaveFileToDB(entry, docDB); } web.SaveChanges(); } } } }
public static ExternalStandard ToExternalStandard(this SETS standard) { var externalStandard = new ExternalStandard(); externalStandard.ShortName = standard.Short_Name; externalStandard.Name = standard.Full_Name; externalStandard.Summary = standard.Standard_ToolTip; externalStandard.Category = standard.Set_Category_.Set_Category_Name; var requirements = new List <ExternalRequirement>(); //Caching for performance using (var db = new CSET_Context()) { //db.Configuration.ProxyCreationEnabled = false; //db.Configuration.AutoDetectChangesEnabled = false; //db.Configuration.LazyLoadingEnabled = false; var reqs = standard.NEW_REQUIREMENT.ToList(); Dictionary <int, List <QuestionAndHeading> > reqQuestions = reqs.Select(s => new { s.Requirement_Id, Questions = s.NEW_QUESTIONs().Select(t => new QuestionAndHeading() { Simple_Question = t.Simple_Question, Heading_Pair_Id = t.Heading_Pair_Id }) }) .ToDictionary(s => s.Requirement_Id, s => s.Questions.ToList()); var reqHeadingIds = reqs.Select(s => s.Question_Group_Heading_Id).ToList(); //var questionHeadings = from a in db.REQUIREMENT_QUESTIONS // join b in db.new on a.Question_Id equals b.Question_Id // join c in db.NEW_QUESTION_SETS on b.Question_Id equals c.Question_Id // where c.Set_Name == standard.Set_Name // select b.question_group_heading_id var questionHeadings = reqQuestions.SelectMany(s => s.Value.Select(t => t.Heading_Pair_Id)).Distinct().ToList(); var reqHeadings = db.QUESTION_GROUP_HEADING.Where(s => reqHeadingIds.Contains(s.Question_Group_Heading_Id)).ToDictionary(s => s.Question_Group_Heading_Id, s => s.Question_Group_Heading1); var headingPairs = db.UNIVERSAL_SUB_CATEGORY_HEADINGS.Where(s => questionHeadings.Contains(s.Heading_Pair_Id)); var subcategories = headingPairs.Join(db.UNIVERSAL_SUB_CATEGORIES, s => s.Universal_Sub_Category_Id, s => s.Universal_Sub_Category_Id, (s, t) => new { s.Heading_Pair_Id, category = t }) .ToDictionary(s => s.Heading_Pair_Id, s => s.category.Universal_Sub_Category); var headings = headingPairs.Join(db.QUESTION_GROUP_HEADING, s => s.Question_Group_Heading_Id, s => s.Question_Group_Heading_Id, (s, t) => new { s.Heading_Pair_Id, category = t }) .ToDictionary(s => s.Heading_Pair_Id, s => s.category.Question_Group_Heading1); var reqReferences = reqs.Select(s => new { s.Requirement_Id, Resources = s.REQUIREMENT_REFERENCES.Select(t => new ExternalResource { Destination = t.Destination_String, FileName = t.Gen_File_.File_Name, PageNumber = t.Page_Number, SectionReference = t.Section_Ref }) }).ToDictionary(t => t.Requirement_Id, t => t.Resources); var reqSource = reqs.Select(s => new { s.Requirement_Id, Resource = s.REQUIREMENT_SOURCE_FILES.Select(t => new ExternalResource { Destination = t.Destination_String, FileName = t.Gen_File_.File_Name, PageNumber = t.Page_Number, SectionReference = t.Section_Ref }).FirstOrDefault() }).ToDictionary(t => t.Requirement_Id, t => t.Resource); var reqLevels = new Dictionary <int, int?>(); var tempLevels = reqs.Select(s => new { s.Requirement_Id, levels = s.REQUIREMENT_LEVELS.Select(t => t.Standard_Level) }).ToList(); if (tempLevels.Any()) { reqLevels = tempLevels.ToDictionary(s => s.Requirement_Id, s => ((s.levels != null && s.levels.Any()) ? s.levels?.Min(t => { SalValues val; if (Enum.TryParse(t, out val)) { return((int)val); } else { return(1); } }) : 1)); } foreach (var requirement in reqs) { var externalRequirement = new ExternalRequirement() { Identifier = requirement.Requirement_Title, Text = requirement.Requirement_Text, Category = requirement.Standard_Category, Weight = requirement.Weight, Subcategory = requirement.Standard_Sub_Category, Supplemental = requirement.Supplemental_Info }; var headingPairId = reqQuestions[requirement.Requirement_Id].Select(s => s.Heading_Pair_Id).FirstOrDefault(s => s != 0); // References var references = externalRequirement.References; reqReferences.TryGetValue(requirement.Requirement_Id, out references); externalRequirement.References = references.ToList(); // Heading string heading = null; headings.TryGetValue(headingPairId, out heading); if (String.IsNullOrEmpty(heading)) { reqHeadings.TryGetValue(requirement.Question_Group_Heading_Id, out heading); } if (String.IsNullOrEmpty(heading)) { throw new Exception("Heading is not valid"); } externalRequirement.Heading = heading; // Questions List <QuestionAndHeading> questions = new List <QuestionAndHeading>(); reqQuestions.TryGetValue(requirement.Requirement_Id, out questions); externalRequirement.Questions = new QuestionList(); foreach (QuestionAndHeading h in questions) { externalRequirement.Questions.Add(h.Simple_Question); } // Subheading string subheading = null; subcategories.TryGetValue(headingPairId, out subheading); if (subheading == null) { subheading = heading; } externalRequirement.Subheading = subheading; // Source var source = externalRequirement.Source; reqSource.TryGetValue(requirement.Requirement_Id, out source); externalRequirement.Source = source; // SAL int?sal; reqLevels.TryGetValue(requirement.Requirement_Id, out sal); externalRequirement.SecurityAssuranceLevel = sal; requirements.Add(externalRequirement); } externalStandard.Requirements = requirements; } return(externalStandard); }
/// <summary> /// Save all Requirements in the specified module. /// </summary> /// <param name="set"></param> /// <param name="db"></param> private static void ProcessRequirements(IExternalStandard externalStandard, SETS set) { var jsonStandard = JsonConvert.SerializeObject(externalStandard, Formatting.Indented); var questionDictionary = new Dictionary <string, NEW_QUESTION>(); var categoryDictionary = new Dictionary <string, STANDARD_CATEGORY>(); var requirementList = new List <string>(); set.NEW_REQUIREMENT = new List <NEW_REQUIREMENT>(); var requirements = set.NEW_REQUIREMENT; int reqSequence = 0; foreach (var requirement in externalStandard.Requirements) { //skip duplicates if (!requirementList.Any(s => s == requirement.Identifier.Trim().ToLower() + "|||" + requirement.Text.Trim().ToLower())) { reqSequence++; var requirementResult = SaveRequirement(requirement, set.Set_Name, reqSequence, new ConsoleLogger()); if (requirementResult != null) { if (requirementResult.Standard_CategoryNavigation != null) { STANDARD_CATEGORY tempCategory; if (categoryDictionary.TryGetValue(requirementResult.Standard_CategoryNavigation.Standard_Category1, out tempCategory)) { requirementResult.Standard_CategoryNavigation = tempCategory; } else { categoryDictionary.Add(requirementResult.Standard_CategoryNavigation.Standard_Category1, requirementResult.Standard_CategoryNavigation); } } foreach (var question in requirementResult.NEW_QUESTIONs().ToList()) { NEW_QUESTION existingQuestion; if (questionDictionary.TryGetValue(question.Simple_Question, out existingQuestion)) { requirementResult.REQUIREMENT_QUESTIONS.Remove(new REQUIREMENT_QUESTIONS() { Question_Id = question.Question_Id, Requirement_Id = requirementResult.Requirement_Id }); } else { questionDictionary.Add(question.Simple_Question, question); } } requirementList.Add(requirementResult.Requirement_Title.Trim().ToLower() + "|||" + requirementResult.Requirement_Text.Trim().ToLower()); requirements.Add(requirementResult); } else { // requirementResult.ErrorMessages.ToList().ForEach(s => result.LogError(s)); } } } }