Example #1
0
        protected void UpdateJobStatus(TJob job, JobStatus status)
        {
            Log.Debug($"Scheduler UpdateJobStatus {job.Name} -> {status}");
            var oldStatus = job.Status;

            if (oldStatus != status)
            {
                job.Status = status;
                ExecuteSafely(() => JobStatusChanged?.Invoke(job, oldStatus, job.Status));
            }
        }
Example #2
0
        private TestEvents.FakeEvent GetJobStatusChangedEvent()
        {
            TestEvents.FakeEvent result = new TestEvents.FakeEvent(this, EventType.JobStatusChanged
                                                                   );
            JobStatusChanged datum = new JobStatusChanged();

            datum.jobid     = "ID";
            datum.jobStatus = "newStatus";
            result.SetDatum(datum);
            return(result);
        }
            public void Simple_constructor()
            {
                //Arrange
                var jobId                 = 123456789;
                var jobReference          = "senders-reference";
                var jobStatus             = JobStatus.InProgress;
                var confirmationReference = new ConfirmationReference(new Uri("http://confirmationreference.no"));
                var nextPermittedPollTime = DateTime.Now;
                var signatures            = new List <Signature>
                {
                    new Signature
                    {
                        SignatureStatus = SignatureStatus.Signed,
                        Identifier      = new PersonalIdentificationNumber("123456789"),
                        XadesReference  = new XadesReference(new Uri("http://xadesuri1.no"))
                    },
                    new Signature
                    {
                        SignatureStatus = SignatureStatus.Waiting,
                        Identifier      = new PersonalIdentificationNumber("123456789"),
                        XadesReference  = null
                    }
                };

                //Act
                var portalJobStatusChangeResponse = new JobStatusChanged(
                    jobId,
                    jobReference,
                    jobStatus,
                    confirmationReference,
                    signatures,
                    nextPermittedPollTime
                    );

                //Assert
                Assert.Equal(jobId, portalJobStatusChangeResponse.JobId);
                Assert.Equal(jobReference, portalJobStatusChangeResponse.JobReference);
                Assert.Equal(jobStatus, portalJobStatusChangeResponse.Status);
                Assert.Equal(confirmationReference, portalJobStatusChangeResponse.ConfirmationReference);
                Assert.Equal(signatures, portalJobStatusChangeResponse.Signatures);
            }
Example #4
0
        public TestHelper ExpectJobStatusForSenderIs(JobStatus expectedStatus, Sender sender = null)
        {
            Assert_state(_jobResponse);

            _jobStatusChanged = GetCurrentReceipt(_jobResponse.JobId, _client, sender);
            Assert.Equal(expectedStatus, _jobStatusChanged.Status);

            if (_jobStatusChanged.Status == NoChanges)
            {
                return(this);
            }

            _confirmationReference = new ConfirmationReference(TransformReferenceToCorrectEnvironment(_jobStatusChanged.ConfirmationReference.Url));

            if (_jobStatusChanged.Status != CompletedSuccessfully)
            {
                return(this);
            }

            _xadesReference = new XadesReference(TransformReferenceToCorrectEnvironment(_jobStatusChanged.Signatures.First().XadesReference.Url));
            _padesReference = new PadesReference(TransformReferenceToCorrectEnvironment(_jobStatusChanged.PadesReference.Url));

            return(this);
        }
Example #5
0
        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;
                    }
                }
            }
        }
 public static void OnJobStatusChanged(object sender, JobStatus e)
 {
     JobStatusChanged?.Invoke(sender, e);
 }
Example #7
0
            public void Converts_portal_job_status_change_response_successfully()
            {
                //Todo: Husk å sjekke om vi skal ha type, ettersom man kan få et fødselsnummer eller en identifier tilbake. Nå er det bare en string

                //Arrange
                var now = DateTime.Now;

                var source = new portalsignaturejobstatuschangeresponse
                {
                    confirmationurl = "http://confirmationurl.no",
                    signaturejobid  = 12345678901011,
                    reference       = "senders-reference",
                    signatures      = new signatures
                    {
                        padesurl  = "http://padesurl.no",
                        signature = new[]
                        {
                            new signature
                            {
                                Item   = "01013300001",
                                status = new signaturestatus
                                {
                                    Value = SignatureStatus.Signed.Identifier,
                                    since = now
                                },
                                xadesurl = "http://xadesurl1.no"
                            },
                            new signature
                            {
                                Item   = "01013300002",
                                status = new signaturestatus
                                {
                                    Value = SignatureStatus.Waiting.Identifier,
                                    since = now
                                },
                                xadesurl = "http://xadesurl2.no"
                            }
                        }
                    },
                    status = portalsignaturejobstatus.IN_PROGRESS
                };

                var jobStatus             = source.status.ToJobStatus();
                var confirmationReference = new ConfirmationReference(new Uri(source.confirmationurl));
                var signature1            = source.signatures.signature[0];
                var signature2            = source.signatures.signature[1];
                var signatures            = new List <Signature>
                {
                    new Signature
                    {
                        SignatureStatus   = new SignatureStatus(signature1.status.Value),
                        Identifier        = new PersonalIdentificationNumber((string)signature1.Item),
                        XadesReference    = new XadesReference(new Uri(signature1.xadesurl)),
                        DateTimeForStatus = now
                    },
                    new Signature
                    {
                        SignatureStatus   = new SignatureStatus(signature2.status.Value),
                        Identifier        = new PersonalIdentificationNumber((string)signature2.Item),
                        XadesReference    = new XadesReference(new Uri(signature2.xadesurl)),
                        DateTimeForStatus = now
                    }
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusChanged(
                    source.signaturejobid,
                    source.reference,
                    jobStatus,
                    confirmationReference,
                    signatures,
                    nextPermittedPollTime
                    );

                var padesUrl = source.signatures.padesurl;

                if (padesUrl != null)
                {
                    expected.PadesReference = new PadesReference(new Uri(padesUrl));
                }

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, actual, out differences);
                Assert.Empty(differences);
            }
Example #8
0
 public virtual void SetDatum(object datum)
 {
     this.datum = (JobStatusChanged)datum;
 }
Example #9
0
        private void ConfirmExcessReceipt(JobStatusChanged statusChange)
        {
            var uri = TransformReferenceToCorrectEnvironment(statusChange.ConfirmationReference.Url);

            _client.Confirm(new ConfirmationReference(uri)).Wait();
        }