Example #1
0
        /// <summary>
        /// Send, recieve, and process sevis batches using the service.
        /// </summary>
        /// <param name="info">The timer trigger instance.</param>
        /// <returns>The task<./returns>
        public async Task ProcessTimer([TimerTrigger(typeof(SevisCommSchedule), RunOnStartup = true)] TimerInfo info)
        {
            var sevisComm = new SevisComm(this.appSettings, this.ecaHttpMessageHandlerService);

            await ProcessAsync(this.service, sevisComm, this.appSettings);

            var nextOccurrenceMessage = info.FormatNextOccurrences(5);

            logger.Info(nextOccurrenceMessage);
        }
Example #2
0
        /// <summary>
        /// Uploads batches to the sevis api.
        /// </summary>
        /// <param name="batchComm">The communication class instance.</param>
        /// <returns>The task.</returns>
        public async Task UploadBatchesAsync(SevisComm batchComm)
        {
            Contract.Requires(batchComm != null, "The batchComm must not be null.");
            var dtoToUpload = await service.GetNextBatchToUploadAsync();

            while (dtoToUpload != null)
            {
                await UploadBatchAsync(batchComm, dtoToUpload);

                dtoToUpload = await service.GetNextBatchToUploadAsync();
            }
        }
Example #3
0
        /// <summary>
        /// Performs processing of the SEVIS batch records.
        /// </summary>
        /// <param name="service">The SEVIS batch services to get and update batches.</param>
        /// <param name="sevisComm">The sevis batch comm object.</param>
        /// <param name="settings">The app settings.</param>
        public async Task ProcessAsync(ISevisBatchProcessingService service, SevisComm sevisComm, AppSettings settings)
        {
            Contract.Requires(service != null, "The SEVIS service must not be null.");
            Contract.Requires(settings != null, "The settings must not be null.");
            Contract.Requires(sevisComm != null, "The sevis comm must not be null.");
            logger.Info("Starting SEVIS Batch Processing");
            await DownloadBatchesAsync(sevisComm);
            await UploadBatchesAsync(sevisComm);

            logger.Debug("Removing processed batches");
            await service.DeleteProcessedBatchesAsync();

            logger.Info("Finished Batch Processing.");
        }
Example #4
0
        public async Task UploadAsyncTest_Base()
        {
            var xml  = XElement.Parse(uploadXmlString);
            var comm = new SevisComm(appSettings, mockedEcaHttpMesssageHandlerService);

            Action <HttpResponseMessage> tester = async(s) =>
            {
                Assert.IsTrue(s.IsSuccessStatusCode);
                var xmlResult = await s.Content.ReadAsStringAsync();

                Assert.AreEqual(xmlResult, uploadResultXml);
            };
            var response = await comm.UploadAsync(xml, batchId, orgId, sevisUser);

            tester(response);
        }
Example #5
0
        public async Task DownloadAsyncTest_Base()
        {
            var comm = new SevisComm(appSettings, mockedEcaHttpMesssageHandlerService);

            Action <HttpResponseMessage> tester = async(s) =>
            {
                Assert.IsTrue(s.IsSuccessStatusCode);
                Stream zipStream = await s.Content.ReadAsStreamAsync();

                var zipResult = new ZipArchive(zipStream);
                var xmlTransactionLogEntry = zipResult.Entries.First(e => e.Name == xmlTransactionLogFileName);
                Assert.IsNotNull(xmlTransactionLogEntry);
                StreamReader reader    = new StreamReader(xmlTransactionLogEntry.Open());
                string       xmloutput = reader.ReadToEnd();
                Assert.AreEqual(xmloutput, xmlTransactionLogString);
            };
            var response = await comm.DownloadAsync(batchId, orgId, sevisUser);

            tester(response);
        }
Example #6
0
        /// <summary>
        /// Calls the sevis api for results to the sevis batch.
        /// </summary>
        /// <param name="batchComm">The sevis comm instance.</param>
        /// <param name="dtoToDownload">The batch to get download results for.</param>
        /// <returns>The task.</returns>
        public async Task DownloadBatchAsync(SevisComm batchComm, SevisBatchProcessingDTO dtoToDownload)
        {
            Contract.Requires(batchComm != null, "The batchComm must not be null.");
            Contract.Requires(dtoToDownload != null, "The dto to download must not be null.");
            // ask for download
            logger.Info("Getting Download, BatchId: {0}", dtoToDownload.BatchId);
            var response = await batchComm.DownloadAsync(dtoToDownload.BatchId, dtoToDownload.SevisOrgId, dtoToDownload.SevisUsername);

            //process response
            if (response.IsSuccessStatusCode)
            {
                var stream = await response.Content.ReadAsStreamAsync();

                await responseHandler.HandleDownloadResponseStreamAsync(GetSystemUser(), dtoToDownload, stream);

                logger.Info("Processed Download Response");
            }
            else
            {
                logger.Error("Download encountered an error, status code: {0}, reason: {1}", response.StatusCode.ToString(), response.ReasonPhrase);
                await service.HandleFailedDownloadBatchAsync(dtoToDownload.Id, null);
            }
        }
Example #7
0
        /// <summary>
        /// Uploads a batch to the sevis api.
        /// </summary>
        /// <param name="batchComm">The sevis communication instance.</param>
        /// <param name="dtoToUpload">The batch to upload.</param>
        /// <returns></returns>
        public async Task UploadBatchAsync(SevisComm batchComm, SevisBatchProcessingDTO dtoToUpload)
        {
            Contract.Requires(batchComm != null, "The batchComm must not be null.");
            Contract.Requires(dtoToUpload != null, "The dto to upload must not be null.");
            //do the send here
            logger.Info("Sending Upload, BatchId: {0}", dtoToUpload.BatchId);
            var response = await batchComm.UploadAsync(XElement.Parse(dtoToUpload.SendString), dtoToUpload.BatchId, dtoToUpload.SevisOrgId, dtoToUpload.SevisUsername);

            //process response message
            if (response.IsSuccessStatusCode)
            {
                var stream = await response.Content.ReadAsStreamAsync();

                await responseHandler.HandleUploadResponseStreamAsync(GetSystemUser(), dtoToUpload, stream);

                logger.Info("Processed Upload Response");
            }
            else
            {
                logger.Error("Upload encountered an error, status code: {0}, reason: {1}", response.StatusCode.ToString(), response.ReasonPhrase);
                await service.HandleFailedUploadBatchAsync(dtoToUpload.Id, null);
            }
        }
Example #8
0
        public void SevisCommTest()
        {
            var comm = new SevisComm(appSettings, mockedEcaHttpMesssageHandlerService);

            Assert.IsNotNull(comm);
        }