public HttpResponseMessage Get(string folder, int page) { try { var applicationKeyService = new ApplicationKeyService(); var mobilityDocumentsService = new MobilityDocumentsService(); string user; string secret; var imageHelper = new Images(applicationKeyService, mobilityDocumentsService); var pageCount = 0; var output = new ImageResponse() { ErrorCount = 0, Content = imageHelper.GetImageInBytes(folder, page, out pageCount), Token = GetResponseToken(out user, out secret).access_token, Key = folder, TotalCount = pageCount }; var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json"); return response; } catch (Exception ex) { var output = new ImageResponse(); output.ErrorCount = 1; if (!ApplicationConfiguration.IsProduction) output.Stacktrace = ex.StackTrace; output.Token = GetResponseToken().access_token; output.Message = ex.Message; var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json"); return response; } }
public HttpResponseMessage GetDocument(string documentName, string folderPath) { var applicationKeyService = new ApplicationKeyService(); var mobilityDocumentsService = new MobilityDocumentsService(); try { string docWithoutExt; ApplicationKey appKey; var user = String.Empty; var secret = String.Empty; var token = GetResponseToken(out user, out secret).access_token; var imageHelper = new Images(applicationKeyService, mobilityDocumentsService); imageHelper.CreateDocumentImage(documentName, user, secret, folderPath.Base64Decode(), out docWithoutExt, out appKey); appKey = applicationKeyService.GetApplicationKey(appKey); while (appKey.PageCount == 0) { appKey = applicationKeyService.GetApplicationKey(appKey); } appKey.DocumentName = docWithoutExt; var output = new ImageResponse { ErrorCount = 0, Content = new byte[0], Token = token, Key = appKey.Key.ToString(), TotalCount = appKey.PageCount }; var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json"); return response; } catch (Exception ex) { var output = new ImageResponse(); output.ErrorCount = 1; if (!ApplicationConfiguration.IsProduction) output.Stacktrace = ex.StackTrace; output.Token = GetResponseToken().access_token; output.Message = ex.Message; var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(JsonConvert.SerializeObject(output), Encoding.UTF8, "application/json"); return response; } }