コード例 #1
0
ファイル: VariableEvaluator.cs プロジェクト: jonaslsl/modSIC
 public VariableEvaluator(IEnumerable<VariableType> variables, oval_system_characteristics systemCharacteristics, oval_variables externalVariables)
 {
     this.variablesOfDefinitions = variables;
     this.evaluatorFactory = new EvaluatorFactory();
     this.systemCharacteristics = systemCharacteristics;
     this.externalVariables = externalVariables;
 }
コード例 #2
0
ファイル: oval_variables.cs プロジェクト: solind/modSIC
        public static oval_variables GetOvalVariablesFromText(string variablesDocumentText, out IEnumerable <string> schemaErrors)
        {
            var _schemaErrors = new List <string>();

            PrepareSerializer();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ValidationType          = ValidationType.Schema;
            settings.XmlResolver             = xmlResolver;
            settings.ValidationFlags         = XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.AllowXmlAttributes;
            settings.ValidationEventHandler += (o, args) => { if (args.Severity == XmlSeverityType.Error)
                                                              {
                                                                  _schemaErrors.Add(args.Message);
                                                              }
            };
            var            varMS  = new MemoryStream(Encoding.UTF8.GetBytes(variablesDocumentText));
            XmlReader      reader = XmlReader.Create(varMS, settings);
            oval_variables result = xmlSerializer.Deserialize(reader) as oval_variables;

            reader.Close();

            if (_schemaErrors.Count > 0)
            {
                result = null;
            }

            schemaErrors = _schemaErrors;
            return(result);
        }
コード例 #3
0
ファイル: EvaluatorFactory.cs プロジェクト: ywcsz/modSIC
 /// <summary>
 /// Creates the correct implementation of variable for the evaluation.
 /// </summary>
 /// <param name="variable">The oval definitions variable.</param>
 /// <returns></returns>
 public Evaluator CreateVariable(VariableType variable, oval_system_characteristics sytemCharacteristics, IEnumerable<VariableType> variablesOfDefinitions, oval_variables externalVariables)
 {
     if (variable is VariablesTypeVariableConstant_variable)
         return new ConstantVariableEvaluator((VariablesTypeVariableConstant_variable)variable);
     else if (variable is VariablesTypeVariableLocal_variable)
         return new LocalVariableEvaluator((VariablesTypeVariableLocal_variable)variable, sytemCharacteristics, variablesOfDefinitions, externalVariables);
     else if (variable is VariablesTypeVariableExternal_variable)
         return new ExternalVariableEvaluator((VariablesTypeVariableExternal_variable)variable, externalVariables);
        return null;
 }
コード例 #4
0
        public string GetEvaluatedExternalVariables(Dictionary<String, String> externalVariablesValues, IEnumerable<Definitions.VariablesTypeVariableExternal_variable> externalVariables)
        {
            var variables = new oval_variables
            {
                generator = Collect.OVAL.Common.DocumentHelpers.GetDefaultGenerator(),
                variables = new List<VariableType>()
            };

            foreach (var item in externalVariables)
            {
                string defaultValue = externalVariablesValues.Where(n => n.Key == item.id).Select(m => m.Value).SingleOrDefault() ?? String.Empty;
                variables.variables.Add(new VariableType(item.datatype, item.id, defaultValue));
            }

            return variables.GetXmlDocument();
        }
コード例 #5
0
        public string GetExternalVariableWithDefaultValueFrom(string  definitionsName)

        {
            var definitions = new OvalDocumentLoader().GetFakeOvalDefinitions(definitionsName);

            var externalVariables = new Variables.oval_variables();
            externalVariables.generator = Modulo.Collect.OVAL.Common.DocumentHelpers.GetDefaultGenerator();
            externalVariables.variables = new List<Variables.VariableType>();

            if (definitions.variables != null)
            {
                foreach (var variable in definitions.variables)
                {
                    string defaultValue = string.Empty;
                    externalVariables.variables.Add(new Variables.VariableType(variable.datatype, variable.id, defaultValue));
                }
            }

            return externalVariables.GetXmlDocument();
        }
コード例 #6
0
        public string GetExternalVariableWithDefaultValueFrom(string definitionsName)

        {
            var definitions = new OvalDocumentLoader().GetFakeOvalDefinitions(definitionsName);

            var externalVariables = new Variables.oval_variables();

            externalVariables.generator = Modulo.Collect.OVAL.Common.DocumentHelpers.GetDefaultGenerator();
            externalVariables.variables = new List <Variables.VariableType>();

            if (definitions.variables != null)
            {
                foreach (var variable in definitions.variables)
                {
                    string defaultValue = string.Empty;
                    externalVariables.variables.Add(new Variables.VariableType(variable.datatype, variable.id, defaultValue));
                }
            }

            return(externalVariables.GetXmlDocument());
        }
コード例 #7
0
ファイル: oval_results.cs プロジェクト: jonaslsl/modSIC
        public static oval_results CreateFromDocuments(
            Definitions.oval_definitions definitions, 
            oval_system_characteristics systemcharacteristics,
            oval_variables evaluatedExternalVariables)
        {
            oval_results newResult = new oval_results();
            newResult.generator = DocumentHelpers.GetDefaultGenerator();
            newResult.oval_definitions = definitions;
            newResult.results =  new List<SystemType> { new SystemType() };
            newResult.results[0].oval_system_characteristics = systemcharacteristics;
            newResult.EvaluatedExternalVariables = evaluatedExternalVariables;

            // Generate new Definition Result entries
            foreach (var definition in definitions.definitions)
            {
                if ((definition.criteria == null) || (definition.criteria.Items == null) || (definition.criteria.Items.Count() < 1))
                    continue;
                var newDefinitionResult = new DefinitionType(definition);
                newResult.results[0].definitions.Add(newDefinitionResult);
            }
            // Generate new Test Result entries
            foreach (var test in definitions.tests)
            {
                var newTestResult = new TestType(test);
                newResult.results[0].tests.Add(newTestResult);
            }
            return newResult;
        }
コード例 #8
0
 public ExternalVariableEvaluator(VariablesTypeVariableExternal_variable variable, oval_variables external_variables)
 {
     this.variable = variable;
     this.external_variables = external_variables;
 }
コード例 #9
0
        public void Test_Create_Variables_Document()
        {
            // Arrange / Act
            oval_variables variables = new oval_variables();
            variables.variables.Add(new VariableType(SimpleDatatypeEnumeration.@string, "oval:XX:var:1", "Red", "Green"));
            variables.variables.Add(new VariableType(SimpleDatatypeEnumeration.boolean, "oval:XX:var:2", "true"));

            //XmlSerializer xmlSerializer = new XmlSerializer(typeof(oval_variables));
            //StringBuilder sb = new StringBuilder();
            //StringWriter sw = new StringWriter(sb);
            //xmlSerializer.Serialize(sw, variables);
            
            IEnumerable<string> schemaErrors;
            oval_variables result = oval_variables.GetOvalVariablesFromText(variables.GetXmlDocument(), out schemaErrors);

            // Assert
            Assert.AreEqual(0, schemaErrors.Count(), string.Join(Environment.NewLine, schemaErrors.ToArray()));
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.variables.Count);
        }
コード例 #10
0
ファイル: oval_results_Test.cs プロジェクト: ywcsz/modSIC
        private oval_results GetOvalResultsFromDefinitionsAndSystemCharacteristicsDocuments(
            string definitionsResourceName, 
            string systemCharacteristicsResourceName,
            oval_variables evaluatedExternalVariables)
        {
            try
            {
                var ovalDocumentLoader = new OvalDocumentLoader();
                var definitions = ovalDocumentLoader.GetFakeOvalDefinitions(definitionsResourceName);
                var systemCharacteristics = ovalDocumentLoader.GetFakeOvalSystemCharacteristics(systemCharacteristicsResourceName);

                return oval_results.CreateFromDocuments(definitions, systemCharacteristics, evaluatedExternalVariables);
            }
            catch (Exception ex)
            {
                Assert.Fail(String.Format(CREATE_OVAL_RESULTS_DOC_ERROR_MSG, ex.Message));
                return null;
            }
        }
コード例 #11
0
ファイル: oval_results_Test.cs プロジェクト: ywcsz/modSIC
        private oval_results Analyse(oval_variables ovalVariables)
        {
            var ovalResultsDoc =
                GetOvalResultsFromDefinitionsAndSystemCharacteristicsDocuments(
                    "definitionsWithStateWithExternalVariables.xml",
                    "system_characteristics_with_state_with_external_variables.xml",
                    ovalVariables);

            ovalResultsDoc.Analyze();

            return ovalResultsDoc;
        }
コード例 #12
0
        private string CreateOvalVariablesWithFakeValues()
        {
            var ovalDefinitions = new OvalDocumentLoader().GetFakeOvalDefinitions(FDCC_XPFIREWALL);
            var externalVariables = ovalDefinitions.variables.OfType<VariablesTypeVariableExternal_variable>();

            var externalVariablesWithFakeValue = new oval_variables();
            foreach(var declaredExternalVariable in externalVariables)
            {
                var newFakeVariable = CreateVariableType(declaredExternalVariable);
                externalVariablesWithFakeValue.variables.Add(newFakeVariable);
            }

            return externalVariablesWithFakeValue.GetXmlDocument();
        }
コード例 #13
0
        private oval_variables CreateOvalVariablesFromExternalVariables(Definitions.VariablesTypeVariableExternal_variable[] externalVariables)
        {
            var newOvalVariables = new oval_variables();
            foreach (var externalVar in externalVariables)
            {
                var newVariableType = this.GetVariableType(externalVar.id, externalVar.datatype, new string[] { string.Empty });
                newOvalVariables.variables.Add(newVariableType);
            }

            return newOvalVariables;
        }