private void _page_PolicyName_BeforeMoveNext(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(PolicyName))
            {
                MsgBox.ShowError("Error Creating Policy", "Must specify a name for the new policy.");
                e.Cancel = true;
            }
            else
            {
                Policy p = Program.gController.Repository.GetPolicy(PolicyName);
                if (p != null)
                {
                    MsgBox.ShowError("Error Creating Policy",
                                     string.Format(
                                         "Cannot create policy {0}. A policy with the name you specified already exists. Specify a different policy name.",
                                         textBox_PolicyName.Text));
                    e.Cancel = true;
                }
            }

            if (!e.Cancel)
            {
                m_policy.IsDynamic = true;
                controlConfigurePolicyVulnerabilities1.InitializeControl(m_policy);
                controlPolicyAddServers1.InitializeControl(m_policy, true);
            }
        }
 private void _page_PolicyType_BeforeMoveNext(object sender, CancelEventArgs e)
 {
     if (radioButtonCreateFromStandard.Checked)
     {
         string fileName = (string)textBox_PolicyName.Tag;
         if (!string.IsNullOrEmpty(fileName))
         {
             m_policy.ImportPolicyFromXMLFile(fileName, false);
             _policyInterview.SetInterviewText(string.Empty);
             _policyInterview.InterviewName = string.Empty;
         }
         else
         {
             MsgBox.ShowError("Error Creating Policy", "Must specify a Standard Policy.");
             e.Cancel = true;
         }
     }
     else
     {
         textBox_PolicyName.Tag = null;
         m_policy                  = new Policy();
         m_policy.IsDynamic        = true;
         m_policy.DynamicSelection = string.Empty;
     }
 }
Exemple #3
0
        /// <summary>
        /// SQLsecure 3.1 (Anshul Aggarwal) - Initializes control using specified configuration values.
        /// </summary>
        public void InitializeControl(Policy policy, int metricId, bool allowEdit)
        {
            m_policy    = policy;
            m_importing = m_policy.PolicyId == 0;
            checkBox_GroupByCategories.Checked = true;

            sqlServerCriteriaControl.InitializeControl(allowEdit);     // SQLsecure 3.1 (Anshul Aggarwal) - Initialize both tabs.
            azureSQLDatabaseCriteriaControl.InitializeControl(allowEdit, GetAzureSQLDBGridColumnMapping());

            loadPolicyMetrics();

            if (metricId > 0)
            {
                UltraGridRow[] rows = ultraGridPolicyMetrics.Rows.GetAllNonGroupByRows();
                foreach (UltraGridRow row in rows)
                {
                    if (row.IsDataRow && ((PolicyMetric)row.ListObject).MetricId == metricId)
                    {
                        ultraGridPolicyMetrics.Selected.Rows.Clear();
                        ultraGridPolicyMetrics.Selected.Rows.Add(row);
                        row.Activate();
                        break;
                    }
                }
            }

            m_allowEdit = allowEdit;
            if (!allowEdit)
            {
                button_Import.Enabled    =
                    button_Clear.Enabled =
                        button_ResetToDefaults.Enabled = false;
            }
        }
        public void InitializeDialog(string fileName, bool allowEdit)
        {
            m_isCreateNew = false;
            m_policy      = new Policy();
            m_policy.ImportPolicyFromXMLFile(fileName);
            textBox_PolicyName.Text = m_policy.PolicyName;
            this.Text = "Importing Policy - " + m_policy.PolicyName;

            if (!allowEdit)
            {
                textBox_PolicyName.Enabled  = false;
                listView_AddServers.Enabled = false;
            }
            else
            {
                if (m_policy != null && m_policy.IsDynamic)
                {
                    listView_AddServers.Items.Clear();
                    listView_AddServers.Enabled = false;
                    listView_AddServers.Items.Add("This is a dynamic policy servers are added at run time");
                }
                if (m_policy != null && m_policy.IsSystemPolicy)
                {
                    textBox_PolicyName.Enabled = false;
                    controlConfigurePolicyVulnerabilities1.Enabled = false;
                }
            }

            controlConfigurePolicyVulnerabilities1.InitilizeControl(m_policy);
        }
