private ImageSource getImage(int imageId, string docName, string path,bool firstCall) { ImageResponse response; try { var agent = new DocumentDetailServiceAgent(); Task<string> docdetailTask; if (firstCall) { docdetailTask = agent.GetFirstDocument(docName, path); docdetailTask.Wait(); JObject parsed = JObject.Parse(docdetailTask.Result); var msg = parsed["Message"].ToObject<string>(); if (!string.IsNullOrEmpty(msg)) { if (msg.ToUpper().Equals(Constants.INVALID_TOKEN_MSG.ToUpper())) { throw new Exception(message: msg); } } response = JsonConvert.DeserializeObject<ImageResponse>(docdetailTask.Result); CommonHelper.UpdateTokenInfo(response.Token); if (response.ErrorCount > 0) { throw new Exception(message: response.Message); } else { _folderName = response.Key; } } else { docdetailTask = agent.GetDocument(docName, imageId); docdetailTask.Wait(); JObject parsed = JObject.Parse(docdetailTask.Result); var msg = parsed["Message"].ToObject<string>(); if (!string.IsNullOrEmpty(msg)) { if (msg.ToUpper().Equals(Constants.INVALID_TOKEN_MSG.ToUpper())) { throw new Exception(message: msg); } } response = JsonConvert.DeserializeObject<ImageResponse>(docdetailTask.Result); Debug.WriteLine(docdetailTask.Result); CommonHelper.UpdateTokenInfo(response.Token); if (response.ErrorCount > 0) { throw new Exception(message: response.Message); } else { TotalPage = response.TotalCount; NotifyPropertyChanged(() => TotalPage); } } } catch (InvalidOperationException ex) { throw new Exception(message: "Server not responding"); } catch (Exception ex) { throw new Exception(message: ex.Message); } return ImageHelper.ByteArrayToImageSource(response.Content); }
private ImageSource getImage(int imageId) { try { var agent = new DocumentDetailServiceAgent(); var imageList = agent.GetDocumentDetailTaskAsync(imageId); imageList.Wait(); return ImageHelper.ByteArrayToImageSource(imageList.Result); } catch (Exception ex) { DisplayAlert(ex.Message, "Error", "OK"); } return null; }