public TestHelper Confirm_job() { Assert_state(_confirmationReference); _client.Confirm(_confirmationReference).ConfigureAwait(false).GetAwaiter().GetResult(); return(this); }
public static async Task GetStatusChange() { PortalClient portalClient = null; //As initialized earlier // Repeat the polling until signer signs the document, but ensure to do this at a // reasonable interval. If you are processing the result a few times a day in your // system, only poll a few times a day. var change = await portalClient.GetStatusChange(); switch (change.Status) { case JobStatus.NoChanges: //Queue is empty. Additional polling will result in blocking for a defined period. break; case JobStatus.Failed: case JobStatus.InProgress: case JobStatus.CompletedSuccessfully: { var signatureJobStatus = change.Status; var signatures = change.Signatures; var signatureOne = signatures.ElementAt(0); var signatureOneStatus = signatureOne.SignatureStatus; break; } } var pollingWillResultInBlock = change.NextPermittedPollTime > DateTime.Now; if (pollingWillResultInBlock) { //Wait until next permitted poll time has passed before polling again. } //Confirm the receipt to remove it from the queue await portalClient.Confirm(change.ConfirmationReference); }
public async Task Throws_unexpected_response_exception() { //Arrange var portalClient = new PortalClient(GetClientConfiguration()) { HttpClient = GetHttpClientWithHandler(new FakeHttpClientHandlerForInternalServerErrorResponse()) }; //Act await Assert.ThrowsAsync <UnexpectedResponseException>(async() => await portalClient.Confirm(new ConfirmationReference(new Uri("http://cancellationuri.no"))).ConfigureAwait(false)).ConfigureAwait(false); }
private void timer1_Tick(object sender, ElapsedEventArgs e) { X509Certificate2 tekniskAvsenderSertifikat; string scertificateThumbprint = ""; string sorganizationNumber = ""; string sEnvironment = ""; string sDebugMode = ""; int iDebugMode = 0; string iterations = ""; //regSubKeycatNos contains a list if all category Numbers, JobID-field name for the category and status for the category for all workflows. List <string> regSubKeyCatNos = new List <string>(); //Load the values from the registry RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); key = key.OpenSubKey("SOFTWARE").OpenSubKey("Canon"); if (key != null) { sorganizationNumber = key.GetValue("OrganizationNo").ToString(); scertificateThumbprint = key.GetValue("CertThumbprint").ToString(); sEnvironment = key.GetValue("Environment").ToString(); sDebugMode = key.GetValue("DebugMode").ToString(); iterations = key.GetValue("NumberOfPolls").ToString(); if (sDebugMode != "") { iDebugMode = Convert.ToInt32(sDebugMode); } foreach (string wfName in key.GetSubKeyNames()) { if (wfName == "OrganizationNo" || wfName == "CertThumbprint" || wfName == "PollingInterval" || wfName == "NumberOfPolls" || wfName == "Environment" || wfName == "DebugMode") { continue; } RegistryKey tempkey; tempkey = key.OpenSubKey(wfName); regSubKeyCatNos.Add(tempkey.GetValue("CategoryNo").ToString() + "|" + tempkey.GetValue("JobIDFieldName").ToString() + "|" + tempkey.GetValue("StatusFieldName").ToString()); if (iDebugMode > 0) { Library.WriteErrorLog("Loaded workflow: " + tempkey.GetValue("CategoryNo").ToString() + "|" + tempkey.GetValue("JobIDFieldName").ToString() + "|" + tempkey.GetValue("StatusFieldName").ToString()); } } } else { Library.WriteErrorLog("No workflow exists/has been configured correctly: No information stored in the registry about the certification or organization number"); } //POSTEN: initiate a portalClient PortalClient portalClient = null; Digipost.Signature.Api.Client.Core.Environment env = Digipost.Signature.Api.Client.Core.Environment.DifiTest; if (sEnvironment == "Production") { env = Digipost.Signature.Api.Client.Core.Environment.Production; //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("!!!!!!!!!!!!Working against the prdouction environment !!!!!!"); } } tekniskAvsenderSertifikat = getCertificat(scertificateThumbprint); //POSTEN: Create Client Configuration ClientConfiguration clientconfiguration = new ClientConfiguration( env, tekniskAvsenderSertifikat, new Sender(sorganizationNumber)); //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("Client configured: " + clientconfiguration.ToString()); Library.WriteErrorLog("Current Environment: " + clientconfiguration.Environment.ToString()); } portalClient = new PortalClient(clientconfiguration); //POSTEN: Do the initial poll and get a status JobStatusChanged jobStatusChanged = portalClient.GetStatusChange().Result; if (jobStatusChanged.Status == JobStatus.NoChanges) { //Queue is empty. Additional polling will result in blocking for a defined period. //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("First Poll: No Change.." + " "); } } else { //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("Staus changed - polling jobs"); } for (int i = 0; i < Convert.ToInt32(iterations); i++) { if (i != 0) { jobStatusChanged = portalClient.GetStatusChange().Result; } try { JobStatus signatureJobStatus = jobStatusChanged.Status; string docNo = jobStatusChanged.JobReference; string tmpFileName = ""; if (signatureJobStatus == JobStatus.CompletedSuccessfully) { //DEBUG if (iDebugMode > 1) { Library.WriteErrorLog("Polling job: " + jobStatusChanged.JobId); } Stream pades = portalClient.GetPades(jobStatusChanged.PadesReference).Result; tmpFileName = System.IO.Path.GetTempPath() + jobStatusChanged.JobId + "_" + Guid.NewGuid().ToString() + ".pdf"; FileStream filestream = File.Create(tmpFileName, (int)pades.Length); byte[] bytesInStream = new byte[pades.Length]; pades.Read(bytesInStream, 0, bytesInStream.Length); filestream.Write(bytesInStream, 0, bytesInStream.Length); filestream.Close(); filestream.Dispose(); //DEBUG if (iDebugMode > 1) { Library.WriteErrorLog("Polling job: " + jobStatusChanged.JobId + ": Pades retrieved"); } } TheServer server = new TheServer(); server.Connect(TheClientType.CustomService); //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("Connected to The Server"); } TheIndexData theInData = new TheIndexData(); TheDocument theDoc = new TheDocument(); bool fileSaved = false; //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("Document Number from Reference: " + docNo); } theInData.DocNo = Convert.ToInt32(docNo); theInData.Load(server); string sPostenStatus = ""; string statusFieldName = ""; statusFieldName = getStatusFieldName(theInData.CtgryNo.ToString(), regSubKeyCatNos); if (iDebugMode > 0) { Library.WriteErrorLog("Found status field name: " + statusFieldName); } if (iDebugMode > 0) { Library.WriteErrorLog("CatNo found: " + theInData.CtgryNo.ToString()); } if (signatureJobStatus != JobStatus.CompletedSuccessfully) { if (signatureJobStatus == JobStatus.Failed) { sPostenStatus = "Signature was either rejected or failed"; } else if (signatureJobStatus == JobStatus.InProgress) { List <Signature> signStatus = new List <Signature>(); signStatus = jobStatusChanged.Signatures; foreach (Signature sign in signStatus) { string tempMail = sign.Identifier.ToContactInformation().Email.Address; } sPostenStatus = "Signature is in Progress"; } if (iDebugMode > 0) { Library.WriteErrorLog("Updating status for document : " + docNo); } if (!string.IsNullOrEmpty(statusFieldName)) { theInData.SetValueByColName(statusFieldName, sPostenStatus); } theInData.SaveChanges(server); //DEBUG if (iDebugMode > 0) { Library.WriteErrorLog("Status updated for document: " + docNo); } } else { if (iDebugMode > 0) { Library.WriteErrorLog("Begin archiving the doc : " + docNo.ToString()); } TheDocument newDoc = new TheDocument(); newDoc.Create(""); newDoc.AddStream(tmpFileName, "", 0); newDoc.IndexData = theInData; if (!string.IsNullOrEmpty(statusFieldName)) { newDoc.IndexData.SetValueByColName(statusFieldName, "Signed"); } string testUser; int testCurrVersion; newDoc.CheckOut(server, 0, out testUser, out testCurrVersion); newDoc.Archive(server, Convert.ToInt32(docNo), "Added by The Polling Service"); newDoc.Dispose(); if (iDebugMode > 0) { Library.WriteErrorLog("Document is archived : " + docNo); } } if (iDebugMode > 0) { Library.WriteErrorLog("Confirming status for JOb ID (Posten): " + jobStatusChanged.JobId); } //Confirming that we have recieved the JobStatusChange string confStatus = portalClient.Confirm(jobStatusChanged.ConfirmationReference).Status.ToString(); fileSaved = true; if (iDebugMode > 0) { Library.WriteErrorLog("Confirming status for JOb ID (Posten): " + jobStatusChanged.JobId + ": - Confirmed: " + confStatus); } if (fileSaved) { File.Delete(tmpFileName); if (iDebugMode > 0) { Library.WriteErrorLog("Deleting Temp-file: " + tmpFileName); } } }catch (TooEagerPollingException eagerPollingException) { Library.WriteErrorLog("No more jobs to poll: " + eagerPollingException.ToString()); break; } } } }