public async Task <IActionResult> Edit(int id, [Bind("Id,ProcedureID,Schedule,Status,User,Date")] ProcedureSchedule procedureSchedule) { if (id != procedureSchedule.Id) { return(NotFound()); } try { procedureSchedule.Date = DateTime.Now; procedureSchedule.User = User.Identity.Name; procedureSchedule.Status = 0; if (ModelState.IsValid) { _context.Update(procedureSchedule); await _context.SaveChangesAsync(); GALibrary.GALogs.SaveLog("ProcedureSchedule", "Fim da edicao do agendamento do procedimento " + procedureSchedule.Id + " realizada pelo usuario " + User.Identity.Name, 2, _context.Parameter.FirstOrDefault()); return(RedirectToAction(nameof(Index))); } ViewBag.procedureId = new SelectList(_context.Procedure.Where(x => x.Enable).OrderBy(x => x.Name), "Id", "Name", procedureSchedule.ProcedureID); ViewBag.procedureScheduleStatus = new SelectList(new[] { new { ID = "", Name = "Todos" }, new { ID = "0", Name = "Pendente" }, new { ID = "1", Name = "Realizada com sucesso" }, new { ID = "2", Name = "Realizada com erros" }, }, "ID", "Name", procedureSchedule.Status); return(View(procedureSchedule)); } catch (Exception erro) { GALibrary.GALogs.SaveLog("ProcedureSchedule", "Erro ao editar agendamento do procedimento " + procedureSchedule.Procedure.Name + " pelo usuario " + User.Identity.Name + ": " + erro.ToString(), 1, _context.Parameter.FirstOrDefault()); return(View("~/Views/Shared/Error.cshtml")); } }
static void ExecutaProcedureTask(Object stateInfo) { Models.GAContext context = new Models.GAContext(); Parameter parameter = context.Parameter.FirstOrDefault(); ProcedureSchedule procedureSchedule = (ProcedureSchedule)stateInfo; GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "Start", "Inicio do procedimento", 2, parameter); Lib.Updates.ExecuteProcedure(procedureSchedule); }
/* * private static Boolean AprovaAtualizacaoComRDM(UpdateGA update) * { * * var builder = new ConfigurationBuilder().SetBasePath(System.IO.Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); * IConfigurationRoot configuration = builder.Build(); * * * var traceGP = new Models.TraceGP(); * configuration.GetSection("TraceGP").Bind(traceGP); * * String stringConnection = traceGP.TraceGPConexao; * String select = traceGP.TraceGPSelect; * * * OracleConnection conn; * OracleCommand cmd = null; * conn = new OracleConnection(stringConnection); * * conn.Open(); * cmd = new OracleCommand(select, conn); * cmd.Parameters.Clear(); * cmd.Parameters.Add(":RDM", update.RDM); * * OracleDataReader reader = cmd.ExecuteReader(); * reader.Read(); * * if (!reader.HasRows) * { * return false; * } * * int resultado = Convert.ToInt16(reader.GetValue(0).ToString()); * * conn.Close(); * * if (resultado == 87 || resultado == 60 || resultado == 76 || resultado == 33) * { * return true; * } * * * return false; * }*/ public static void ExecuteProcedure(ProcedureSchedule procedureSchedule) { Models.GAContext context = new Models.GAContext(); GALibrary.Models.Parameter parameter = context.Parameter.FirstOrDefault(); var steps = context.ProcedureSteps.Where(x => x.ProcedureID == procedureSchedule.ProcedureID).ToList().OrderBy(x => x.Order); //Atualiza status para atualizando (3) procedureSchedule.Status = 3; context.Entry(procedureSchedule).State = EntityState.Modified; context.SaveChanges(); try { foreach (ProcedureSteps step in steps) { switch (step.Type) { case 3: GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "Command", "Inicio da execucao do comando", 2, parameter); UpdateCommand(null, procedureSchedule, step.ProcessId); GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "Command", "Fim da execucao do comando", 2, parameter); break; case 4: GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "ServiceStart", "Inicio do start de serviço", 2, parameter); UpdateServiceStart(null, procedureSchedule, step.ProcessId); GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "ServiceStart", "Fim do start de serviço", 2, parameter); break; case 5: GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "ServiceStop", "Inicio da parada de serviço", 2, parameter); UpdateServiceStop(null, procedureSchedule, step.ProcessId); GALibrary.GALogs.SaveLogProcedure(procedureSchedule, "ServiceStop", "Fim da parada de serviço", 2, parameter); break; } } procedureSchedule.Status = 1; context.Entry(procedureSchedule).State = EntityState.Modified; context.SaveChanges(); } catch { procedureSchedule.Status = 2; context.Entry(procedureSchedule).State = EntityState.Modified; context.SaveChanges(); } }
public static String UpdateServiceStop(UpdateGA update, ProcedureSchedule procedureschedule, int serviceId) { Models.GAContext context = new Models.GAContext(); GALibrary.Models.Parameter parameter = context.Parameter.FirstOrDefault(); Service service = context.Service.First(x => x.Id == serviceId); Server server = context.Server.Include(x => x.ServerUser).First(x => x.Id == service.ServerId); OS os = context.OS.First(x => x.Id == server.OSId); String result = ""; String comandoCompleto = os.AccessCommand; comandoCompleto = comandoCompleto.Replace("nomeDoServidor", server.Name); comandoCompleto = comandoCompleto.Replace("usuarioDeAcesso", GALibrary.GACrypto.Base64Decode(server.ServerUser.ServerUsername)); comandoCompleto = comandoCompleto.Replace("senhaDeAcesso", GALibrary.GACrypto.Base64Decode(server.ServerUser.ServerPassword)); comandoCompleto = comandoCompleto.Replace("comandoParaExecutar", service.CommandStop); try { if (update != null) { GALibrary.GALogs.SaveLogUpdate(update, "ServiceStop", "Procedimento - " + service.Name, 2, parameter); } else { GALibrary.GALogs.SaveLogProcedure(procedureschedule, "ServiceStop - " + service.Name, "Parando servico", 2, parameter); } System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + comandoCompleto); procStartInfo.RedirectStandardOutput = true; procStartInfo.CreateNoWindow = true; procStartInfo.UseShellExecute = false; System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.StartInfo = procStartInfo; proc.Start(); result = proc.StandardOutput.ReadToEnd(); if (update != null) { GALibrary.GALogs.SaveLogUpdate(update, "ServiceStop - " + service.Name, "Retorno: " + result, 2, parameter); } else { GALibrary.GALogs.SaveLogProcedure(procedureschedule, "ServiceStop - " + service.Name, "Retorno: " + result, 2, parameter); } } catch (Exception error) { if (update != null) { GALibrary.GALogs.SaveLogUpdate(update, "ServiceStop - " + service.Name, error.ToString(), 1, parameter); } else { GALibrary.GALogs.SaveLogProcedure(procedureschedule, "ServiceStop - " + service.Name, error.ToString(), 1, parameter); } return(error.ToString()); } return(result); }