public static PolicyMetricConfiguration GetNAConfiguration() { var naConfiguration = new PolicyMetricConfiguration(); naConfiguration.m_MetricName = naConfiguration.m_MetricDescription = naConfiguration.m_ValidValues = naConfiguration.m_ValueDescription = naConfiguration.m_ReportKey = naConfiguration.m_ReportText = naConfiguration.m_SeverityValues = new SqlString(Utility.Constants.POLICY_METRIC_CONSTANT_NOT_APPLICABLE); return(naConfiguration); }
private void setValues(SqlDataReader rdr) { m_PolicyId = rdr.GetSqlInt32((int)PolicyColumn.PolicyId); m_AssessmentId = rdr.GetSqlInt32((int)PolicyColumn.AssessmentId); m_PolicyName = rdr.GetSqlString((int)PolicyColumn.PolicyName); m_MetricId = rdr.GetSqlInt32((int)PolicyColumn.MetricId); m_MetricType = rdr.GetSqlString((int)PolicyColumn.MetricType); m_MetricName = rdr.GetSqlString((int)PolicyColumn.MetricName); m_MetricDescription = rdr.GetSqlString((int)PolicyColumn.MetricDescription); m_IsUserEntered = rdr.GetSqlBoolean((int)PolicyColumn.IsUserEntered); m_IsMultiSelect = rdr.GetSqlBoolean((int)PolicyColumn.IsMultiSelect); m_ValidValues = rdr.GetSqlString((int)PolicyColumn.ValidValues); m_ValueDescription = rdr.GetSqlString((int)PolicyColumn.ValueDescription); m_IsEnabled = rdr.GetSqlBoolean((int)PolicyColumn.IsEnabled); m_ReportKey = rdr.GetSqlString((int)PolicyColumn.ReportKey); m_ReportText = rdr.GetSqlString((int)PolicyColumn.ReportText); m_Severity = rdr.GetSqlInt32((int)PolicyColumn.Severity); m_SeverityValues = rdr.GetSqlString((int)PolicyColumn.SeverityValues); m_AzureSQLDatabaseConfiguration = PolicyMetricConfiguration.GetNAConfiguration(); }
public static List <PolicyMetric> GetPolicyMetrics(string connectionString, int policyId, int?assessmentId) { List <PolicyMetric> policyMetricList = new List <PolicyMetric>(); try { if (!string.IsNullOrEmpty(connectionString)) { // Retrieve server information. logX.loggerX.Info("Retrieve Policies Metrics"); using (SqlConnection connection = new SqlConnection(connectionString)) { // Open the connection. connection.Open(); SqlParameter paramPolicyId = new SqlParameter(ParamPolicyId, policyId); SqlParameter paramAssessmentId = new SqlParameter(ParamAssessmentId, assessmentId); using (SqlDataReader rdr = Sql.SqlHelper.ExecuteReader(connection, null, CommandType.Text, assessmentId.HasValue ? QueryGetAssessmentMetrics : QueryGetPolicyMetrics, assessmentId.HasValue ? new SqlParameter[] { paramPolicyId, paramAssessmentId } : new SqlParameter[] { paramPolicyId })) { while (rdr.Read()) { PolicyMetric policyMetric = new PolicyMetric(rdr); policyMetricList.Add(policyMetric); } } logX.loggerX.Info("Retrieving Policies Metrics Extended Information."); // SQLsecure 3.1 (Anshul Aggarwal) - Fetch extended info values for metrics. using (SqlDataReader rdr = Sql.SqlHelper.ExecuteReader(connection, null, CommandType.Text, assessmentId.HasValue ? QueryGetAssessmentMetricsExtendedInfo : QueryGetPolicyMetricsExtendedInfo, assessmentId.HasValue ? new SqlParameter[] { paramPolicyId, paramAssessmentId } : new SqlParameter[] { paramPolicyId })) { while (rdr.Read()) { PolicyMetricConfiguration configuration = new PolicyMetricConfiguration(rdr); if (configuration.ServerType == ServerType.AzureSQLDatabase) { var matchingPolicyMetric = policyMetricList.Find(pm => pm.MetricId == configuration.MetricId); if (matchingPolicyMetric != null) { matchingPolicyMetric.m_AzureSQLDatabaseConfiguration = configuration; } } } } } } } catch (SqlException ex) { logX.loggerX.Error(string.Format(Utility.ErrorMsgs.ErrorStub, Utility.ErrorMsgs.CantGetPolicies), ex); MsgBox.ShowError(Utility.ErrorMsgs.CantGetPolicies, ex.Message); } catch (Exception ex) { logX.loggerX.Error(string.Format(Utility.ErrorMsgs.ErrorStub, Utility.ErrorMsgs.CantGetPolicies), ex); MsgBox.ShowError(Utility.ErrorMsgs.CantGetPolicies, ex.Message); } return(policyMetricList); }