Пример #1
0
        /// <summary>
        /// Locks or unlocks the file
        /// </summary>
        /// <param name="isLock"></param>
        private void FileLock(bool isLock)
        {
            providerRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <ProviderOrganisation> >();
            ProviderOrganisation providerEntry = providerRepository.First(x => x.KeyValue == ProviderKey && x.FileType == _fileType);

            providerEntry.Status = (isLock ? "Locked" : "Unlocked");
            providerRepository.Update(providerEntry);
            providerRepository.SaveChanges();
        }
Пример #2
0
 public MIUploadService(IUnitOfWork uowItem, IUcbManagementInformationRepository <ProviderOrganisation> providerOrganisationRepositoryItem,
                        IUcbManagementInformationRepository <InputFileHistory> inputFileHistoryRepositoryItem, IUcbManagementInformationRepository <Alert> alertRepositoryItem,
                        IUcbManagementInformationRepository <AlertUser> alertUserRepositoryItem, IUcbManagementInformationRepository <MCUser> userRepositoryItem,
                        IUcbManagementInformationRepository <UploadJobQueue> uploadJobQueueRepositoryItem)
 {
     uow = uowItem;
     providerOrganisationRepository = providerOrganisationRepositoryItem;
     inputFileHistoryRepository     = inputFileHistoryRepositoryItem;
     alertRepository          = alertRepositoryItem;
     alertUserRepository      = alertUserRepositoryItem;
     userRepository           = userRepositoryItem;
     uploadJobQueueRepository = uploadJobQueueRepositoryItem;
 }
Пример #3
0
        public static string GetSystemParameterByName(string Name)
        {
            IUcbManagementInformationRepository <MCSystemParameter> systemParameterRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <MCSystemParameter> >();
            MCSystemParameter parameter = systemParameterRepository.Find(x => x.Name == Name).FirstOrDefault();

            if (parameter != null)
            {
                return(parameter.ParameterValue);
            }
            else
            {
                return(null);
            }
        }
        public FileUploadJob(Guid code, string fileName, string providerKey, string userID, string webPath, DateTime?added, DateTime?started, DateTime?ended, string description)
        {
            Code           = code;
            ProviderKey    = providerKey;
            UniqueFileName = fileName;
            AddedTime      = added;
            StartTime      = started;
            EndTime        = ended;
            Description    = description;
            //GET Schema file paths from configuration
            _schema        = webPath + ConfigurationManager.AppSettings["ParticipantSchema"];
            _mappingSchema = webPath + ConfigurationManager.AppSettings["ParticipantMappingSchema"];

            //Get Connection string from configuration
            _connectionString = ConfigurationManager.ConnectionStrings["MIStagingConnectionString"].ConnectionString;

            //set private variables
            IUcbManagementInformationRepository <ProviderOrganisation> providerOrganisationRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <ProviderOrganisation> >();
            ProviderOrganisation providerOrganisationItem =
                providerOrganisationRepository.First(x => x.KeyValue == ProviderKey);

            _providingOrganistaionCode = providerOrganisationItem.Code;
            _fileType = "Participant";
            FileInfo DataFileInfoItem = new FileInfo(UniqueFileName);

            _fileLength = DataFileInfoItem.Length;

            _userID  = userID;
            UserId   = userID;
            JobSteps = new List <JobStep>()
            {
                new JobStep("SchemaValidation", "Schema Validation", this, 1),
                new JobStep("DeleteFromLoadingArea", "DeleteFromLoadingArea", this, 2),
                new JobStep("BulkUpload", "Bulk Load", this, 3),
                new JobStep("CopyBulkLoadedData", "CopyBulkLoadedData", this, 4),
                new JobStep("ValidateParticipantDuplicates", "Validate Participant", this, 5),
                new JobStep("ValidateAgreementRegion", "Validate Participant", this, 6),
                new JobStep("ValidateParticipantPostCode", "Validate Participant", this, 7),
                new JobStep("ValidateLeaver", "Validate Participant", this, 8),
                new JobStep("ValidateLeavingDate", "Validate Participant", this, 9),
                new JobStep("ValidateStartDate", "Validate Participant", this, 10),
                new JobStep("LoadParticipantMessages", "Validate Participant", this, 11),
                new JobStep("ValidatePreviousLoad", "Validate Participant", this, 12),
                new JobStep("UpdateParticipantCounts", "Validate Participant", this, 13)
            };
        }
