public void ProcessAzureStatus()
        {
            try
            {
                AzureStatus azureStatus = AzureStatusEngine.GetAzureStatus();

                foreach (Service service in azureStatus.Services)
                {
                    Model.Service serviceDb = GetServiceDbByServiceId(service.Id);

                    if (serviceDb == null)
                    {
                        serviceDb = CreateServiceDb(service);
                    }

                    foreach (Region region in service.Regions)
                    {
                        Model.Region regionDb = GetRegionDbByRegionId(region.Id);

                        if (regionDb == null)
                        {
                            regionDb = CreateRegionDb(region);
                        }

                        Model.ServiceStatus serviceStatusDb = GetServiceStatusByServiceIdandRegionId(service, region);

                        if (serviceStatusDb == null)
                        {
                            serviceStatusDb = CreateServiceStatus(serviceDb, regionDb, (Model.Status)Enum.Parse(typeof(Model.Status), region.Status));
                        }
                        else
                        {
                            UpdateServiceStatus(serviceStatusDb, (Model.Status)Enum.Parse(typeof(Model.Status), region.Status));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }
        }
Esempio n. 2
0
        private static AzureStatus MakeRequest(string requestUrl)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                {
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(String.Format("Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription));
                    }

                    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(AzureStatus));
                    object      objResponse  = jsonSerializer.ReadObject(response.GetResponseStream());
                    AzureStatus jsonResponse = objResponse as AzureStatus;
                    return(jsonResponse);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }