コード例 #1
0
        private void CarryOnDoctor()
        {
            try
            {
                var doctorUri          = ConfigurationManager.AppSettings["DoctorMonkeyUri"];
                var doctorWebApiClient = new HttpClient();

                var registrants = doctorWebApiClient.GetAsync($"{doctorUri}/Registrants").Result;
                var content     = registrants.Content.ReadAsStringAsync().Result;

                var patients     = _monkeyHelper.Registrants(content).ToList();
                var sickPatients = _monkeyHelper.GetHostServiceInfo(patients)
                                   .Where(x => x.ServiceStatus == ServiceHostStatus.Stopped ||
                                          x.ServiceStatus == ServiceHostStatus.Stopping).ToList();

                WriteToEventLog("Registered patients: " + JsonConvert.SerializeObject(patients.Select(x => x.ServiceDescription)), EventLogEntryType.SuccessAudit);

                if (sickPatients.Any())
                {
                    WriteToEventLog("Patients feeling unwell: " + JsonConvert.SerializeObject(sickPatients.Select(x => x.Service)), EventLogEntryType.SuccessAudit);

                    foreach (var patient in sickPatients)
                    {
                        WriteToEventLog("Fixing Patient: " + patient.Service + " on " + patient.Host, EventLogEntryType.SuccessAudit);
                        var reply = doctorWebApiClient
                                    .GetAsync($"{doctorUri}/Start{patient.Type}?host={patient.Host}&service={patient.Service}")
                                    .Result;

                        var patientStatus = _monkeyHelper.PatientCheckUp(patient);

                        WriteToEventLog($"{patient.Service} on {patient.Host} : {patientStatus}", EventLogEntryType.Information);
                    }
                }
                else
                {
                    WriteToEventLog("All registered patients are feeling happy :)", EventLogEntryType.SuccessAudit);
                }
            }
            catch (Exception ex)
            {
                WriteToEventLog($"CarryOnDoctor() ERROR: {ex.Message}", EventLogEntryType.Error);
                throw;
            }
        }