public async Task <IEnumerable <ImageApiModel> > DoGetFilesAsync() { try { var request = (HttpWebRequest)HttpWebRequest.Create(UrlHelper.baseUrl + UrlHelper.ImageList); request.ContentType = "application/json; charset=utf-8"; request.ContentLength = 0; request.KeepAlive = true; request.Method = "GET"; string token = ApplicationPropertiesHelper.GetToken(); request.Headers.Set("X-API-KEY", "343b1ae9-fb57-45fd-90f0-g1e097f9d621"); request.Headers.Set("Authorization", "Bearer " + token); var response = (HttpWebResponse)(request.GetResponseAsync().Result); string result = ""; using (var stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { result = await reader.ReadToEndAsync(); } } IEnumerable <ImageApiModel> images = JsonConvert.DeserializeObject <IEnumerable <ImageApiModel> >(result); return(images); } catch (Exception ex) { return(null); } }
public async Task <ApiResponse> DoRequestAsync(string method, string url, object parameters) { try { IDictionary <string, string> dictionaryParameters = ConvertationHelper.ParametersToDictionary(parameters); string data = string.Join("&", dictionaryParameters .Select(pair => string.Concat(UrlHelper.UrlEncode(pair.Key), "=", UrlHelper.UrlEncode(pair.Value)))); var request = (HttpWebRequest)HttpWebRequest.Create(url + "?" + data); request.ContentType = "application/json; charset=utf-8"; request.ContentLength = 0; request.KeepAlive = true; request.Method = method; request.Headers.Set("X-API-KEY", "343b1ae9-fb57-45fd-90f0-g1e097f9d621"); string token = ApplicationPropertiesHelper.GetToken(); request.Headers.Set("Authorization", "Bearer " + token); var response = (HttpWebResponse)(request.GetResponseAsync().Result); using (var stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { await reader.ReadToEndAsync(); return(ApiResponse.Ok()); } } } catch (Exception ex) { return(ApiResponse.Fail(ex.Message)); } }
public AxleWeightViewModel(string axlePosition, int numberOfAxle) { AxlePosition = axlePosition; NumberOfAxle = numberOfAxle; Psi = ApplicationPropertiesHelper.GetProperty(_lastPsiValueKey + _axlePosition, 50); }
public async Task <ApiResponse> DoPostFileAsync(string url, byte[] image, object parameters) { try { HttpClient client = new HttpClient(); IDictionary <string, string> dictionaryParameters = ConvertationHelper.ParametersToDictionary(parameters); string data = string.Join("&", dictionaryParameters.Select(pair => string.Concat(UrlHelper.UrlEncode(pair.Key), "=", UrlHelper.UrlEncode(pair.Value)))); ByteArrayContent byteContent = new ByteArrayContent(image); MultipartFormDataContent content = new MultipartFormDataContent(); content.Add(byteContent, "image", "filename.ext"); string token = ApplicationPropertiesHelper.GetToken(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var response = await client.PostAsync(url + "?" + data, content); return(ApiResponse.Ok()); } catch (Exception ex) { return(ApiResponse.Fail(ex.Message)); } }
public WeightPageForCombinationViewModel(string combination) { NumberOfAxles = combination.Split(',') .Select((a) => Convert.ToInt32(a)) .ToList(); string imageFile = combination.Replace(',', '_') + ".png"; ImageSource = ImageSourceHelper.GetFromResource(imageFile); PsiTableTruck = DictionaryToList(_psiTableTruckBase); PsiTableTrailerGeneric = DictionaryToList(_psiTableTrailerGenericBase); SelectedIndexA = ApplicationPropertiesHelper.GetProperty(nameof(SelectedIndexA), -1); SelectedIndexB = ApplicationPropertiesHelper.GetProperty(nameof(SelectedIndexB), -1); SelectedIndexC = ApplicationPropertiesHelper.GetProperty(nameof(SelectedIndexC), -1); SelectedIndexD = ApplicationPropertiesHelper.GetProperty(nameof(SelectedIndexD), -1); HelpCommand = new Command(async() => { await Commons.DisplayAlert(AppResources.WeightHelpTitle, AppResources.WeightHelpMessage, "Ok"); }); MaxLegalWeight = (NumberOfAxles[2] > 0) ? 67500 : 5500 + GetMaxWeightForAxle(NumberOfAxles[0]) + GetMaxWeightForAxle(NumberOfAxles[1]); }