Exemple #5
0
 public void SaveMetricChanges(Policy policy)
 {
     if (OKToSave())
     {
         RetrieveValuesFromUI();
         policy.SetPolicyMetrics(m_metrics);
     }
 }
        public static bool Process(Policy importingPolicy, bool allowEdit, RequestedOperation op)
        {
            Form_PolicyProperties frm = new Form_PolicyProperties(op);

            frm.InitializeDialog(importingPolicy, allowEdit);

            // return true if updated, otherwise false
            return(DialogResult.Cancel != frm.ShowDialog());
        }
 public void InitializeDialog(Policy importingPolicy, bool allowEdit)
 {
     m_isCreateNew = true;
     m_policy      = new Policy();
     m_policy.UpdatePolicyFromImporting(importingPolicy);
     m_policy.IsSystemPolicy = false;
     Text = string.Format(IMPORTTITLEFMT, m_policy.PolicyName);
     InitializeDialogCommon(allowEdit);
 }
        public void InitializeControl(Policy policy, int metricId, bool allowEdit)
        {
            m_policy              = policy;
            m_importing           = m_policy.PolicyId == 0;
            button_Remove.Enabled = false;
            checkBox_GroupByCategories.Checked = true;

            loadPolicyMetrics();

            if (metricId > 0)
            {
                UltraGridRow[] rows = ultraGridPolicyMetrics.Rows.GetAllNonGroupByRows();
                foreach (UltraGridRow row in rows)
                {
                    if (row.IsDataRow && ((PolicyMetric)row.ListObject).MetricId == metricId)
                    {
                        ultraGridPolicyMetrics.Selected.Rows.Clear();
                        ultraGridPolicyMetrics.Selected.Rows.Add(row);
                        row.Activate();
                        break;
                    }
                }
            }

            m_allowEdit = allowEdit;
            if (!allowEdit)
            {
                button_Clear.Enabled =
                    button_ResetToDefaults.Enabled      =
                        button_Edit.Enabled             =
                            button_Remove.Enabled       = false;
                textBox_ReportKey.Enabled               =
                    textBox_ReportText.Enabled          =
                        textBox_UserEnterSingle.Enabled = false;
                radioButton_SeverityCritical.Enabled    =
                    radioButton_SeverityMedium.Enabled  =
                        radioButton_SeverityLow.Enabled = false;
                checkBox1.Enabled                                =
                    checkBox2.Enabled                            =
                        checkBox3.Enabled                        =
                            checkBox4.Enabled                    =
                                checkBox5.Enabled                =
                                    checkBox6.Enabled            =
                                        checkBox7.Enabled        =
                                            checkBox8.Enabled    = false;
                radioButton1.Enabled                             =
                    radioButton2.Enabled                         =
                        radioButton3.Enabled                     =
                            radioButton4.Enabled                 =
                                radioButton5.Enabled             =
                                    radioButton6.Enabled         =
                                        radioButton7.Enabled     =
                                            radioButton8.Enabled = false;
                listView_MultiSelect.Enabled                     = false;
            }
        }
        public void InitializeDialog(string fileName, bool allowEdit)
        {
            m_isCreateNew = true;
            m_policy      = new Policy();
            m_policy.ImportPolicyFromXMLFile(fileName, false);
            m_policy.IsSystemPolicy = false;
            this.Text = string.Format(IMPORTTITLEFMT, m_policy.PolicyName);

            InitializeDialogCommon(allowEdit);
        }
Exemple #10
0
        private void DeletePolicy(object sender, EventArgs e)
        {
            if (_grid_Policies.ActiveRow != null && _grid_Policies.ActiveRow.IsDataRow)
            {
                int    policyId = (int)_grid_Policies.ActiveRow.Cells[colHeaderHiddenPolicyId].Value;
                Policy p        = Program.gController.Repository.GetPolicy(policyId);

                DeletePolicy(p);
            }
        }
        private void _page_PolicyName_BeforeDisplay(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty((string)textBox_PolicyName.Tag))
            {
                Policy p = new Policy();
                p.ImportPolicyFromXMLFile((string)textBox_PolicyName.Tag, false);

                textBox_Description.Text = p.PolicyDescription;
            }
        }
