public async Task <byte[]> GetStaticMap(double latitude, double longitude, double zoom, int width, int height, float bearing = 0.0f, float pitch = 0.0f, bool classicMap = false, bool retina = false) { string res = this.GetStaticMapUri(latitude, longitude, zoom, width, height, bearing, pitch, classicMap, retina); var request = PrepareRequest(res, Method.GET); RawBytes rb = new RawBytes(); var result = await SendRequest <byte[]>(request, rb); return(rb.Data); }
private async Task <T> SendRequest <T>(RestRequest request, RawBytes rb = null) { try { System.Diagnostics.Debug.WriteLine(String.Format("Sending request: {0}{1}", client.BaseUrl, request.Resource)); var response = await client.ExecuteTaskAsync <T>(request, cts.Token); if (rb != null) { rb.Data = response.RawBytes; } return(response.Data); } catch (WebException ex) { System.Diagnostics.Debug.WriteLine(ex); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(default(T)); }
private async Task <T> SendRequest <T>(RestRequest request, string pubkey = null, bool signData = true, RestClient customClient = null, SignHandler customSign = null, RawBytes rb = null, System.IO.Stream responseStream = null, bool preferSSL = false, bool suppressUnAuthorized = false, bool suppressNoConnection = false, bool suppressServerErrors = false, CancellationTokenSource cancellationTokenSource = null) { var resource = request.Resource; var client = customClient ?? restClient; if (signData) { SignRequest(request, pubkey, client, customSign: customSign); } try { IRestResponse <T> response; if (responseStream != null) { request.ResponseWriter = (obj) => { obj.CopyTo(responseStream); obj.Close(); }; if (cancellationTokenSource != null) { response = await client.ExecuteTaskAsync <T>(request, cancellationTokenSource.Token); } else { response = await client.ExecuteTaskAsync <T>(request); } responseStream.Dispose(); } else { if (cancellationTokenSource != null) { response = await client.ExecuteTaskAsync <T>(request, cancellationTokenSource.Token); } else { response = await client.ExecuteTaskAsync <T>(request); } if (rb != null) { rb.Data = response.RawBytes; } } if (response.ResponseUri != null) { if (!response.ResponseUri.ToString().Contains("package_photo")) { System.Diagnostics.Debug.WriteLine("Status: {0}, Content: {1}", response.StatusCode, response.Content); } } ServiceStackSerializer.HandleStatusCode(response, resource); return(response.Data); } catch (WebException e) { System.Diagnostics.Debug.WriteLine("SendRequest to: {0} Error: {1}", client.BaseUrl, e.ToString()); if (!suppressNoConnection) { try { App.Locator.Workspace.OnConnectionError(new ConnectionErrorEventArgs(resource)); } catch { App.Locator.Workspace.OnConnectionError(new ConnectionErrorEventArgs("")); } } } catch (ServiceException e) { System.Diagnostics.Debug.WriteLine(e); if (!suppressServerErrors) { App.Locator.Workspace.OnServiceError(new ServiceErrorEventArgs(e)); } } catch (UnAuthorizedException e) { //Profile.DeleteCredentials (); if (!suppressUnAuthorized) { App.Locator.Workspace.OnAuthenticationRequired(e); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); //if (!suppressNoConnection) //_workspace.OnConnectionError(EventArgs.Empty); } return(default(T)); }