private void UpdateDocument(UpdateDocumentJustificatifInputModel update) { try { using (var client = new HttpClient { BaseAddress = new Uri(UpsideoFinaveo2CommandsDocumentsWebApi) }) { using (var request = new HttpRequestMessage(HttpMethod.Post, UrlWebApiUpdateDocument)) { var json = Task.Run(() => JsonConvert.SerializeObject(update)); using (var stringContent = new StringContent(json.Result, Encoding.UTF8, "application/json")) { request.Content = stringContent; var response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result; response.EnsureSuccessStatusCode(); } } } } catch (Exception exc) { var log = new InsertLogErrorsCommandModel() { ErrorId = Guid.NewGuid(), Description = "OCR CTMS UpdateDocument :" + exc.Message, Exception = exc.InnerException.Message, Action = new StackTrace(exc).GetFrame(0).GetMethod().Name, LogType = "Error", EventAction = "Error", Layer = "Upsideo.Finaveo2.WindowsService.CheckDocumentsCTMS", }; CreateLog(log); } }
private async void CtmsService() { try { // recupere tout les docs en attente d'envoie OCR var AllDocEnAttente = await GetAllDocumentsByStatutOcr(); // modifier leur statutOcr En cours d'envoie OCR foreach (var item in AllDocEnAttente) { var update = new UpdateDocumentJustificatifInputModel { Id = item.Id, IdTiers = item.IdTiers, IdOuvertureCompte = item.IdOuvertureCompte, DocumentName = item.DocumentName, DocPath = item.DocPath, DocumentType = item.DocumentType, DateUpload = item.DateUpload, DateEmission = item.DateExpiration, DateExpiration = item.DateExpiration, NumeroPieceIdentite = item.NumeroPieceIdentite, LieuDelivrancePieceIdentite = item.LieuDelivrancePieceIdentite, Statut = item.Statut, JustificatifDomicileCode = item.JustificatifDomicileCode, UserId = item.UserId, CgpUserRights = item.CgpUserRights, ClientUserRights = item.ClientUserRights, MOUserRights = item.MOUserRights, TCUserRights = item.TCUserRights, StatutOcr = StatutOcr.EnCoursDeValidationOCR.ToString(), }; UpdateDocument(update); } // Get AccesToken and Create Folder in the first time : var AccesToken = GetTokenFromAuthentification(); // acces token to send var RefFolder = CreateFolderWithReference(AccesToken); // reference dolder to send // check document et modifier les statutOcr et ResponseOCr et ErreurDetail foreach (var d in AllDocEnAttente) { var StatutOcr = ""; var ResponseOcr = ""; var ErreurDetailOcr = ""; //Get Tiers : string ResponseTiersGlobal = d.IdTiers != Guid.Empty ? await GetTiers(d.IdTiers) : await GetTiers(await GetIdTiersFromOuvertureCompte(d.IdOuvertureCompte)); //Tiers tiersGlobal = JsonConvert.DeserializeObject<Tiers>(ResponseTiersGlobal) ; object tiersDetail = null; //if (tiersGlobal != null && tiersGlobal.TypePersonne.Equals("PersonnePhysique")) //{ // tiersDetail = JsonConvert.DeserializeObject<TiersPP>(ResponseTiersGlobal); //} //else //{ // tiersDetail = JsonConvert.DeserializeObject<TiersPM>(ResponseTiersGlobal); //} var docPath = Path.Combine(DematerializationRootPath, d.DocPath); if (File.Exists(docPath) /*&& tiersDetail != null*/) { SendFileToCheck(docPath, tiersDetail, ref StatutOcr, ref ResponseOcr, ref ErreurDetailOcr, AccesToken, RefFolder); // Update db set StatutOcr = Valide or NonValide var update = new UpdateDocumentJustificatifInputModel { Id = d.Id, IdTiers = d.IdTiers, IdOuvertureCompte = d.IdOuvertureCompte, DocumentName = d.DocumentName, DocPath = d.DocPath, DocumentType = d.DocumentType, DateUpload = d.DateUpload, DateEmission = d.DateExpiration, DateExpiration = d.DateExpiration, NumeroPieceIdentite = d.NumeroPieceIdentite, LieuDelivrancePieceIdentite = d.LieuDelivrancePieceIdentite, Statut = d.Statut, JustificatifDomicileCode = d.JustificatifDomicileCode, UserId = d.UserId, CgpUserRights = d.CgpUserRights, ClientUserRights = d.ClientUserRights, MOUserRights = d.MOUserRights, TCUserRights = d.TCUserRights, StatutOcr = StatutOcr, ErreurDetailsOcr = ErreurDetailOcr, ResponseOcr = ResponseOcr }; UpdateDocument(update); } } } catch (Exception exc) { var log = new InsertLogErrorsCommandModel() { ErrorId = Guid.NewGuid(), Description = "OCR CTMS " + exc.Message, Exception = exc.InnerException.Message, Action = new StackTrace(exc).GetFrame(0).GetMethod().Name, LogType = "Error", EventAction = "Error", Layer = "Upsideo.Finaveo2.WindowsService.CheckDocumentsCTMS", }; CreateLog(log); } }