Exemple #12
0
        /// <summary>
        /// SQLsecure 3.1 (Anshul Aggarwal) - Initializes control using specified configuration values.
        /// </summary>
        public void InitializeControl(Policy policy)
        {
            m_policy    = policy;
            m_importing = m_policy.PolicyId == 0;
            checkBox_GroupByCategories.Checked = true;

            sqlServerCriteriaControl.InitializeControl();      // SQLsecure 3.1 (Anshul Aggarwal) - Initialize both tabs.
            azureSQLDatabaseCriteriaControl.InitializeControl(GetAzureSQLDBGridColumnMapping());

            loadPolicyMetrics();
        }
        private void _page_Interview_BeforeDisplay(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty((string)textBox_PolicyName.Tag))
            {
                if (string.IsNullOrEmpty(_policyInterview.InterviewName) &&
                    string.IsNullOrEmpty(_policyInterview.GetInterviewText()))
                {
                    Policy p = new Policy();
                    p.ImportPolicyFromXMLFile((string)textBox_PolicyName.Tag, false);

                    _policyInterview.SetInterviewText(p.InterviewText);
                    _policyInterview.InterviewName = p.InterviewName;
                }
            }
        }
Exemple #14
0
        private void _cmsi_Assessments_Delete_Click(object sender, EventArgs e)
        {
            if (_grid_Assessments.ActiveRow != null && _grid_Assessments.ActiveRow.IsDataRow)
            {
                string policyName = _grid_Assessments.ActiveRow.Cells[colHeaderName].Text;

                int policyId     = (int)_grid_Assessments.ActiveRow.Cells[colHeaderHiddenPolicyId].Value;
                int assessmentId = (int)_grid_Assessments.ActiveRow.Cells[colHeaderHiddenAssessmentId].Value;

                Repository.AssessmentList assessments = Program.gController.Repository.Policies.Find(policyId).Assessments;
                Policy p = assessments.Find(assessmentId);

                DeletePolicy(p);
            }
        }
        public void InitializeDialog(int policyID, bool allowEdit)
        {
            m_allowEdit = allowEdit;
            if (policyID == 0)
            {
                m_isCreateNew = true;
                m_policy      = new Policy();
            }
            else
            {
                m_isCreateNew            = false;
                m_policy                 = Policy.GetPolicy(policyID);
                textBox_PolicyName.Text  = m_policy.PolicyName;
                this.Text                = "Policy Properties - " + m_policy.PolicyName;
                m_orginalServersInPolicy = m_policy.GetMemberServers();

                foreach (ListViewItem server in listView_AddServers.Items)
                {
                    if (m_orginalServersInPolicy.Contains((RegisteredServer)server.Tag))
                    {
                        server.Checked = true;
                    }
                }
            }

            if (!allowEdit)
            {
                textBox_PolicyName.Enabled  = false;
                listView_AddServers.Enabled = false;
            }
            else
            {
                if (m_policy != null && m_policy.IsDynamic)
                {
                    listView_AddServers.Items.Clear();
                    listView_AddServers.Enabled = false;
                    listView_AddServers.Items.Add("This is a dynamic policy servers are added at run time");
                }
                if (m_policy != null && m_policy.IsSystemPolicy)
                {
                    textBox_PolicyName.Enabled = false;
                    controlConfigurePolicyVulnerabilities1.Enabled = false;
                }
            }

            controlConfigurePolicyVulnerabilities1.InitilizeControl(m_policy);
        }
        protected void printGrid(Infragistics.Win.UltraWinGrid.UltraGrid grid)
        {
            // Associate the print document with the grid & preview dialog here
            // for consistency with other forms that require it
            _ultraGridPrintDocument.Grid = grid;
            _ultraGridPrintDocument.DefaultPageSettings.Landscape = true;
            _ultraGridPrintDocument.DefaultPageSettings.Color     = false;
            _ultraGridPrintDocument.DocumentName    = PrintTitle;
            _ultraGridPrintDocument.FitWidthToPages = 1;

            Policy policy = Program.gController.Repository.Policies.Find(m_PolicyId);

            if (policy.AssessmentId != m_AssessmentId && policy.HasAssessment(m_AssessmentId))
            {
                policy = policy.Assessments.Find(m_AssessmentId);
            }

            PolicyMetric check = null;

            foreach (PolicyMetric metric in policy.GetPolicyMetrics())
            {
                if (metric.MetricId == m_MetricId)
                {
                    check = metric;
                    break;
                }
            }

            if (policy != null && check != null)
            {
                _ultraGridPrintDocument.Header.TextLeft =
                    string.Format(PrintHeaderDisplay,
                                  policy.PolicyAssessmentName,
                                  check.MetricName,
                                  DateTime.Now.ToShortDateString()
                                  );
                _ultraPrintPreviewDialog.Document = _ultraGridPrintDocument;

                // Call ShowDialog to show the print preview dialog.
                _ultraPrintPreviewDialog.ShowDialog();
            }
            else
            {
                logX.loggerX.Error(string.Format(Utility.ErrorMsgs.ErrorStub, Utility.ErrorMsgs.CantGetPolicy));
                MsgBox.ShowError(Utility.ErrorMsgs.PolicyCaption, Utility.ErrorMsgs.CantGetPolicy);
            }
        }