Пример #5
0
        public JobBase GetFileUploadJobByCode(Guid code)
        {
            var job = (FileUploadJob)JobQueue.Instance.FindJobByCode(code);

            if (job == null)
            {
                IUcbManagementInformationRepository <UploadJobQueue> uploadJobQueueRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UploadJobQueue> >();
                var uploadjob = uploadJobQueueRepository.Find(x => x.Code == code, "JobSteps").FirstOrDefault();
                if (uploadjob != null)
                {
                    var           descSplit   = uploadjob.JobDescription.Split('|');
                    FileUploadJob jobToReturn = new FileUploadJob()
                    {
                        Code           = uploadjob.Code,
                        ProviderKey    = descSplit[1],
                        Status         = (JobStatus)Enum.Parse(typeof(JobStatus), uploadjob.Status),
                        UniqueFileName = descSplit[3],
                        UserId         = uploadjob.UserId,
                        JobSteps       = new List <MIFileUpload.JobQueue.JobStep>()
                    };
                    foreach (UcbManagementInformation.Server.DataAccess.JobStep step in uploadjob.JobSteps.OrderBy(x => x.StepOrder))
                    {
                        jobToReturn.JobSteps.Add(new MIFileUpload.JobQueue.JobStep(step.StartTime, step.EndTime, (JobStepStatus)Enum.Parse(typeof(JobStepStatus), step.Status))
                        {
                            Code      = step.Code,
                            Category  = step.Category,
                            Name      = step.Name,
                            ParentJob = jobToReturn,
                            Order     = step.StepOrder
                        });
                    }
                    return(jobToReturn);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(job);
            }
        }
Пример #6
0
        public IEnumerable <JobBase> GetCompleteFileUploadJobs()
        {
            List <JobBase> listToReturn = new List <JobBase>();
            DateTime       Yesterday    = DateTime.Now.AddDays(-1);
            IUcbManagementInformationRepository <UploadJobQueue> uploadJobQueueRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UploadJobQueue> >();
            var uploadjobList = uploadJobQueueRepository.Find(x => x.TimeAdded > Yesterday && (x.Status == "Succeeded" || x.Status == "Failed"), "JobSteps").OrderByDescending(x => x.TimeStarted);

            foreach (var uploadjob in uploadjobList)
            {
                var     descSplit   = uploadjob.JobDescription.Split('|');
                JobBase jobToReturn = new JobBase()
                {
                    Code        = uploadjob.Code,
                    AddedTime   = uploadjob.TimeAdded,
                    Description = uploadjob.JobDescription,
                    StartTime   = uploadjob.TimeStarted,
                    EndTime     = uploadjob.EndTime,
                    Status      = (JobStatus)Enum.Parse(typeof(JobStatus), uploadjob.Status),
                    UserId      = uploadjob.UserId,
                    JobSteps    = new List <MIFileUpload.JobQueue.JobStep>()
                };
                foreach (UcbManagementInformation.Server.DataAccess.JobStep step in uploadjob.JobSteps.OrderBy(x => x.StepOrder))
                {
                    jobToReturn.JobSteps.Add(
                        new MIFileUpload.JobQueue.JobStep(step.StartTime, step.EndTime, (JobStepStatus)Enum.Parse(typeof(JobStepStatus), step.Status))
                    {
                        Code      = step.Code,
                        Category  = step.Category,
                        Name      = step.Name,
                        ParentJob = jobToReturn,
                        Order     = step.StepOrder
                    });
                }
                listToReturn.Add(jobToReturn);
            }
            return(listToReturn);
            // return listToReturn;
        }
        /// <summary>
        /// Copys the uploaded data to a validated area
        /// </summary>
        /// <param name="uploadDecision">The type of data to copy: 'ValidOnly','ValidAndInfo' or 'ValidInfoAndWarning'</param>
        /// <returns></returns>
        public int ValidatedUpload(int maximumErrorLevel)
        {
            using (spRunner.Cn)
            {
                spRunner.Cn.Open();
                spRunner.IsOpen = true;
                using (SqlTransaction transact = spRunner.Cn.BeginTransaction())
                {
                    DeleteValidatedParticipantData(transact);
                    CopyValidatedParticipants(transact);
                    transact.Commit();
                }
                spRunner.Cn.Close();
                spRunner.IsOpen = false;
            }
            //Stamp number of records uploaded and remove lock of database
            using (uow = SimpleServiceLocator.Instance.Get <IUnitOfWork>("UcbManagementInformation"))
            {
                inputFileHistoryRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <InputFileHistory> >(uow.ObjectContext);
                providerRepository         = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <ProviderOrganisation> >(uow.ObjectContext);
                InputFileHistory ifh = inputFileHistoryRepository.Find(x => x.Code == _inputFileHistoryCode).First();
                ifh.Status         = "Validated Loaded " + maximumErrorLevel.ToString();
                ifh.UploadDecision = maximumErrorLevel;
                //_inputFileHistoryRow.ValidatedLoadDate = DateTime.Now;
                inputFileHistoryRepository.Update(ifh);

                ProviderOrganisation po = providerRepository.First(x => x.KeyValue == ProviderKey && x.FileType == "Participant");
                po.CurrentValidatedFileCode = _inputFileHistoryCode;
                providerRepository.Update(po);

                uow.Commit();
            }

            DeleteParticipantData();
            //DeleteParticipantDataOver4HoursOld();
            DeleteInputFileErrorsOver1YearOld();
            return(0);
        }
        public void UpdateUser(UcbManagementInformation.Server.DataAccess.MCUser user)
        {
            // Ensure the user data that will be modified represents the currently
            // authenticated identity
            if ((this.ServiceContext.User == null) ||
                (this.ServiceContext.User.Identity == null) ||
                !string.Equals(this.ServiceContext.User.Identity.Name, user.Name, System.StringComparison.Ordinal))
            {
                throw new UnauthorizedAccessException("You are only authorized to modify your own profile.");
            }

            //this.ObjectContext.Users.AttachAsModified(user, this.ChangeSet.GetOriginal(user));

            IUcbManagementInformationRepository <UcbManagementInformation.Server.DataAccess.MCUser> UserRep = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UcbManagementInformation.Server.DataAccess.MCUser> >(this.ObjectContext);

            UserRep.Attach(user);
            UserRep.SaveChanges();
        }
 public AlertService(IUcbManagementInformationRepository <Alert> alertRepositoryItem, IUcbManagementInformationRepository <AlertUser> alertUserRepositoryItem, IUnitOfWork uowItem)
 {
     alertRepository     = alertRepositoryItem;
     alertUserRepository = alertUserRepositoryItem;
     uow = uowItem;
 }
        // the main work loop
        public void Run()
        {
            // initialize the flag that keeps the loop going
            IsOn = true;
            // start
            while (IsOn)
            {
                try
                {
                    // get the next pending job, otherwise the default one
                    AtomicAction("Dequeue", Guid.Empty);
                    // execute the job and retrieve the delay value
                    if (CurrentJob != null)
                    {
                        CurrentJob.Status = JobStatus.Running;
                        IUnitOfWork uow = SimpleServiceLocator.Instance.Get <IUnitOfWork>("UcbManagementInformation");

                        IUcbManagementInformationRepository <UploadJobQueue> uploadJobQueueRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UploadJobQueue> >(uow.ObjectContext);
                        IUcbManagementInformationRepository <UcbManagementInformation.Server.DataAccess.JobStep> jobStepRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <UcbManagementInformation.Server.DataAccess.JobStep> >(uow.ObjectContext);
                        IUcbManagementInformationRepository <Alert>     alertRepository     = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <Alert> >(uow.ObjectContext);
                        IUcbManagementInformationRepository <AlertUser> alertUserRepository = DataAccessUtilities.RepositoryLocator <IUcbManagementInformationRepository <AlertUser> >(uow.ObjectContext);

                        var waitingJob = uploadJobQueueRepository.First(x => x.Code == CurrentJob.Code);
                        waitingJob.Status      = "Running";
                        waitingJob.TimeStarted = DateTime.Now;
                        uploadJobQueueRepository.Update(waitingJob);
                        uow.Commit();

                        int rv = CurrentJob.RunJob();

                        using (uow)
                        {
                            //Log the job and job steps;
                            waitingJob = uploadJobQueueRepository.First(x => x.Code == CurrentJob.Code);
                            uploadJobQueueRepository.Update(waitingJob);

                            if (rv == 0)
                            {
                                CurrentJob.Status  = JobStatus.Succeeded;
                                waitingJob.EndTime = DateTime.Now;
                                waitingJob.Status  = "Succeeded";
                            }
                            else
                            {
                                CurrentJob.Status  = JobStatus.Failed;
                                waitingJob.EndTime = DateTime.Now;
                                waitingJob.Status  = "Failed";
                            }
                            uploadJobQueueRepository.Update(waitingJob);
                            foreach (JobStep currentStep in CurrentJob.JobSteps)
                            {
                                UcbManagementInformation.Server.DataAccess.JobStep stepToSave = new UcbManagementInformation.Server.DataAccess.JobStep()
                                {
                                    Code               = currentStep.Code,
                                    Category           = currentStep.Category,
                                    EndTime            = currentStep.EndTime,
                                    StartTime          = currentStep.StartTime,
                                    Status             = currentStep.Status.ToString(),
                                    Name               = currentStep.Name,
                                    UploadJobQueueCode = CurrentJob.Code,
                                    StepOrder          = currentStep.Order
                                };
                                jobStepRepository.Add(stepToSave);
                            }
                            var alertToUpdate = alertRepository.FirstOrDefault(x => x.RelatedEntityCode == CurrentJob.Code);
                            if (alertToUpdate != null)
                            {
                                alertToUpdate.Status        = "Completed";
                                alertToUpdate.CompletedDate = DateTime.Now;
                                alertToUpdate.Message       = "File upload job : " + waitingJob.JobDescription + " has finished. ";
                                if (CurrentJob.Status == JobStatus.Succeeded)
                                {
                                    alertToUpdate.Message += "The Job was successfull.";
                                }
                                else
                                {
                                    alertToUpdate.Message += "The Job failed.";
                                    var failedStep = CurrentJob.JobSteps.FirstOrDefault(x => x.Status == JobStepStatus.Failed);
                                    if (failedStep != null)
                                    {
                                        alertToUpdate.Message += " The failing step was " + failedStep.Name;
                                    }
                                }
                            }
                            uow.Commit();
                        }

                        if (CurrentJob.UnhandledException != null)
                        {
                            ExceptionPolicy.HandleException(CurrentJob.UnhandledException, ExceptionHandlingPolicies.UnhandledException);
                        }
                        //Job completed and saved to DB so remove from memory!!!!
                        CurrentJob = null;
                    }
                    // check to make sure a stop hasn't been issued
                    // and that the job calls for a wait
                    if (IsOn && sleepTime > 0)
                    {
                        // wait for the time specified
                        System.Threading.Thread.Sleep(sleepTime);
                    }
                }
                catch (Exception ex)
                {
                    //publish ex;

                    ExceptionPolicy.HandleException(ex, ExceptionHandlingPolicies.UnhandledException);
                }
            }
        }