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 bool WriteActionLog(ActionLog actionLog) { try { short hadError; if (actionLog.HadError) { hadError = 1; } else { hadError = 0; } Domain.Local.Logs.ActionLogs newActionLog = new Domain.Local.Logs.ActionLogs { installation = session.Get <TUFStatus.Domain.Local.App.Installations> (actionLog.InstallationID), application_id = (int)actionLog.ApplicationID, action_type_id = (int)actionLog.ActionTypeID, gear_code = actionLog.GearCode, action_time = actionLog.ActionTime, action_result = actionLog.ActionResult, action_messages = actionLog.ActionMessage, had_error = hadError, is_transferred = 0 }; var repository = new TUFStatus.DAL.Repositories.Repository <ISession, Domain.Local.Logs.ActionLogs>(session); using (var xa = session.BeginTransaction()) { repository.Add(newActionLog); xa.Commit(); //Assert.NotNull(fad); //Assert.AreNotEqual(0, fad.Id); } } catch (Exception ex) { ErrorHandler.Instance.HandleError(ActionLog.ActionTypes.Application, "", "There was an error writing the local action log:", ex.Message); return(false); } return(true); }
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 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); }
public bool WriteActionLog(ActionLog ActionLog) { throw new NotImplementedException(); }