static void diagLogTest() { DiagLog.Log("log always"); DiagLog.LogLevel(LoggingLevel.DEBUG, "debugMsg"); DiagLog.LogLevel(LoggingLevel.INFO, "infoMsg"); DiagLog.LogLevel(LoggingLevel.WARN, "warnMsg"); DiagLog.LogLevel(LoggingLevel.ERROR, "errMsg"); DiagLog.Level = LoggingLevel.ERROR; DiagLog.Log("ERRROR level on"); DiagLog.LogLevel(LoggingLevel.DEBUG, "debugMsg"); DiagLog.LogLevel(LoggingLevel.INFO, "infoMsg"); DiagLog.LogLevel(LoggingLevel.WARN, "warnMsg"); DiagLog.LogLevel(LoggingLevel.ERROR, "errMsg"); DiagLog.Level = LoggingLevel.ALL; DiagLog.Log("ALL level on"); DiagLog.LogLevel(LoggingLevel.DEBUG, "debugMsg"); DiagLog.LogLevel(LoggingLevel.INFO, "infoMsg"); DiagLog.LogLevel(LoggingLevel.WARN, "warnMsg"); DiagLog.LogLevel(LoggingLevel.ERROR, "errMsg"); string fileName = DiagLog.LogFileName; DiagLog.LogFileName = @"C:\public\Test2.log"; fileName = DiagLog.LogFileName; DiagLog.Level = LoggingLevel.ALL; DiagLog.Log("ALL level on"); DiagLog.LogLevel(LoggingLevel.DEBUG, "debugMsg"); DiagLog.LogLevel(LoggingLevel.INFO, "infoMsg"); DiagLog.LogLevel(LoggingLevel.WARN, "warnMsg"); DiagLog.LogLevel(LoggingLevel.ERROR, "errMsg"); }
private void loadDataSource() { //Debug.Assert(!m_snapshotId.Equals(0)); try { // Open connection to repository and query permissions. DiagLog.LogInfo("Retrieve User Permissions"); using (SqlConnection connection = new SqlConnection(Program.gController.Repository.ConnectionString)) { // Open the connection. connection.Open(); // Setup register server params. SqlParameter paramSnapshotId = new SqlParameter(ParamGetPermissionsSnapshotId, m_snapshotId); SqlParameter paramLoginType = new SqlParameter(ParamGetPermissionsLoginType, m_loginType); SqlParameter paramSid = new SqlParameter(ParamGetPermissionsSid, m_user.Sid.BinarySid); SqlParameter paramSqlLogin = new SqlParameter(ParamGetPermissionsSqlLogin, m_user.Name); SqlParameter paramDatabase = new SqlParameter(ParamGetPermissionsDatabase, m_database); SqlCommand cmd = new SqlCommand(QueryGetPermissions, connection); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandTimeout = 90; // The permissions take > 30 secs on a 2005 server cmd.Parameters.Add(paramSnapshotId); cmd.Parameters.Add(paramLoginType); cmd.Parameters.Add(paramSid); cmd.Parameters.Add(paramSqlLogin); cmd.Parameters.Add(paramDatabase); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); //Build Explicit Permissions datasource this._grid_Explicit.BeginUpdate(); DataView dv_Explicit = new DataView(ds.Tables[0]); dv_Explicit.RowFilter = string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit); this._grid_Explicit.DataSource = dv_Explicit; this._grid_Explicit.DataMember = ""; this._grid_Explicit.EndUpdate(); //Build Effective/Assigned Permissions datasource this._grid_Effective.BeginUpdate(); DataView dv_Effective = new DataView(ds.Tables[0]); dv_Effective.RowFilter = string.Format(FilterPermissionType, Utility.Permissions.Type.Effective); this._grid_Effective.DataSource = dv_Effective; this._grid_Effective.DataMember = ""; this._grid_Effective.EndUpdate(); //Build Server Logins datasource this._grid_Server.BeginUpdate(); DataView dv_Server = new DataView(ds.Tables[0]); dv_Server.RowFilter = string.Format(@"{0} AND {1}", string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit), string.Format(FilterPermissionLevel, Utility.Permissions.Level.Server) ); DataTable dt_Server = dv_Server.ToTable(true, new string[] { colPrincipalName, colPrincipalType }); dv_Server = dt_Server.DefaultView; dv_Server.Sort = colPrincipalName; this._grid_Server.DataSource = dv_Server; this._grid_Server.DataMember = ""; this._grid_Server.DisplayLayout.Bands[0].Columns.Add(); this._grid_Server.EndUpdate(); //Build Database Logins datasource this._grid_Database.BeginUpdate(); DataView dv_Database = new DataView(ds.Tables[0]); dv_Database.RowFilter = string.Format(@"{0} AND {1}", string.Format(FilterPermissionType, Utility.Permissions.Type.Explicit), string.Format(FilterPermissionLevel, Utility.Permissions.Level.Database) ); DataTable dt_Database = dv_Database.ToTable(true, new string[] { colDatabasePrincipalName, colDatabasePrincipalType }); dv_Database = dt_Database.DefaultView; dv_Database.Sort = colDatabasePrincipalName; this._grid_Database.DataSource = dv_Database; this._grid_Database.DataMember = ""; this._grid_Database.DisplayLayout.Bands[0].Columns.Add(); this._grid_Database.EndUpdate(); //Build Raw data grid datasource for use in testing and development this._grid.BeginUpdate(); this._grid.DataSource = ds.Tables[0]; this._grid.DataMember = ""; this._grid.EndUpdate(); m_snapshotId_shown = m_snapshotId; m_loginType_shown = m_loginType; m_user_shown = m_user; m_database_shown = m_database; } } catch (SqlException ex) { DiagLog.LogError(@"Error - Unable to retrieve user permissions", ex); MsgBox.ShowError(Utility.ErrorMsgs.CantGetUserPermissionsCaption, ex.Message); checkSelections(); } }
private void loadDataSource() { m_snapshots = Snapshot.LoadSnapshots(m_serverInstance.ConnectionName); m_dt_snapshots.Clear(); Image iconImage; Image automatedImage; Image baselineImage; string status; foreach (Snapshot snap in m_snapshots) { switch (snap.Status) { case Utility.Snapshot.StatusInProgress: iconImage = _imageList.Images[0]; status = Utility.Snapshot.StatusInProgressText; break; case Utility.Snapshot.StatusWarning: iconImage = _imageList.Images[0]; status = Utility.Snapshot.StatusWarningText; break; case Utility.Snapshot.StatusError: iconImage = _imageList.Images[1]; status = Utility.Snapshot.StatusErrorText; break; case Utility.Snapshot.StatusSuccessful: iconImage = _imageList.Images[0]; status = Utility.Snapshot.StatusSuccessfulText; break; default: //Debug.Assert(false, "Unknown status encountered"); DiagLog.LogWarn("Warning - unknown Snapshot status encountered", snap.Status); iconImage = _imageList.Images[1]; status = Utility.Snapshot.StatusUnknownText; break; } switch (snap.Automated) { case Utility.Snapshot.AutomatedTrue: automatedImage = _imageList.Images[3]; break; case Utility.Snapshot.AutomatedFalse: automatedImage = null; break; default: DiagLog.LogWarn("Warning - unknown Snapshot automated indicator encountered", snap.Automated); automatedImage = null; break; } switch (snap.Baseline) { case Utility.Snapshot.BaselineTrue: baselineImage = _imageList.Images[2]; break; case Utility.Snapshot.BaselineFalse: baselineImage = null; break; default: DiagLog.LogWarn("Warning - unknown Snapshot baseline indicator encountered", snap.Baseline); baselineImage = null; break; } m_dt_snapshots.Rows.Add(iconImage, snap.SnapshotId, snap.StartTime.Date, snap.StartTime, //snap.StartTime.TimeOfDay.Subtract(new TimeSpan(0, 0, 0, 0, snap.StartTime.Millisecond)), automatedImage, status, snap.SnapshotComment, baselineImage, snap.BaselineComment, snap.NumObject, snap.NumPermission, snap.NumLogin, snap.NumWindowsGroupMember); } m_dt_snapshots.DefaultView.Sort = colStartTime + " Desc"; this._grid.BeginUpdate(); this._grid.DataSource = m_dt_snapshots.DefaultView; this._grid.DataMember = ""; this._grid.EndUpdate(); }