public static RateCardPayload GetRateCardInfo(string restUrl, Guid orgId) { HttpWebResponse httpWebResponse = AzureResourceManagerUtil.RateCardRestApiCall(restUrl, orgId); try { if (httpWebResponse == null) { Trace.TraceWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); Trace.TraceWarning($"{nameof(httpWebResponse)} == null"); Trace.TraceWarning($" {nameof(GetRateCardInfo)}({nameof(restUrl)}, {nameof(orgId)})"); Trace.TraceWarning($" {nameof(restUrl)}: {restUrl}"); Trace.TraceWarning($" {nameof(orgId)}: {orgId}"); // throw exception to start from scretch and retry. //throw new Exception("Possible reason: Bad request (400), Forbidden (403) to access. Server busy. Client blacklisted."); } else { // look response codes @ https://msdn.microsoft.com/en-us/library/azure/mt219001.aspx // see: https://msdn.microsoft.com/en-us/library/azure/mt219004.aspx if (httpWebResponse.StatusCode == HttpStatusCode.OK) { Trace.TraceInformation($"Received Rest Call Response: {nameof(HttpStatusCode.OK)}. Processing..."); string streamContent; using (Stream receiveStream = httpWebResponse.GetResponseStream()) { // Pipes the stream to a higher level stream reader with the required encoding format. using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { streamContent = readStream.ReadToEnd(); } } RateCardPayload rateCardPayload = JsonConvert.DeserializeObject <RateCardPayload>(streamContent); return(rateCardPayload); } else if (httpWebResponse.StatusCode == HttpStatusCode.Accepted) { Trace.TraceWarning($"Data not ready. {nameof(HttpStatusCode.Accepted)}. Not capable of handling this."); } else { Trace.TraceWarning("NEW RESPONSE TYPE. HANDLE THIS - GetRateCardInfo!"); Trace.TraceWarning($"code:{httpWebResponse.StatusCode} desc:{httpWebResponse.StatusDescription}"); } } return(null); } finally { httpWebResponse?.Dispose(); } }
public static RateCardPayload GetRateCardInfo(string restURL, string orgID) { HttpWebResponse httpWebResponse = null; httpWebResponse = AzureResourceManagerUtil.RateCardRestApiCall(restURL, orgID); if (httpWebResponse == null) { Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); Console.WriteLine("httpWebResponse == null"); Console.WriteLine(" GetRateCardInfo(string restURL, string orgID)"); Console.WriteLine(" restURL: {0}", restURL); Console.WriteLine(" orgID: {0}", orgID); // throw exception to start from scretch and retry. //throw new Exception("Possible reason: Bad request (400), Forbidden (403) to access. Server busy. Client blacklisted."); } else { // look response codes @ https://msdn.microsoft.com/en-us/library/azure/mt219001.aspx if (httpWebResponse.StatusCode == HttpStatusCode.OK) { Console.WriteLine("Received Rest Call Response: HttpStatusCode.OK. Processing..."); Stream receiveStream = httpWebResponse.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); string streamContent = readStream.ReadToEnd(); RateCardPayload rateCardPayload = JsonConvert.DeserializeObject <RateCardPayload>(streamContent); return(rateCardPayload); } else if (httpWebResponse.StatusCode == HttpStatusCode.Accepted) { Console.WriteLine("Data not ready. HttpStatusCode.Accepted. Not capable of handling this."); } else { Console.WriteLine("NEW RESPONSE TYPE. HANDLE THIS - GetRateCardInfo!"); Console.WriteLine("code:{0} desc:{1}", httpWebResponse.StatusCode, httpWebResponse.StatusDescription); } } return(null); }