public void BuildComponentInfoTab(ComponentQuestionInfoData info, CSET_Context controlContext)
        {
            try
            {
                IsComponent = true;
                ShowRequirementFrameworkTitle = false;
                NEW_QUESTION question = BuildFromNewQuestion(info, info.Set, controlContext);
                ComponentVisibility = true;
                // Build multiServiceComponent types list if any
                ComponentTypes.Clear();
                int salLevel = controlContext.UNIVERSAL_SAL_LEVEL.Where(x => x.Universal_Sal_Level1 == question.Universal_Sal_Level).First().Sal_Level_Order;

                List <ComponentOverrideLinkInfo> tmpList = new List <ComponentOverrideLinkInfo>();

                foreach (COMPONENT_QUESTIONS componentType in question.COMPONENT_QUESTIONS)
                {
                    bool enabled = info.HasComponentsForTypeAtSal(componentType.Component_Type, salLevel);
                    SymbolComponentInfoData componentTypeData = info.DictionaryComponentInfo[componentType.Component_Type];
                    tmpList.Add(new ComponentOverrideLinkInfo()
                    {
                        TypeComponetXML = componentTypeData.XMLName,
                        Type            = componentTypeData.DisplayName,
                        Enabled         = enabled
                    });
                }
                ComponentTypes = tmpList.OrderByDescending(x => x.Enabled).ThenBy(x => x.Type).ToList();
            }
            catch (Exception ex)
            {
                //CSETLogger.Fatal("Failed to get component information tab data.", ex);
            }
        }
示例#2
0
        public void BuildComponentInfoTab(ComponentQuestionInfoData info, CSET_Context controlContext)
        {
            try
            {
                IsComponent = true;
                ShowRequirementFrameworkTitle  = false;
                this.RequirementFrameworkTitle = "Components";
                NEW_QUESTION question = BuildFromNewQuestion(info, info.Set, controlContext);
                ComponentVisibility = true;
                // Build multiServiceComponent types list if any
                ComponentTypes.Clear();
                int salLevel = controlContext.UNIVERSAL_SAL_LEVEL.Where(x => x.Universal_Sal_Level1 == question.Universal_Sal_Level).First().Sal_Level_Order;

                List <ComponentOverrideLinkInfo> tmpList = new List <ComponentOverrideLinkInfo>();


                foreach (COMPONENT_QUESTIONS componentType in controlContext.COMPONENT_QUESTIONS.Where(x => x.Question_Id == info.QuestionID))
                {
                    bool enabled = info.HasComponentsForTypeAtSal(componentType.Component_Symbol_Id, salLevel);
                    COMPONENT_SYMBOLS componentTypeData = info.DictionaryComponentInfo[componentType.Component_Symbol_Id];
                    tmpList.Add(new ComponentOverrideLinkInfo()
                    {
                        Component_Symbol_Id = componentTypeData.Component_Symbol_Id,
                        Symbol_Name         = componentTypeData.Symbol_Name,
                        Enabled             = enabled
                    });
                }
                ComponentTypes = tmpList.OrderByDescending(x => x.Enabled).ThenBy(x => x.Symbol_Name).ToList();
                var reqid = controlContext.REQUIREMENT_QUESTIONS.Where(x => x.Question_Id == info.QuestionID).First().Requirement_Id;
                BuildDocuments(reqid, controlContext);
                var requirement = controlContext.NEW_REQUIREMENT.Where(x => x.Requirement_Id == reqid).Select(t => new
                {
                    Question_or_Requirement_Id = t.Requirement_Id,
                    Text             = FormatRequirementText(t.Requirement_Text),
                    SupplementalInfo = FormatSupplementalInfo(t.Supplemental_Info)
                }).FirstOrDefault();
                if (requirement != null)
                {
                    RequirementsData = new RequirementTabData()
                    {
                        RequirementID    = requirement.Question_or_Requirement_Id,
                        Text             = requirement.Text,
                        SupplementalInfo = FormatSupplementalInfo(requirement.SupplementalInfo),
                    };
                    QuestionsVisible = false;
                    ShowSALLevel     = true;
                }
            }
            catch (Exception ex)
            {
                //CSETLogger.Fatal("Failed to get component information tab data.", ex);
            }
        }
        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);
        }
示例#4
0
        public static async Task <ConverterResult <NEW_REQUIREMENT> > ToRequirement(this IExternalRequirement externalRequirement, string setName, ILogger logger)
        {
            var result         = new ConverterResult <NEW_REQUIREMENT>(logger);
            var newRequirement = result.Result;

            //basic mappings
            newRequirement.Supplemental_Info      = externalRequirement.Supplemental;
            newRequirement.Requirement_Text       = externalRequirement.Text;
            newRequirement.Requirement_Title      = externalRequirement.Identifier;
            newRequirement.Original_Set_Name      = setName;
            newRequirement.Weight                 = externalRequirement.Weight;
            newRequirement.REQUIREMENT_LEVELS     = new List <REQUIREMENT_LEVELS>();
            newRequirement.REQUIREMENT_REFERENCES = new List <REQUIREMENT_REFERENCES>();
            newRequirement.REQUIREMENT_SETS       = new List <REQUIREMENT_SETS>()
            {
                new REQUIREMENT_SETS()
                {
                    Set_Name = setName
                }
            };
            //newRequirement.NEW_QUESTION = new List<NEW_QUESTION>();

            QUESTION_GROUP_HEADING          questionGroupHeading = null;
            UNIVERSAL_SUB_CATEGORY_HEADINGS subcategory          = null;

            using (var db = new CSET_Context())
            {
                try
                {
                    questionGroupHeading = db.QUESTION_GROUP_HEADING.FirstOrDefault(s => s.Question_Group_Heading1.Trim().ToLower() == externalRequirement.Heading.Trim().ToLower());
                    try
                    {
                        var subcatId = db.UNIVERSAL_SUB_CATEGORIES.FirstOrDefault(s => s.Universal_Sub_Category.Trim().ToLower() == externalRequirement.Subheading.Trim().ToLower())?.Universal_Sub_Category_Id ?? 0;
                        if (subcatId == 0)
                        {
                            var subcat = new UNIVERSAL_SUB_CATEGORIES()
                            {
                                Universal_Sub_Category = externalRequirement.Subheading
                            };
                            db.UNIVERSAL_SUB_CATEGORIES.Add(subcat);
                            await db.SaveChangesAsync();

                            subcatId = subcat.Universal_Sub_Category_Id;
                        }
                        try
                        {
                            subcategory = db.UNIVERSAL_SUB_CATEGORY_HEADINGS.FirstOrDefault(s => (s.Universal_Sub_Category_Id == subcatId) && (s.Question_Group_Heading_Id == questionGroupHeading.Question_Group_Heading_Id));
                            if (subcategory == null)
                            {
                                subcategory = new UNIVERSAL_SUB_CATEGORY_HEADINGS()
                                {
                                    Universal_Sub_Category_Id = subcatId, Question_Group_Heading_Id = questionGroupHeading.Question_Group_Heading_Id
                                };
                                db.UNIVERSAL_SUB_CATEGORY_HEADINGS.Add(subcategory);
                                await db.SaveChangesAsync();
                            }
                        }
                        catch
                        {
                        }
                    }
                    catch
                    {
                    }
                }
                catch
                {
                }
            }
            if (questionGroupHeading == null)
            {
                result.LogError(String.Format("Heading invalid for requirement {0} {1}.  Please double check that the heading is spelled correctly.", externalRequirement.Identifier, externalRequirement.Text));
            }
            else
            {
                newRequirement.Question_Group_Heading_Id = questionGroupHeading.Question_Group_Heading_Id;
            }

            if (subcategory == null)
            {
                result.LogError(String.Format("Subheading invalid for requirement {0} {1}.  Please double check that the heading is spelled correctly.", externalRequirement.Identifier, externalRequirement.Text));
            }
            externalRequirement.Category = string.IsNullOrWhiteSpace(externalRequirement.Category) ? externalRequirement.Heading : externalRequirement.Category;
            using (var db = new CSET_Context())
            {
                var category = db.STANDARD_CATEGORY.FirstOrDefault(s => s.Standard_Category1 == externalRequirement.Category);
                if (category == null)
                {
                    newRequirement.Standard_CategoryNavigation = new STANDARD_CATEGORY()
                    {
                        Standard_Category1 = externalRequirement.Category
                    };
                }
                else
                {
                    newRequirement.Standard_Category = category.Standard_Category1;
                }
            }
            foreach (var sal in Enum.GetValues(typeof(SalValues)).Cast <SalValues>().ToList())
            {
                try
                {
                    if ((int)sal >= (externalRequirement.SecurityAssuranceLevel ?? 0))
                    {
                        var rl = new REQUIREMENT_LEVELS()
                        {
                            Standard_Level = sal.ToString(),
                            Level_Type     = "NST"
                        };
                        newRequirement.REQUIREMENT_LEVELS.Add(rl);
                    }
                }
                catch
                {
                    result.LogError(String.Format("An error occurred while adding SALs for requirement {0} {1}.", externalRequirement.Identifier, externalRequirement.Text));
                }
            }
            var importer = new DocumentImporter();

            if (externalRequirement.References != null)
            {
                foreach (var reference in externalRequirement.References)
                {
                    var reqReference = new REQUIREMENT_REFERENCES();
                    try
                    {
                        reqReference.Destination_String = reference.Destination;
                        reqReference.Page_Number        = reference.PageNumber;
                        reqReference.Section_Ref        = String.IsNullOrEmpty(reference.SectionReference) ? "" : reference.SectionReference;
                        reqReference.Gen_File_Id        = importer.LookupGenFileId(reference.FileName);
                    }
                    catch
                    {
                        result.LogError(String.Format("Reference {0} could not be added for requirement {1} {2}.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    if (reqReference.Gen_File_Id == 0)
                    {
                        result.LogError(String.Format("Reference {0} has not been loaded into CSET.  Please add the file and try again.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    else
                    {
                        newRequirement.REQUIREMENT_REFERENCES.Add(reqReference);
                    }
                }
            }
            var reqSource = new REQUIREMENT_SOURCE_FILES();

            try
            {
                if (externalRequirement.Source != null)
                {
                    reqSource.Gen_File_Id        = importer.LookupGenFileId(externalRequirement.Source.FileName);
                    reqSource.Page_Number        = externalRequirement.Source.PageNumber;
                    reqSource.Destination_String = externalRequirement.Source.Destination;
                    reqSource.Section_Ref        = String.IsNullOrEmpty(externalRequirement.Source.SectionReference) ? "" : externalRequirement.Source.SectionReference;
                    if (reqSource.Gen_File_Id == 0)
                    {
                        result.LogError(String.Format("Source {0} has not been loaded into CSET.  Please add the file and try again.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                    else
                    {
                        newRequirement.REQUIREMENT_SOURCE_FILES.Add(reqSource);
                    }
                }
            }
            catch
            {
                result.LogError(String.Format("Source {0} could not be added for requirement {1} {2}.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
            }
            if (externalRequirement.Questions == null || externalRequirement.Questions.Count() == 0)
            {
                externalRequirement.Questions = new QuestionList()
                {
                    externalRequirement.Text
                };
            }
            foreach (var question in externalRequirement.Questions)
            {
                NEW_QUESTION newQuestion = null;
                var          set         = new NEW_QUESTION_SETS()
                {
                    Set_Name = setName, NEW_QUESTION_LEVELS = new List <NEW_QUESTION_LEVELS>()
                };
                using (var db = new CSET_Context())
                {
                    newQuestion = db.NEW_QUESTION.FirstOrDefault(s => s.Simple_Question.ToLower().Trim() == question.ToLower().Trim());
                    if (newQuestion != null)
                    {
                        db.Entry(newQuestion).State = EntityState.Detached;
                    }
                }
                if (newQuestion == null)
                {
                    newQuestion = new NEW_QUESTION();
                    try
                    {
                        newQuestion.Original_Set_Name   = setName;
                        newQuestion.Simple_Question     = question;
                        newQuestion.Weight              = externalRequirement.Weight;
                        newQuestion.Question_Group_Id   = questionGroupHeading.Question_Group_Heading_Id;
                        newQuestion.Universal_Sal_Level = ((SalValues)(externalRequirement.SecurityAssuranceLevel ?? (int)SalValues.L)).ToString();
                        newQuestion.Std_Ref             = setName.Replace("_", "");
                        newQuestion.Std_Ref             = newQuestion.Std_Ref.Substring(0, Math.Min(newQuestion.Std_Ref.Length, 50));
                        newQuestion.Heading_Pair_Id     = subcategory.Heading_Pair_Id;
                    }
                    catch
                    {
                        result.LogError(String.Format("Question {0} could not be added for requirement {1} {2}.", question, externalRequirement.Identifier, externalRequirement.Text));
                    }
                }
                foreach (var sal in Enum.GetValues(typeof(SalValues)).Cast <SalValues>().ToList())
                {
                    try
                    {
                        if ((int)sal >= (externalRequirement.SecurityAssuranceLevel ?? 0))
                        {
                            var rl = new NEW_QUESTION_LEVELS()
                            {
                                Universal_Sal_Level = sal.ToString(),
                            };
                            set.NEW_QUESTION_LEVELS.Add(rl);
                        }
                    }
                    catch
                    {
                        result.LogError(String.Format("An error occurred while adding SALs for requirement {1} {2}.", externalRequirement.Source?.FileName, externalRequirement.Identifier, externalRequirement.Text));
                    }
                }
                newQuestion.NEW_QUESTION_SETS          = new List <NEW_QUESTION_SETS>();
                newQuestion.REQUIREMENT_QUESTIONS_SETS = new List <REQUIREMENT_QUESTIONS_SETS>();
                newQuestion.NEW_QUESTION_SETS.Add(set);
                newQuestion.REQUIREMENT_QUESTIONS_SETS.Add(new REQUIREMENT_QUESTIONS_SETS {
                    Set_Name = setName, Requirement_ = newRequirement
                });
                using (CSET_Context db = new CSET_Context())
                {
                    db.NEW_QUESTION.Add(newQuestion);
                }
            }
            return(result);
        }
示例#5
0
 public QuestionPoco(ANSWER answer, NEW_QUESTION question) : this(answer)
 {
     this.Question = question;
 }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        public static void SaveQuestions(
            string setName,
            IExternalRequirement externalRequirement,
            NEW_REQUIREMENT newRequirement,
            QUESTION_GROUP_HEADING questionGroupHeading,
            UNIVERSAL_SUB_CATEGORY_HEADINGS uschPairing,
            CSET_Context db)
        {
            if (externalRequirement.Questions == null || externalRequirement.Questions.Count() == 0)
            {
                return;

                // trying to manufacture a question where none was defined could get us into trouble
                // externalRequirement.Questions = new QuestionList() { externalRequirement.Text };
            }

            var stdRefNum = 1;

            foreach (var question in externalRequirement.Questions)
            {
                NEW_QUESTION newQuestion = null;


                // Look for existing question by question text
                newQuestion = db.NEW_QUESTION.FirstOrDefault(s => s.Simple_Question.ToLower().Trim() == question.ToLower().Trim());

                if (newQuestion == null)
                {
                    newQuestion = new NEW_QUESTION();
                    try
                    {
                        newQuestion.Original_Set_Name   = setName;
                        newQuestion.Simple_Question     = question;
                        newQuestion.Weight              = externalRequirement.Weight;
                        newQuestion.Question_Group_Id   = questionGroupHeading.Question_Group_Heading_Id;
                        newQuestion.Universal_Sal_Level = SalCompare.FindLowestSal(externalRequirement.SecurityAssuranceLevels);
                        newQuestion.Std_Ref             = setName.Replace("_", "");
                        newQuestion.Std_Ref             = newQuestion.Std_Ref.Substring(0, Math.Min(newQuestion.Std_Ref.Length, 50));
                        newQuestion.Std_Ref_Number      = stdRefNum++;

                        newQuestion.Heading_Pair_Id = uschPairing.Heading_Pair_Id;

                        db.NEW_QUESTION.Add(newQuestion);
                        db.SaveChanges();
                    }
                    catch (Exception exc)
                    {
                        var a = exc;
                        // result.LogError(String.Format("Question {0} could not be added for requirement {1} {2}.", question, externalRequirement.Identifier, externalRequirement.Text));
                    }
                }


                var nqs = new NEW_QUESTION_SETS()
                {
                    Question_Id = newQuestion.Question_Id,
                    Set_Name    = setName
                };

                if (db.NEW_QUESTION_SETS.Count(x => x.Question_Id == nqs.Question_Id && x.Set_Name == nqs.Set_Name) == 0)
                {
                    db.NEW_QUESTION_SETS.Add(nqs);
                    db.SaveChanges();


                    // attach question SAL levels
                    var nqlList = new List <NEW_QUESTION_LEVELS>();
                    foreach (string sal in externalRequirement.SecurityAssuranceLevels)
                    {
                        var nql = new NEW_QUESTION_LEVELS()
                        {
                            Universal_Sal_Level = sal.ToString(),
                            New_Question_Set_Id = nqs.New_Question_Set_Id
                        };

                        if (!nqlList.Exists(x =>
                                            x.Universal_Sal_Level == nql.Universal_Sal_Level &&
                                            x.New_Question_Set_Id == nqs.New_Question_Set_Id))
                        {
                            db.NEW_QUESTION_LEVELS.Add(nql);
                            nqlList.Add(nql);
                        }
                    }
                }


                try
                {
                    var rqs = new REQUIREMENT_QUESTIONS_SETS()
                    {
                        Question_Id    = newQuestion.Question_Id,
                        Set_Name       = setName,
                        Requirement_Id = newRequirement.Requirement_Id
                    };
                    if (db.REQUIREMENT_QUESTIONS_SETS.Count(x =>
                                                            x.Question_Id == rqs.Question_Id &&
                                                            x.Set_Name == rqs.Set_Name) == 0)
                    {
                        db.REQUIREMENT_QUESTIONS_SETS.Add(rqs);
                    }


                    var rq = new REQUIREMENT_QUESTIONS()
                    {
                        Question_Id    = newQuestion.Question_Id,
                        Requirement_Id = newRequirement.Requirement_Id
                    };
                    if (db.REQUIREMENT_QUESTIONS_SETS.Count(x => x.Question_Id == rq.Question_Id &&
                                                            x.Requirement_Id == rq.Requirement_Id) == 0)
                    {
                        db.REQUIREMENT_QUESTIONS.Add(rq);
                    }

                    db.SaveChanges();
                }
                catch (Exception exc)
                {
                    throw new Exception("Error saving REQUIREMENT_QUESTIONS_SETS and REQUIREMENT_QUESTIONS");
                }
            }
        }