protected override GetBingMapsPreviewResponse InternalExecute() { string str = "Function start"; GetBingMapsPreviewResponse result; try { string requestString = GetBingMapsPreview.BuildImageRequestString(this.request.Latitude, this.request.Longitude, this.request.LocationName, this.request.MapWidth, this.request.MapHeight, this.request.MapControlKey); str = "Executing web request"; using (HttpWebResponse httpWebResponse = this.ExecuteWebRequest(requestString)) { if (httpWebResponse == null) { throw new OwaException("BingMapsRequestNullError"); } str = "Inspecting response status code"; if (httpWebResponse.StatusCode != HttpStatusCode.OK) { result = GetBingMapsPreview.CreateErrorResponse("WebResponse status code: " + httpWebResponse.StatusCode, httpWebResponse.StatusDescription); } else { if (httpWebResponse.ContentLength > 204800L) { throw new OwaException("ImageMaxStreamSizeExceededError"); } str = "Getting attachment data from the response"; int imageDataSize = 0; Stream responseStream = httpWebResponse.GetResponseStream(); if (responseStream == null) { throw new OwaException("WebResponseStreamNullError"); } byte[] contentFromStream = GetBingMapsPreview.GetContentFromStream(responseStream, 204800, out imageDataSize); string imageData = Convert.ToBase64String(contentFromStream); str = "Building response with encoded image data string"; result = new GetBingMapsPreviewResponse { ImageData = imageData, ImageDataSize = imageDataSize, ImageDataType = "image/jpeg" }; } } } catch (OwaException exception) { result = GetBingMapsPreview.CreateErrorResponse(exception); } catch (NullReferenceException ex) { result = GetBingMapsPreview.CreateErrorResponse("NullReferenceException", "Null reference exception in GetBingMapsPreview InternalExecute. The last executed step was: " + str + ". Details: " + ex.Message); } return(result); }
private static GetBingMapsPreviewResponse CreateErrorResponse(OwaException exception) { if (exception.Message == "ImageMaxStreamSizeExceededError") { return(GetBingMapsPreview.CreateErrorResponse("ImageMaxStreamSizeExceededError", "The image size exceeded the maximum size")); } if (exception.Message == "ImageAttachmentDataNullError") { return(GetBingMapsPreview.CreateErrorResponse("ImageAttachmentDataNullError", "Image attachment data was null")); } if (exception.Message == "CreateAttachmentRequestError") { return(GetBingMapsPreview.CreateErrorResponse("CreateAttachmentRequestError", "Error building CreateAttachmentRequest")); } if (exception.Message == "CreateAttachmentResultNullError") { return(GetBingMapsPreview.CreateErrorResponse("CreateAttachmentResultNullError", "No response message from CreateAttachmentHelper.CreateAttachment")); } if (exception.Message == "BingMapsRequestNullError") { return(GetBingMapsPreview.CreateErrorResponse("BingMapsRequestNullError", "Request to Bing Maps to get the map image returned null")); } if (exception.Message == "WebRequestNullError") { return(GetBingMapsPreview.CreateErrorResponse("WebRequestNullError", "The HttpWebRequest created to query Bing Maps was null")); } if (exception.Message == "WebResponseStreamNullError") { return(GetBingMapsPreview.CreateErrorResponse("WebResponseStreamNullError", "The response stream for the maps image was null")); } if (exception.InnerException != null) { return(GetBingMapsPreview.CreateErrorResponse(exception.Message, exception.InnerException.Message)); } return(GetBingMapsPreview.CreateErrorResponse(exception.Message, exception.ToString())); }