Пример #1
0
        public void view_OnGetExternalVariables(object sender, ExternalVariableEventArgs e)
        {
            var helper = new ExternalVariableHelper();

            e.Values = new Dictionary <string, string>();
            GetValues(e.Values, helper);

            e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
Пример #2
0
        private void GetValues(Dictionary <string, string> dic, ExternalVariableHelper helper)
        {
            foreach (var control in Controls)
            {
                if (control is Panel)
                {
                    var    panel = (Panel)control;
                    string value = String.Empty;
                    foreach (var item in panel.Controls)
                    {
                        if (item is RadioButton)
                        {
                            var radio = (RadioButton)item;
                            if (radio.Checked)
                            {
                                value = String.Format("{0}", radio.Tag);
                                break;
                            }
                        }
                    }

                    //e.Values.Add(panel.Name, value);
                    dic.Add(panel.Name, value);
                }
                else if (control is CheckBox)
                {
                    var check = (CheckBox)control;
                    //e.Values.Add(check.Name, check.Checked.ToString().ToLower());

                    dic.Add(check.Name, check.Checked.ToString().ToLower());
                }
                else if (control is ComboBox)
                {
                    var value = helper.GetSelectItemValue((ComboBox)control);
                    //e.Values.Add(control.Name, value);

                    dic.Add(control.Name, value);
                }
                else if (!(control is Label))
                {
                    //e.Values.Add(control.Name, control.Text);
                    dic.Add(control.Name, control.Text);
                }
            }

            //e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
Пример #3
0
        public void view_OnGetExternalVariables(object sender, ExternalVariableEventArgs e)
        {
            var helper = new ExternalVariableHelper();

            e.Values = new Dictionary <string, string>();
            foreach (var control in Controls)
            {
                if (control is Panel)
                {
                    var    panel = (Panel)control;
                    string value = String.Empty;
                    foreach (var item in panel.Controls)
                    {
                        if (item is RadioButton)
                        {
                            var radio = (RadioButton)item;
                            if (radio.Checked)
                            {
                                value = String.Format("{0}", radio.Tag);
                                break;
                            }
                        }
                    }
                    e.Values.Add(panel.Name, value);
                }
                else if (control is CheckBox)
                {
                    var check = (CheckBox)control;
                    e.Values.Add(check.Name, check.Checked.ToString().ToLower());
                }
                else if (control is ComboBox)
                {
                    var value = helper.GetSelectItemValue((ComboBox)control);
                    e.Values.Add(control.Name, value);
                }
                else if (!(control is Label))
                {
                    e.Values.Add(control.Name, control.Text);
                }
            }

            e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
Пример #4
0
        private bool CheckExternalVariables(string filename, out string errors)
        {
            errors = null;

            if (filename == null)
            {
                errors = Resource.EmptyDefinitionFilename;
                return(false);
            }

            if (!File.Exists(filename))
            {
                errors = Resource.OVALDefinitionsFileNotFound;
                return(false);
            }

            var helper      = new ExternalVariableHelper();
            var definitions = helper.GetOvalDefinitionsFromFile(filename, out errors);

            if (definitions != null)
            {
                var platform = new TargetPlatformDiscoverer(definitions.objects);
                var family   = platform.Discover();
                isUnixDefinition = (family.ToString() == "unix");

                if (definitions.variables != null)
                {
                    ExternalVariables       = definitions.variables.OfType <Modulo.Collect.OVAL.Definitions.VariablesTypeVariableExternal_variable>();
                    ExternalVariablesValues = GetExternalVariablesDefaultValuesFromDefinition(definitions.GetDefinitionsXml());
                }

                return(true);
            }

            return(false);
        }
Пример #5
0
        public void view_OnGetExternalVariables(object sender, ExternalVariableEventArgs e)
        {
            var helper = new ExternalVariableHelper();

            e.Values = new Dictionary<string, string>();
            foreach (var control in Controls)
            {
                if (control is Panel)
                {
                    var panel = (Panel)control;
                    string value = String.Empty;
                    foreach (var item in panel.Controls)
                    {
                        if (item is RadioButton)
                        {
                            var radio = (RadioButton)item;
                            if (radio.Checked)
                            {
                                value = String.Format("{0}", radio.Tag);
                                break;
                            }
                        }
                    }
                    e.Values.Add(panel.Name, value);
                }
                else if (control is CheckBox)
                {
                    var check = (CheckBox)control;
                    e.Values.Add(check.Name, check.Checked.ToString().ToLower());
                }
                else if (control is ComboBox)
                {
                    var value = helper.GetSelectItemValue((ComboBox)control);
                    e.Values.Add(control.Name, value);
                }
                else if (!(control is Label))
                {
                    e.Values.Add(control.Name, control.Text);
                }
            }

            e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
Пример #6
0
        private bool CheckExternalVariables(string filename, out string errors)
        {
            errors = null;

            if (filename == null)
            {
                errors = Resource.EmptyDefinitionFilename;
                return false;
            }

            if (!File.Exists(filename))
            {
                errors = Resource.OVALDefinitionsFileNotFound;
                return false;
            }

            var helper = new ExternalVariableHelper();
            var definitions = helper.GetOvalDefinitionsFromFile(filename, out errors);
            if (definitions != null)
            {
                var platform = new TargetPlatformDiscoverer(definitions.objects);
                var family = platform.Discover();
                isUnixDefinition = (family.ToString() == "unix");

                if (definitions.variables != null)
                {
                    ExternalVariables = definitions.variables.OfType<Modulo.Collect.OVAL.Definitions.VariablesTypeVariableExternal_variable>();
                    ExternalVariablesValues = GetExternalVariablesDefaultValuesFromDefinition(definitions.GetDefinitionsXml());
                }

                return true;
            }

            return false;
        }
        private void View_OnXCCDF(object sender, OnXCCDFEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                var doc = new XmlDocument();
                doc.Load(e.Filename);
                var nav = doc.CreateNavigator();

                var ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("xccdf", "http://checklists.nist.gov/xccdf/1.2");

                var helper = new ExternalVariableHelper();
                var dic = new Dictionary<string, string>();

                var controlDic = Controls.ToDictionary(c => c.Name, c => c);

                GetValues(dic, helper);

                float step = 1.0f / dic.Count;
                foreach (var item in dic.ToArray())
                {
                    try
                    {
                        var value = nav.Evaluate("string(//xccdf:Value[@id= string(//xccdf:check-export[@export-name='" + item.Key + "']/@value-id)]/xccdf:value)", ns);
                        dic[item.Key] = value.ToString();

                        var control = controlDic[item.Key];

                        if (control is NumericUpDown)
                        {
                            control.Invoke(new Action(() =>
                            {
                                (control as NumericUpDown).Value = decimal.Parse(value.ToString());
                            }));
                        }
                        else if (control is TextBox)
                        {
                            control.Invoke(new Action(() =>
                            {
                                (control as TextBox).Text = value.ToString();
                            }));
                        }
                        else if (control is CheckBox)
                        {
                            if (value.ToString() == "1") { value = "true"; }
                            if (value.ToString() == "0") { value = "false"; }
                            control.Invoke(new Action(() =>
                            {
                                (control as CheckBox).Checked = bool.Parse(value.ToString());
                            }));
                        }
                        else
                        {

                        }
                    }
                    catch
                    {

                    }

                    view.Progress += step;
                }

                int x = 10;
            });
        }
        private void GetValues(Dictionary<string, string> dic, ExternalVariableHelper helper)
        {
            foreach (var control in Controls)
            {
                if (control is Panel)
                {
                    var panel = (Panel)control;
                    string value = String.Empty;
                    foreach (var item in panel.Controls)
                    {
                        if (item is RadioButton)
                        {
                            var radio = (RadioButton)item;
                            if (radio.Checked)
                            {
                                value = String.Format("{0}", radio.Tag);
                                break;
                            }
                        }
                    }

                    //e.Values.Add(panel.Name, value);
                    dic.Add(panel.Name, value);
                }
                else if (control is CheckBox)
                {
                    var check = (CheckBox)control;
                    //e.Values.Add(check.Name, check.Checked.ToString().ToLower());

                    dic.Add(check.Name, check.Checked.ToString().ToLower());
                }
                else if (control is ComboBox)
                {
                    var value = helper.GetSelectItemValue((ComboBox)control);
                    //e.Values.Add(control.Name, value);

                    dic.Add(control.Name, value);
                }
                else if (!(control is Label))
                {
                    //e.Values.Add(control.Name, control.Text);
                    dic.Add(control.Name, control.Text);
                }
            }

            //e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
        public void view_OnGetExternalVariables(object sender, ExternalVariableEventArgs e)
        {
            var helper = new ExternalVariableHelper();

            e.Values = new Dictionary<string, string>();
            GetValues(e.Values, helper);

            e.Xml = helper.GetEvaluatedExternalVariables(e.Values, e.ExternalVariables);
        }
Пример #10
0
        private void View_OnXCCDF(object sender, OnXCCDFEventArgs e)
        {
            Task.Factory.StartNew(() =>
            {
                var doc = new XmlDocument();
                doc.Load(e.Filename);
                var nav = doc.CreateNavigator();

                var ns = new XmlNamespaceManager(doc.NameTable);
                ns.AddNamespace("xccdf", "http://checklists.nist.gov/xccdf/1.2");

                var helper = new ExternalVariableHelper();
                var dic    = new Dictionary <string, string>();

                var controlDic = Controls.ToDictionary(c => c.Name, c => c);

                GetValues(dic, helper);

                float step = 1.0f / dic.Count;
                foreach (var item in dic.ToArray())
                {
                    try
                    {
                        var value     = nav.Evaluate("string(//xccdf:Value[@id= string(//xccdf:check-export[@export-name='" + item.Key + "']/@value-id)]/xccdf:value)", ns);
                        dic[item.Key] = value.ToString();

                        var control = controlDic[item.Key];

                        if (control is NumericUpDown)
                        {
                            control.Invoke(new Action(() =>
                            {
                                (control as NumericUpDown).Value = decimal.Parse(value.ToString());
                            }));
                        }
                        else if (control is TextBox)
                        {
                            control.Invoke(new Action(() =>
                            {
                                (control as TextBox).Text = value.ToString();
                            }));
                        }
                        else if (control is CheckBox)
                        {
                            if (value.ToString() == "1")
                            {
                                value = "true";
                            }
                            if (value.ToString() == "0")
                            {
                                value = "false";
                            }
                            control.Invoke(new Action(() =>
                            {
                                (control as CheckBox).Checked = bool.Parse(value.ToString());
                            }));
                        }
                        else
                        {
                        }
                    }
                    catch
                    {
                    }

                    view.Progress += step;
                }

                view.Progress = 0;
            });
        }