Exemple #17
0
        private void _grid_Policies_AfterRowActivate(object sender, EventArgs e)
        {
            bool enabled = false;

            if (_grid_Policies.ActiveRow != null && _grid_Policies.ActiveRow.IsDataRow)
            {
                int policyId = (int)_grid_Policies.ActiveRow.Cells[colHeaderHiddenPolicyId].Value;
                Program.gController.Repository.RefreshPolicies();
                loadAssessmentsDataSource(policyId, true);
                Policy p = Program.gController.Repository.GetPolicy(policyId);
                if (!p.HasAssessments() && !p.IsSystemPolicy)
                {
                    enabled = true;
                }
            }
            _cmsi_Policies_Delete.Enabled = enabled;
        }
        private void _wizard_Finish(object sender, EventArgs e)
        {
            try
            {
                if (!controlConfigurePolicyVulnerabilities1.OKToSave())
                {
                    DialogResult = DialogResult.None;
                    return;
                }

                List <RegisteredServer> serversToAdd    = null;
                List <RegisteredServer> serversToRemove = null;
                string dynamicSelection = null;
                bool   isDynamic;
                controlPolicyAddServers1.GetServers(true, out serversToAdd, out serversToRemove, out dynamicSelection, out isDynamic);

                int policyId = -1;
                policyId = Policy.AddPolicy(PolicyName, PolicyDescription, isDynamic, dynamicSelection, _policyInterview.InterviewName, _policyInterview.GetInterviewText());
                if (policyId != -1)
                {
                    // Notify controller that a new server was added.
                    Program.gController.SignalRefreshPoliciesEvent(0);

                    // Now add the metrics to the policy
                    m_policy = Policy.GetPolicy(policyId);
                    controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy);
                    m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString);

                    // Now add the selected servers to the policy
                    foreach (RegisteredServer rServer in serversToAdd)
                    {
                        RegisteredServer.AddRegisteredServerToPolicy(rServer.RegisteredServerId, m_policy.PolicyId, m_policy.AssessmentId);
                    }
                }
            }
            catch (Exception ex)
            {
                string title = "Error Creating Policy";
                string msg   =
                    string.Format("Failed to Create policy {0} error message: {1}", textBox_PolicyName.Text,
                                  ex.Message);
                logX.loggerX.Error(msg);
                MsgBox.ShowError(title, msg);
            }
        }
        public void InitializeDialog(int policyID, int assessmentId, bool allowEdit)
        {
            if (policyID == 0)
            {
                m_isCreateNew     = true;
                button_OK.Enabled = false;
                m_policy          = new Policy();
                //           m_allowEdit = allowEdit;
            }
            else
            {
                m_isCreateNew = false;
                m_policy      = Policy.GetPolicy(policyID, assessmentId);
                //    m_allowEdit = allowEdit && !m_policy.IsApprovedAssessment;
                this.Text = string.Format(TITLEFMT, m_policy.PolicyAssessmentName);
            }

            InitializeDialogCommon(allowEdit);
        }
