public void ProcessDepartments(JobAudit job)
        {
            try
            {
                _job           = job;
                _job.JobStatus = BOFileStatus.Processing;
                JobAuditDAL.UpdateJobAudit(_job);

                DateTime start = DateTime.Now;

                List <byte[]> files = CompressHelper.DeCompress(_job.FilePath);

                int totalItems = 0;
                List <Department> fromClient = ProcessDepartmentsFile(job.RetailerId, files.FirstOrDefault(), out totalItems);
                List <Department> fromDB     = DeptDAL.GetAllDepartments(job.RetailerId);

                UpdateDB(fromClient, fromDB);

                _job.ItemsProcessed = totalItems;
                _job.ProcessTime    = (int)DateTime.Now.Subtract(start).TotalSeconds;
                _job.JobStatus      = BOFileStatus.Done;
                JobAuditDAL.UpdateJobAudit(_job);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }
        public static void ProcessJobs(int retailerId)
        {
            Trace.WriteLine("Checking for available jobs - " + retailerId);
            List <JobAudit> jobs = JobAuditDAL.GetNewJobAudits(retailerId);

            if (jobs == null || jobs.Count == 0)
            {
                Trace.WriteLine("No Jobs Waiting");
                return;
            }

            Trace.WriteLine(jobs.Count + " jobs found");

            DepartmentProcessor  deptProcessor  = new DepartmentProcessor();
            ItemProcessor        itmProcessor   = new ItemProcessor();
            TransactionProcessor transProcessor = new TransactionProcessor();

            while (jobs != null && jobs.Count > 0)
            {
                JobAudit job = jobs.First();

                if (!BOFilesHelper.Exists(job.FilePath))
                {
                    Trace.WriteLine("Job Not Found - " + job.Id);
                    job.JobStatus = BOFileStatus.FileNotFound;
                    JobAuditDAL.UpdateJobAudit(job);
                    jobs.Remove(job);
                    continue;
                }

                Trace.WriteLine(job.FileType + " Job Found" + "(" + job.Id + ")");

                switch (job.FileType)
                {
                case InputFileType.Items:
                    itmProcessor.ProcessItems(job);
                    break;

                case InputFileType.Departments:
                    deptProcessor.ProcessDepartments(job);
                    break;

                case InputFileType.Transactions:
                    transProcessor.ProcessTransactions(job);
                    break;

                default:
                    break;
                }

                Trace.WriteLine("Job Processed");

                jobs = JobAuditDAL.GetNewJobAudits(retailerId);
            }
            deptProcessor  = null;
            itmProcessor   = null;
            transProcessor = null;
        }
Exemple #3
0
 public static void AddBOFile(int retailerId, BOFileType fileType, string filePath)
 {
     try
     {
         JobAudit job = new JobAudit {
             RetailerId = retailerId, FileType = (InputFileType)fileType, FilePath = filePath, JobStatus = BOFileStatus.NotUploaded
         };
         JobAuditDAL.InsertJobAudit(job);
     }
     catch (Exception ex)
     {
         Logger.LogException(ex);
     }
 }
Exemple #4
0
        public static bool UploadedBOFile(int retailerId, string filePath)
        {
            var job = JobAuditDAL.GetJobAuditByFilePath(retailerId, filePath);

            if (job != null)
            {
                job.JobStatus = BOFileStatus.New;
                JobAuditDAL.UpdateJobAudit(job);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool ProcessTransactions(JobAudit job)
        {
            try
            {
                int totalItems = 0;
                _job           = job;
                _job.JobStatus = BOFileStatus.Processing;
                JobAuditDAL.UpdateJobAudit(_job);

                DateTime startTime = DateTime.Now;

                List <byte[]> files = CompressHelper.DeCompress(_job.FilePath);

                foreach (byte[] file in files)
                {
                    Transactions receivedTransactions = file.Deserialize <Transactions>();

                    if (receivedTransactions == null || receivedTransactions.SaleTransactions == null || receivedTransactions.SaleTransactions.Count == 0)
                    {
                        continue;
                    }

                    foreach (SalesTransaction trans in receivedTransactions.SaleTransactions)
                    {
                        if (trans.TransactionDetails == null)
                        {
                            continue;
                        }

                        foreach (SalesTransactionDetail item in trans.TransactionDetails)
                        {
                            totalItems++;

                            Transaction transaction = item.ToDALTransaction(job.RetailerId, trans);

                            bool transactionExists = TransDAL.TransactionExists(transaction);

                            if (transaction == null || transactionExists)
                            {
                                continue;
                            }

                            int errorCount = TransDAL.InsertTransaction(transaction);

                            _job.ErrorCount += errorCount;
                            _job.IncrementNew(errorCount);
                        }
                    }
                }

                _job.ItemsProcessed = totalItems;
                _job.ProcessTime    = (int)DateTime.Now.Subtract(startTime).TotalSeconds;
                _job.JobStatus      = BOFileStatus.Done;
                JobAuditDAL.UpdateJobAudit(_job);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(false);
            }
        }