private void executerSucces_Click(object sender, RoutedEventArgs e) { _logWriter.LogWrite($"exécution Batch : {cheminBatchSucces}"); string output = processBatch(cheminBatchSucces); _logWriter.LogWrite($"exit code Batch : {exitCode}"); if (exitCode == 0 /*un deuxieme exitCode*/) { var numbers = Regex.Split(output, @"\D+") .Where(s => !string.IsNullOrWhiteSpace(s)) .Select(s => int.Parse(s)).ToList(); var dt = DateTime.Now.AddDays(-numbers[0]).AddHours(-numbers[1]) .AddMinutes(-numbers[2]).AddSeconds(-numbers[3]); //DateTime dt = DateTime.Parse(output, "dd mm yyyy"); //Logique après retour positif /* * exitCode == DcMaster * ExitCode2 == DcCoordnateur */ //Execute psinfo here //Retrieve Response uptime string //Convert format to Timespan //Substract timespan from current date //If it was 15 days ago or more, then reboot _logWriter.LogWrite($"date dernier upTime : {dt}"); #if !DEBUG var api = new IO.Swagger.Api.AuthorizationsApi(); try { var result = api.AuthorizationsPostAuthorization("DcMaster1", "DeploymentCoord1", "10.19.15.12", DateTime.Now.AddDays(-12)); } catch (Exception ex) { throw; } // Log // blocage screen // commande de redemarrage #endif } }
private void executerSucces_Click(object sender, RoutedEventArgs e) { try { AuthorizationModel authorizationResult = null; Restaurant restaurant = null; _logWriter.LogWrite($"exécution Batch : {cheminBatchSucces}"); //string output = UptimeHelper.processBatch(cheminBatchSucces, ServerName, _logWriter, ref exitCode); _logWriter.LogWrite($"exit code Batch : {exitCode}"); if (exitCode != 0) { } if (exitCode == 0) { var uptime = 18;// UptimeHelper.GetUptime(output,_logWriter); DateTime?LastBootTime = DateTime.Now.AddDays(-uptime); //TODO //string ServerIpAddress = IpAddressHelper.CcToIp(ServerName); _logWriter.LogWrite($"date dernier upTime : {uptime} days ago"); _logWriter.LogWrite($"date dernier LastBootTime : {LastBootTime.Value} "); //gestion des exceptions pour apres authorizationResult = AuthorizationsApi.AuthorizationsPostAuthorization(ServerIpAddress, LastBootTime); restaurant = RestaurantsApi.RestaurantsGetRestaurant(ServerIpAddress); //authorizationResult = new IO.Swagger.Model.AuthorizationModel(); //authorizationResult.StatusCode = "OK"; //restaurant = new Restaurant { RestaurantId = 16 , OpeningDate = DateTime.Now}; IO.Swagger.Model.ServerEvent event_ = null; if (authorizationResult.StatusCode == "OK") { // blocage de l'interface var _bloquerWindow = new bloquerWindow(_logWriter, ServerIpAddress, restaurant.RestaurantId.Value); _bloquerWindow.Show(); this.Close(); } else { // Specifié la raison du rejet Event.demandeRejete + DAte du rejet ServerEventsApi.ServerEventsPostServerEvent(new IO.Swagger.Model.ServerEvent() { Date = DateTime.Now, Event = IO.Swagger.Model.ServerEvent.EventEnum.NUMBER_4, RestaurantId = restaurant.RestaurantId.Value, Detail = authorizationResult.Detail }); } } } catch (Exception ex) { _logWriter.LogWrite($" ClassName : MainWindow "); _logWriter.LogWrite($" Exception : {ex.Message}"); _logWriter.LogWrite($" Exception : {ex.StackTrace}"); throw; } }