Exemple #20
0
        private void _grid_Assessments_AfterRowActivate(object sender, EventArgs e)
        {
            bool enabled = false;

            if (_grid_Assessments.ActiveRow != null && _grid_Assessments.ActiveRow.IsDataRow)
            {
                int policyId = (int)_grid_Assessments.ActiveRow.Cells[colHeaderHiddenPolicyId].Value;
                Program.gController.Repository.RefreshPolicies();
                int assessmentId = (int)_grid_Assessments.ActiveRow.Cells[colHeaderHiddenAssessmentId].Value;
                Repository.AssessmentList assessments = Program.gController.Repository.Policies.Find(policyId).Assessments;
                Policy p = assessments.Find(assessmentId);
                if (!p.IsApprovedAssessment && !p.IsCurrentAssessment)
                {
                    enabled = true;
                }
            }
            _cmsi_Assessments_Delete.Enabled    = enabled;
            _cmsi_Assessments_Configure.Enabled = enabled;
        }
Exemple #21
0
 private void ultraListViewPolicies_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         UltraListViewSubItem item;
         item = ultraListViewPolicies.SubItemFromPoint(e.Location);
         if (item != null)
         {
             if (item.Key == "Manage")
             {
                 Policy policy = (Policy)item.Item.Tag;
                 if (policy != null)
                 {
                     Forms.Form_PolicyProperties.Process(policy.PolicyId, policy.AssessmentId, Program.gController.isAdmin, Forms.Form_PolicyProperties.RequestedOperation.ConfigureMetrics);
                     LoadData();
                 }
             }
         }
     }
 }
Exemple #22
0
        private void button_Import_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            string fileName = Forms.Form_ImportPolicy.Process();

            if (!string.IsNullOrEmpty(fileName))
            {
                Policy policy = new Policy();
                policy.ImportPolicyFromXMLFile(fileName, false);
                policy.IsSystemPolicy = false;
                if (Form_ImportExportPolicySecuriyChecks.ProcessImport(policy, Program.gController.isAdmin))
                {
                    m_importing = true;
                    loadPolicyMetrics();
                    m_policy.UpdatePolicyMetricsFromSelectedSecurityChecks(policy);
                }
            }

            Cursor = Cursors.Default;
        }
