예제 #1
0
        private void ExecuteLogic()
        {
            // Declarations
            string                    sUrl;
            JobScheduler              jobScheculer;
            HttpResponseMessage       response;
            List <SchedulerExecution> schedulerExecutions;

            // Get all scheduler executions(in TSchedulerExecution)
            schedulerExecutions = SchedulerBlo.GetCurrentExecutions();

            foreach (SchedulerExecution schedulerExecution in schedulerExecutions)
            {
                // If the execution is scheduled(pending) and execution time has passed, run logic
                if (schedulerExecution.Status.Equals((int)Enumerations.ExecutionStatus.Scheduled) &&
                    schedulerExecution.ExecutionTimeStamp < DateTime.Now)
                {
                    // Get the corresponding job scheduler
                    jobScheculer = SchedulerBlo.GetJobScheduler(schedulerExecution.SchedulerId);

                    using (var client = new HttpClient())
                    {
                        client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
                        // Compose the URL
                        client.BaseAddress = new Uri(Helper.GetRegistryKeyValue(Constants._PioRegistryPath, Constants._PioServer));
                        // AccountPayablePath in Registry = api/AccountsPayable/PaymentOrders?payerId={0}&dateFrom={1}&dateTo={2}
                        sUrl = string.Format("{0}{1}",
                                             client.BaseAddress,
                                             string.Format(Helper.GetRegistryKeyValue(Constants._PioRegistryPath, Constants._Pio_AccountPayable),
                                                           jobScheculer.PartnerId,
                                                           "2018-04-01T00:00:00",
                                                           "2018-04-03T00:00:00"));

                        response = client.GetAsync(sUrl).Result;
                        if (response.IsSuccessStatusCode)
                        {
                        }
                    }
                }



                // Take the XML file from the shared folder, send to PIO

                // Request from PIO the XML file and store it on the shared folder
                // File Name:       TATAPPO_<<PoNum>><<Date of File PreparationYYYYMMDD>>_<<incremental#>>.XML
                //              RES_TATAPPO_<<PoNum>><<Date of File PreparationYYYYMMDD>>_<<incremental#>>.XML


                /*
                 * switch (jobScheculer.PartnerType)
                 *      {
                 *          case (int)Enumerations.PartnerType.Bank:
                 *              break;
                 *          case (int)Enumerations.PartnerType.Payer:
                 *              break;
                 *          case (int)Enumerations.PartnerType.Sprovider:
                 *              break;
                 *          case (int)Enumerations.PartnerType.NApplicable:
                 *              break;
                 *          case (int)Enumerations.PartnerType.Distributor:
                 *              break;
                 *          case (int)Enumerations.PartnerType.Reinsurer:
                 *              break;
                 *          case (int)Enumerations.PartnerType.HealthProvider:
                 *              break;
                 *      }
                 *
                 *      switch (jobScheculer.ActionTye)
                 *      {
                 *          case (int)Enumerations.ActionType.Push:
                 *              // Push data from NC DBs to shared folder accessed by client via SFTP
                 *
                 *              break;
                 *
                 *          case (int)Enumerations.ActionType.Pull:
                 *              break;
                 *
                 *          case (int)Enumerations.ActionType.Inbound:
                 *              break;
                 *
                 *          case (int)Enumerations.ActionType.Outbound:
                 *              break;
                 *      }
                 */
            }
        }
예제 #2
0
        private void ManageSchedulerExecutions()
        {
            // Declarations
            DateTime?                 dUpcomingExecution;
            SchedulerExecution        execution;
            SchedulerLog              executionLog;
            SchedulerSettings         oSetting;
            List <JobScheduler>       jobSchedulers;
            List <SchedulerExecution> schedulerExecutions;
            List <SchedulerLog>       lastSchedulerExecutionLogs;

            // Get active schedulers with their corresponding settings
            jobSchedulers = SchedulerBlo.GetDetailedActiveSchedulers();

            if (jobSchedulers != null)
            {
                // Get all scheduler executions(in TSchedulerExecution)
                schedulerExecutions = SchedulerBlo.GetCurrentExecutions();

                // Get latest scheduler execution logs(in TSchedulerExecutionLog)
                lastSchedulerExecutionLogs = SchedulerBlo.GetLatestExecutionLogs();

                // Iterate through each scheduler
                foreach (JobScheduler jobScheduler in jobSchedulers)
                {
                    // Validate the scheduler end date
                    if (jobScheduler.EndDate != null && jobScheduler.EndDate < DateTime.Now)
                    {
                        // Diable scheduler when end date has expired
                        jobScheduler.Enabled = false;
                        SchedulerBlo.SetSchedulerState(jobScheduler);
                    }
                    else
                    {
                        // Iterate through each scheduler setting
                        foreach (SchedulerSettings setting in jobScheduler.Settings)
                        {
                            // Try to find an execution for this setting
                            execution = schedulerExecutions.Where(x => x.SchedulerSettingsId == setting.SchedulerSettingsId).FirstOrDefault();

                            // Find the latest execution log for this setting
                            executionLog = lastSchedulerExecutionLogs
                                           .Where(x => x.SchedulerSettingsId == setting.SchedulerSettingsId)
                                           .OrderByDescending(x => x.ExecutionTimeStamp)
                                           .FirstOrDefault();

                            // Assign setting to a new object in order to pass it as ref(since setting is a foreach iteration variable)
                            oSetting = setting;

                            // Get upcoming scheduler execution
                            int action = 0;
                            dUpcomingExecution = SchedulerBlo.GetUpcomingSchedulerExecution(jobScheduler.RecurrenceFrequency, ref execution,
                                                                                            executionLog.ExecutionTimeStamp, ref oSetting, ref action);

                            switch (action)
                            {
                            case (int)Enumerations.RecordActionStatus.Keep:
                                break;

                            case (int)Enumerations.RecordActionStatus.Insert:
                                execution = new SchedulerExecution(setting.SchedulerSettingsId, jobScheduler.SchedulerId, dUpcomingExecution, (int)Enumerations.ExecutionStatus.Scheduled);
                                SchedulerBlo.CreateExecution(ref execution);
                                break;

                            case (int)Enumerations.RecordActionStatus.Update:
                                execution = new SchedulerExecution(execution.SchedulerExecutionId, jobScheduler.SchedulerId, setting.SchedulerSettingsId, dUpcomingExecution, (int)Enumerations.ExecutionStatus.Scheduled);
                                SchedulerBlo.UpdateExecution(execution);
                                break;

                            case (int)Enumerations.RecordActionStatus.Delete:
                                break;
                            }
                        }
                    }
                }
            }
        }