public ActionLog RunSPCSync() { ActionLog actionLog = null; int result = 0; string message = ""; bool error = false; ActionLog.ActionTypes actionTypeID = ActionLog.ActionTypes.Syncronisation; if (run_sync > 0) { try { Classes.Synchroniser synchroniser = new Classes.Synchroniser(); result = synchroniser.SynchroniseWithSPC((CloudStatusDB)Program.cloudStatusDB); message = "Syncronisation successful"; } catch (Exception ex) { error = true; message = ex.Message; ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error running the SPC Sync", ex.Message); } actionLog = new ActionLog(installation_id, ApplicationList.TUFStatus, actionTypeID, "", result, message, error); } return(actionLog); }
public ErrorLog(int InstID, TUFMANInstallation.ApplicationList AppID, ActionLog.ActionTypes ActionTypeID, string GearCode, string ErrorInfo, string ErrorMSG) { _InstallationID = InstID; _ApplicationID = AppID; _ActionTypeID = ActionTypeID; _GearCode = GearCode; _ErrorTime = System.DateTime.Now; _ErrorInfo = ErrorInfo; _ErrorMessage = ErrorMSG; }
public ActionLog(int InstID, TUFMANInstallation.ApplicationList AppID, ActionLog.ActionTypes ActionTypeID, string GearCode, int ActionResult, string ActionMSG, Boolean HadError) { _InstallationID = InstID; _ApplicationID = AppID; _ActionTypeID = ActionTypeID; _GearCode = GearCode; _ActionTime = System.DateTime.Now; _ActionResult = ActionResult; _ActionMessage = ActionMSG; _HadError = HadError; }
public ActionLog RunLicenseLinking(int mode) { ActionLog actionLog; int result = 0; bool error = false; string message; SqlConnection sqlConnection = new SqlConnection(); SqlCommand sqlCommand = new SqlCommand(); SqlParameter sqlParameter = new SqlParameter(); ActionLog.ActionTypes actionTypeID = ActionLog.ActionTypes.TUFMANLicenseLinking; try { sqlConnection.ConnectionString = GetConnectionString(); sqlConnection.Open(); sqlCommand.Connection = sqlConnection; sqlCommand.CommandType = System.Data.CommandType.Text; sqlCommand.CommandTimeout = 600; sqlCommand.CommandText = "DECLARE @nResult int; exec @nResult = tufman.update_all_lic_links " + mode + "; SELECT @nResult"; result = (int)sqlCommand.ExecuteScalar(); // report success to the log message = "License link successful, mode=" + mode; } catch (Exception ex) { error = true; message = ex.Message; ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error running the license linking, mode=" + mode, ex.Message); } finally { if (sqlConnection.State == System.Data.ConnectionState.Open) { sqlConnection.Close(); } } // Setup Action log actionLog = new ActionLog(installation_id, ApplicationList.TUFStatus, actionTypeID, "", result, message, error); return(actionLog); }
public ActionLog RunRaiseCatch(string gearcode, int mode) { ActionLog actionLog = null; int result = 0; string message = ""; bool error = false; SqlConnection sqlConnection = new SqlConnection(); SqlCommand sqlCommand = new SqlCommand(); SqlParameter sqlParameter = new SqlParameter(); ActionLog.ActionTypes actionTypeID = ActionLog.ActionTypes.TUFMANRecon; try { sqlConnection.ConnectionString = GetConnectionString(); sqlConnection.Open(); sqlCommand.Connection = sqlConnection; sqlCommand.CommandType = System.Data.CommandType.Text; sqlCommand.CommandTimeout = 600; sqlCommand.CommandText = "DECLARE @nResult int; exec @nResult = tufman.raise_catches_from_unloadings_" + gearcode + "; SELECT @nResult"; result = (int)sqlCommand.ExecuteScalar(); // report success to the log message = "Raise catch for " + gearcode + " successful"; } catch (Exception ex) { error = true; message = ex.Message; ErrorHandler.Instance.HandleError(actionTypeID, gearcode, "There was an error raising catch", ex.Message); } finally { if (sqlConnection.State == System.Data.ConnectionState.Open) { sqlConnection.Close(); } } actionLog = new ActionLog(installation_id, ApplicationList.TUFStatus, actionTypeID, gearcode, result, message, error); return(actionLog); }
public void HandleError(ActionLog.ActionTypes actionID, string gearcode, string info, string errMessage, bool writeToDB = true) { if (useMessageBox) { string message; message = info + Environment.NewLine + Environment.NewLine + errMessage; MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // save error to the local DB if (writeToDB) { ErrorLog errorLog = new ErrorLog(Program.TufmanInstallationID, TUFStatus.TUFMANInstallation.ApplicationList.TUFStatus, actionID, gearcode, info, errMessage); if (localStatusDB != null) { localStatusDB.WriteErrorLog(errorLog); } } // write to the local log file textLog.WriteErrorLog(gearcode, info, errMessage); }
public ActionLog RunDBBackup(int mode) { ActionLog actionLog = null; int result = 0; string message = ""; bool error = false; SqlConnection sqlConnection = new SqlConnection(); SqlCommand sqlCommand = new SqlCommand(); SqlParameter sqlParameter = new SqlParameter(); ActionLog.ActionTypes actionTypeID = ActionLog.ActionTypes.TUFMANBackup; string strSQL; string filename; string compressedFilename; string backupPath; string backupCopyPath; filename = tufman_database + "_day_" + ((System.DateTime.Now.Day) % 7).ToString(); backupPath = backup_folder; backupCopyPath = backup_copy_folder; if ((backupPath != null) && (backupPath.Length > 0)) { strSQL = "BACKUP DATABASE " + tufman_database + " TO DISK = N'" + backupPath + "\\" + filename + ".bak" + "' " + " WITH RETAINDAYS = 21, NAME = N'Full Database Backup', " + " NOFORMAT, INIT, SKIP, NOREWIND, NOUNLOAD, STATS = 10,CONTINUE_AFTER_ERROR"; try { sqlConnection.ConnectionString = GetConnectionString(); sqlConnection.Open(); sqlCommand.Connection = sqlConnection; sqlCommand.CommandType = System.Data.CommandType.Text; sqlCommand.CommandTimeout = 0; sqlCommand.CommandText = strSQL; result = (int)sqlCommand.ExecuteNonQuery(); // report success to the log message = "Backup successful to " + backupPath + "\\" + filename + ".bak" + ", mode=" + mode; try { // compress file and create weekly and monthly backup files if (System.IO.File.Exists(backupPath + "\\7za.exe")) { compressedFilename = filename + ".zip"; // delete file if it exists if (System.IO.File.Exists(backupPath + "\\" + compressedFilename)) { System.IO.File.Delete(backupPath + "\\" + compressedFilename); } // compress string strCommand; strCommand = "a -tzip " + filename + ".zip " + filename + ".bak"; //MessageBox.Show(strCommand) System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo(); processStartInfo.FileName = "7za.exe"; processStartInfo.Arguments = strCommand; processStartInfo.WorkingDirectory = backupPath; System.Diagnostics.Process process = System.Diagnostics.Process.Start(processStartInfo); process.WaitForExit(); // delete original backup file if compressed file successful if (System.IO.File.Exists(backupPath + "\\" + compressedFilename)) { System.IO.File.Delete(backupPath + "\\" + filename + ".bak"); } // copy to weekly and monthly, and to backup_copy if setup string fileCopyName; if (System.IO.Directory.Exists(backupCopyPath)) { System.IO.File.Copy(backupPath + "\\" + compressedFilename, backupCopyPath + "\\" + compressedFilename, true); } // weekly fileCopyName = tufman_database + "_wk_" + (((int)(System.DateTime.Now.Day + 1) / 7) + 1).ToString() + ".zip"; System.IO.File.Copy(backupPath + "\\" + compressedFilename, backupPath + "\\" + fileCopyName, true); System.IO.File.Copy(backupPath + "\\" + fileCopyName, backupCopyPath + "\\" + fileCopyName, true); // monthly fileCopyName = tufman_database + "_mon_" + System.DateTime.Now.Month.ToString("00") + ".zip"; System.IO.File.Copy(backupPath + "\\" + compressedFilename, backupPath + "\\" + fileCopyName, true); System.IO.File.Copy(backupPath + "\\" + fileCopyName, backupCopyPath + "\\" + fileCopyName, true); } else { // report that 7za doesn't exist ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error compressing or copying the backups", "7za.exe not found"); } } catch (Exception ex) { ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error compressing or copying the backups", ex.Message); } } catch (Exception ex) { error = true; message = ex.Message; ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error backing up the DB, mode==" + mode, ex.Message); ErrorHandler.Instance.HandleError(actionTypeID, "", "There was an error backing up the DB, mode==" + mode, strSQL); } finally { if (sqlConnection.State == System.Data.ConnectionState.Open) { sqlConnection.Close(); } } } else { error = true; message = "There is no backup folder set"; } actionLog = new ActionLog(installation_id, ApplicationList.TUFStatus, actionTypeID, "", result, message, error); return(actionLog); }