Exemple #23
0
        private void loadAssessmentsDataSource(int policyId, bool bUpdate)
        {
            _dt_Assessments.Clear();
            try
            {
                // Retrieve policy information.
                Repository.AssessmentList assessments = Program.gController.Repository.Policies.Find(policyId).Assessments;

                foreach (Sql.Policy p in assessments)
                {
                    if (!p.IsAssessment)
                    {
                        continue;
                    }

                    DataRow newRow = _dt_Assessments.NewRow();

                    newRow[colHeaderName]               = p.AssessmentName;
                    newRow[colHeaderDate]               = p.AssessmentDate.Value.ToLocalTime().ToString(Utility.Constants.DATETIME_FORMAT);
                    newRow[colHeaderConfiguredHigh]     = p.MetricCountHigh;
                    newRow[colHeaderConfiguredMedium]   = p.MetricCountMedium;
                    newRow[colHeaderConfiguredLow]      = p.MetricCountLow;
                    newRow[colHeaderRiskHigh]           = p.FindingCountHigh;
                    newRow[colHeaderRiskMedium]         = p.FindingCountMedium;
                    newRow[colHeaderRiskLow]            = p.FindingCountLow;
                    newRow[colHeaderDescription]        = p.AssessmentDescription;
                    newRow[colHeaderHiddenPolicyId]     = p.PolicyId;
                    newRow[colHeaderHiddenAssessmentId] = p.AssessmentId;
                    newRow[colHeaderState]              = p.AssessmentStateName;

                    if (p.FindingCountHigh > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.High;
                    }
                    else if (p.FindingCountMedium > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.Medium;
                    }
                    else if (p.FindingCountLow > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.Low;
                    }
                    else if (p.FindingCountHighExplained > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.HighExplained;
                    }
                    else if (p.FindingCountMediumExplained > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.MediumExplained;
                    }
                    else if (p.FindingCountLowExplained > 0)
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.LowExplained;
                    }
                    else
                    {
                        newRow[colHeaderStatus] = Utility.Policy.SeverityExplained.Ok;
                    }

                    _dt_Assessments.Rows.Add(newRow);
                }
            }
            catch (Exception ex)
            {
                logX.loggerX.Error(@"Error - Unable to retrieve Assessments", ex);
                Utility.MsgBox.ShowError(Utility.ErrorMsgs.CantGetLoginsCaption, ex);
            }

            this._grid_Assessments.BeginUpdate();
            this._grid_Assessments.DataSource = _dt_Assessments;
            this._grid_Assessments.DataMember = "";
            if (bUpdate)
            {
                this._grid_Assessments.EndUpdate();
            }

            Policy policy = Program.gController.Repository.GetPolicy(policyId);

            _label_Assessments.Text = string.Format(AssessmentsHeaderDisplay, policy.PolicyName, _grid_Assessments.Rows.Count.ToString());

            if (_grid_Assessments.Rows.Count == 0)
            {
                _label_NoAssessments.Visible = true;
                _grid_Assessments.Visible    = false;
            }
            else
            {
                _label_NoAssessments.Visible = false;
                _grid_Assessments.Visible    = true;
            }
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            try
            {
                // Is Policy name already used
                Policy p = Program.gController.Repository.GetPolicy(textBox_PolicyName.Text);
                if (p != null)
                {
                    MsgBox.ShowError("Error Creating Policy",
                                     string.Format("Cannot create policy {0}. A policy with the name you specified already exist. Specify a different policy name.", textBox_PolicyName.Text));
                    DialogResult = DialogResult.None;
                    return;
                }

                int policyId = -1;
                List <RegisteredServer> serversToAdd    = new List <RegisteredServer>();
                List <RegisteredServer> serversToRemove = new List <RegisteredServer>();

                foreach (ListViewItem server in listView_AddServers.CheckedItems)
                {
                    serversToAdd.Add((RegisteredServer)server.Tag);
                }

                if (!m_isCreateNew && m_orginalServersInPolicy != null)
                {
                    foreach (RegisteredServer r in m_orginalServersInPolicy)
                    {
                        bool isStillChecked = false;
                        foreach (ListViewItem server in listView_AddServers.CheckedItems)
                        {
                            if ((RegisteredServer)server.Tag == r)
                            {
                                isStillChecked = true;
                                break;
                            }
                        }
                        if (!isStillChecked)
                        {
                            serversToRemove.Add(r);
                        }
                    }

                    foreach (RegisteredServer rServer in serversToRemove)
                    {
                        RegisteredServer.RemoveRegisteredServerFromPolicy(rServer.RegisteredServerId, m_policy.PolicyId);
                    }
                }

                if (m_isCreateNew)
                {
                    policyId = Policy.AddPolicy(textBox_PolicyName.Text, false, string.Empty);
                    if (policyId != -1)
                    {
                        m_policy = Policy.GetPolicy(policyId);
                        controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy);
                        m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString);
                    }
                }
                else
                {
                    controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy);
                    m_policy.SetPolicyName(textBox_PolicyName.Text);
                    m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString);
                }

                foreach (RegisteredServer rServer in serversToAdd)
                {
                    RegisteredServer.AddRegisteredServerToPolicy(rServer.RegisteredServerId, policyId);
                }
            }
            catch (Exception ex)
            {
                string title = "Error Updating Policy";
                string msg   =
                    string.Format("Failed to Update policy {0} error message: {1}", textBox_PolicyName.Text, ex.Message);
                if (m_isCreateNew)
                {
                    title = "Error Creating Policy";
                    msg   =
                        string.Format("Failed to Create policy {0} error message: {1}", textBox_PolicyName.Text,
                                      ex.Message);
                }
                logX.loggerX.Error(msg);
                MsgBox.ShowError(title, msg);
            }
        }
        public Form_WizardCreatePolicy()
        {
            InitializeComponent();

            // Set the intro text in the wizard.
            _rtb_Introduction.Rtf = WizardIntroText;

            // Select the intro page.
            _wizard.SelectedPage = _page_Introduction;

            m_policy                  = new Policy();
            m_policy.IsDynamic        = true;
            m_policy.DynamicSelection = string.Empty;

            radioButtonCreateNew.Checked = true;

            // load value lists for listview display
            ValueList radioButtonValueList = new ValueList();

            radioButtonValueList.Key          = "RadioButton";
            radioButtonValueList.DisplayStyle = ValueListDisplayStyle.Picture;
            ValueListItem listItem;

            radioButtonValueList.ValueListItems.Clear();
            listItem                  = new ValueListItem(CheckState.Checked);
            listItem.DisplayText      = "Checked";
            listItem.Appearance.Image = AppIcons.AppImage16(AppIcons.Enum.RadioButtonChecked);
            radioButtonValueList.ValueListItems.Add(listItem);
            listItem                  = new ValueListItem(CheckState.Unchecked);
            listItem.DisplayText      = "UnChecked";
            listItem.Appearance.Image = AppIcons.AppImage16(AppIcons.Enum.RadioButtonUnChecked);
            radioButtonValueList.ValueListItems.Add(listItem);
            _ultraListViewStandardPolicies.SubItemColumns["CheckState"].ValueList = radioButtonValueList;


            // Load builtin standard Policies
            string path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

            path = path.Substring(0, path.LastIndexOf(Path.DirectorySeparatorChar));
            string policyPath = path + @"\" + Utility.Constants.Policy_Install_Folder;

            if (Directory.Exists(policyPath))
            {
                string[] files = Directory.GetFiles(policyPath);
                foreach (string f in files)
                {
                    Policy p = new Policy();
                    p.ImportPolicyFromXMLFile(f, false);
                    UltraListViewItem li = _ultraListViewStandardPolicies.Items.Add(p.PolicyName, p.PolicyName);
                    li.Tag = f;
                    li.SubItems["CheckState"].Value = CheckState.Unchecked;
                    li.SubItems["Count"].Value      = p.MetricCount;

                    //save the policy for displaying the description
                    m_Templates.Add(f, p);
                }
                if (_ultraListViewStandardPolicies.Items.Count > 0)
                {
                    _ultraListViewStandardPolicies.Items[0].SubItems["CheckState"].Value = CheckState.Checked;
                }
                _ultraListViewStandardPolicies.Enabled = false;
            }

            setTemplateDescription();
        }
        private void button_OK_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(textBox_PolicyName.Text.Trim()))
                {
                    ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General];
                    textBox_PolicyName.Focus();
                    MsgBox.ShowError(ERRORTITLE_CREATE, ERRORMSGNAMEEMPTY);
                    DialogResult = DialogResult.None;
                    return;
                }

                if (m_policy.IsPolicy)
                {
                    // Is Policy name already used
                    Policy p = Program.gController.Repository.GetPolicy(textBox_PolicyName.Text);
                    if (p != null && p.PolicyId != m_policy.PolicyId)
                    {
                        ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General];
                        textBox_PolicyName.Focus();
                        MsgBox.ShowError(ERRORTITLE_CREATE,
                                         string.Format(ERRORMSGDUP, textBox_PolicyName.Text));
                        DialogResult = DialogResult.None;
                        return;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(textBox_PolicyName.Text))
                    {
                        ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.General];
                        textBox_PolicyName.Focus();
                        MsgBox.ShowError(ERRORTITLE_CREATE, ERRORMSGNAMEEMPTY);
                        DialogResult = DialogResult.None;
                        return;
                    }

                    Policy p = Program.gController.Repository.GetPolicy(m_policy.PolicyId);
                    if (p.HasAssessment(textBox_PolicyName.Text))
                    {
                        Policy a = p.GetAssessment(textBox_PolicyName.Text);
                        if (a.AssessmentId != m_policy.AssessmentId)
                        {
                            MsgBox.ShowError(ERRORTITLE_UPDATE,
                                             string.Format(ERRORMSGDUP, textBox_PolicyName.Text, p.PolicyName));
                            DialogResult = DialogResult.None;

                            Cursor = Cursors.Default;
                            return;
                        }
                    }
                }
                if (!controlConfigurePolicyVulnerabilities1.OKToSave())
                {
                    ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.SecurityChecks];
                    DialogResult = DialogResult.None;
                    return;
                }
                if (controlConfigurePolicyVulnerabilities1.NumSecurityChecks == 0)
                {
                    if (DialogResult.No == MsgBox.ShowWarningConfirm(WARNINGTITLE, ErrorMsgs.NoPolicyMetricsMsg))
                    {
                        ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.SecurityChecks];
                        DialogResult = DialogResult.None;
                        return;
                    }
                }
                if (controlPolicyAddServers1.NumServers == 0)
                {
                    if (DialogResult.No == MsgBox.ShowWarningConfirm(WARNINGTITLE, ErrorMsgs.NoPolicyServersMsg))
                    {
                        ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[(int)FormTabs.Servers];
                        DialogResult = DialogResult.None;
                        return;
                    }
                }

                List <RegisteredServer> serversToAdd    = null;
                List <RegisteredServer> serversToRemove = null;
                string dynamicSelection = null;
                bool   isDynamic;
                controlPolicyAddServers1.GetServers(m_isCreateNew, out serversToAdd, out serversToRemove,
                                                    out dynamicSelection, out isDynamic);

                int policyId = -1;
                if (m_isCreateNew)
                {
                    policyId =
                        Policy.AddPolicy(textBox_PolicyName.Text, textBox_Description.Text, isDynamic, dynamicSelection, _policyInterview.InterviewName, _policyInterview.GetInterviewText());
                    if (policyId != -1)
                    {
                        m_policy = Policy.GetPolicy(policyId);
                        controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy);
                        m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString);
                    }
                }
                else
                {
                    policyId = m_policy.PolicyId;
                    controlConfigurePolicyVulnerabilities1.SaveMetricChanges(m_policy);
                    if (m_policy.IsAssessment)
                    {
                        m_policy.AssessmentName        = textBox_PolicyName.Text;
                        m_policy.AssessmentDescription = textBox_Description.Text;
                        m_policy.AssessmentNotes       = _textBox_Notes.Text;
                    }
                    else
                    {
                        m_policy.SetPolicyName(textBox_PolicyName.Text);
                        m_policy.PolicyDescription = textBox_Description.Text;
                    }
                    m_policy.IsDynamic        = isDynamic;
                    m_policy.DynamicSelection = dynamicSelection;
                    m_policy.InterviewName    = _policyInterview.InterviewName;
                    m_policy.InterviewText    = _policyInterview.GetInterviewText();

                    m_policy.SavePolicyToRepository(Program.gController.Repository.ConnectionString);
                }

                //list should be empty if dynamic
                if (!isDynamic)
                {
                    foreach (RegisteredServer rServer in serversToRemove)
                    {
                        RegisteredServer.RemoveRegisteredServerFromPolicy(rServer.RegisteredServerId, m_policy.PolicyId, m_policy.AssessmentId);
                    }

                    foreach (RegisteredServer rServer in serversToAdd)
                    {
                        RegisteredServer.AddRegisteredServerToPolicy(rServer.RegisteredServerId, policyId, m_policy.AssessmentId);
                    }
                }

                Program.gController.SignalRefreshPoliciesEvent(0);
            }
            catch (Exception ex)
            {
                string title = ERRORTITLE_UPDATE;
                string msg   =
                    string.Format(ERRORMSGFMT, textBox_PolicyName.Text, ex.Message);
                if (m_isCreateNew)
                {
                    title = ERRORTITLE_CREATE;
                    msg   =
                        string.Format(ERRORMSGFMT, textBox_PolicyName.Text, ex.Message);
                }
                logX.loggerX.Error(msg);
                MsgBox.ShowError(title, msg);
            }
        }