private async Task <bool> UpdateStatusDateTimeUpload(Model.ModelBackupSchedule _backupSchedule, Model.Enum.BackupStatus bkpStatus, ModelTaskServiceSettings _setting) { try { bool isValid = true; switch (bkpStatus) { case Model.Enum.BackupStatus.Success: { //TimeSpan? allTime = null; //allTime = (_backupSchedule.BackupExecDateHourStart - DateTime.Now); //_backupSchedule.BackupExecTotalTime = Convert.ToInt32(allTime); _backupSchedule.UploadDateHourFinish = DateTime.Now; var resp = await UpdateStatusBackup(_backupSchedule, Model.Enum.BackupStatus.Success, true, _setting); if (resp != "sucess") { isValid = false; } break; } case Model.Enum.BackupStatus.Failed: { //TimeSpan? allTime = null; //allTime = (_backupSchedule.BackupExecDateHourStart - DateTime.Now); //_backupSchedule.BackupExecTotalTime = Convert.ToInt32(allTime); _backupSchedule.UploadDateHourFinish = DateTime.Now; var resp = await UpdateStatusBackup(_backupSchedule, Model.Enum.BackupStatus.Failed, true, _setting); if (resp != "sucess") { isValid = false; } break; } case Model.Enum.BackupStatus.Runing: { _backupSchedule.UploadDateHourStart = DateTime.Now; var respUpd = await UpdateStatusBackup(_backupSchedule, Model.Enum.BackupStatus.Runing, false, _setting); if (respUpd != "sucess") { isValid = false; } break; } case Model.Enum.BackupStatus.Corrupted: { //TimeSpan? allTime = null; //allTime = (_backupSchedule.BackupExecDateHourStart - DateTime.Now); //_backupSchedule.BackupExecTotalTime = Convert.ToInt32(allTime); _backupSchedule.UploadDateHourFinish = DateTime.Now; var resp = await UpdateStatusBackup(_backupSchedule, Model.Enum.BackupStatus.Corrupted, true, _setting); if (resp != "sucess") { isValid = false; } break; } case Model.Enum.BackupStatus.None: { break; } case Model.Enum.BackupStatus.OutOfDate: { //TimeSpan? allTime = null; //allTime = (_backupSchedule.BackupExecDateHourStart - DateTime.Now); //_backupSchedule.BackupExecTotalTime = Convert.ToInt32(allTime); _backupSchedule.UploadDateHourFinish = DateTime.Now; var resp = await UpdateStatusBackup(_backupSchedule, Model.Enum.BackupStatus.OutOfDate, true, _setting); if (resp != "sucess") { isValid = false; } break; } } return(isValid); } catch (Exception err) { throw err; } }
public async Task <string> ExecShrink(Model.ModelBackupSchedule _backupSchedule, Model.Enum.BackupStatus bkpStatus, bool bkpIsRunning, ModelTaskServiceSettings _setting) { UtilitariosInfra.UtilTelegram _utilTelegram = new UtilitariosInfra.UtilTelegram(_setting.UidTelegramToken); try { string url = "http://" + _backupSchedule.CustomerProduct.Server.IpAddress + ":" + _backupSchedule.CustomerProduct.Server.Port; _backupSchedule.BackupStatus = bkpStatus; var json = JsonConvert.SerializeObject(_backupSchedule); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var streamResult = await client.PostAsync(url + "/api/DatabaseService/Shrink", stringContent); if (!streamResult.IsSuccessStatusCode) { return(await streamResult.Content.ReadAsStringAsync()); } return("sucess"); } catch (Exception err) { _utilTelegram.SendMessage($"Falha na atualização Status: {_backupSchedule.Databases.DatabaseName}:{_backupSchedule.DateHourExecution.ToShortTimeString()}\n {err.Message}", _setting.UidTelegramDestino); return("false"); } }
public async Task <bool> UpdateStatusBackup(Model.ModelBackupSchedule _backupSchedule, Model.Enum.BackupStatus bkpStatus, bool bkpIsRunning) { string url = "http://" + _backupSchedule.CustomerProduct.Server.IpAddress + ":" + _backupSchedule.CustomerProduct.Server.Port; _backupSchedule.BackupStatus = bkpStatus; var json = JsonConvert.SerializeObject(_backupSchedule); var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); var streamResult = await client.PutAsync(url + "/api/DatabaseSchedule/UpdateStatus", stringContent); if (!streamResult.IsSuccessStatusCode) { return(false); } return(true); }