Example #1
0
        public static void Update(object objItem)
        {
            TaskDetailManager taskDetailManager = new TaskDetailManager(Constants.ConnectionString);
            TaskDetail        taskDetail        = (TaskDetail)objItem;

            try
            {
                if (!ReferenceEquals(taskDetail, null))
                {
                    taskDetail.TaskStatusText = Constants.PROCESSING_TEXT;
                    taskDetail.TaskStatus     = TaskDetailStatus.Processing;
                    taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);

                    LoginCheck(taskDetail);

                    List <InProduct> products = new List <InProduct>();
                    //if (taskDetail.TaskMode == Constants.TaskMode.SECLOCK_MANUFACTURER_CRAWL)
                    //{
                    //    InManufacturer manufacturer = new InManufacturer();
                    //    manufacturer.Name = taskDetail.TaskNameText;
                    //    manufacturer.Code = taskDetail.TaskNameValue;
                    //    new SecLockSpider().GetProductsByManufacturer(manufacturer);
                    //    foreach (InManufacturerSeries s in manufacturer.SeriesList)
                    //        products.AddRange(s.Products);
                    //}
                    //else if (taskDetail.TaskMode == Constants.TaskMode.SECLOCK_CATEGORY_CRAWL)
                    //{
                    //    InCategory category = new InCategory();
                    //    category.Name = taskDetail.TaskNameText;
                    //    category.Code = taskDetail.TaskNameValue;
                    //    new SecLockSpider().GetCategoryProducts(category);
                    //    products = category.Products;
                    //}
                    products.Add(
                        new InProduct()
                    {
                        Code = taskDetail.TaskNameValue,
                        Name = taskDetail.TaskNameText
                    }
                        );
                    double totalProducts = products.Count();
                    for (int index = 0; index < totalProducts; index++)
                    {
                        try
                        {
                            products[index] = new SecLockSpider().GetProductFromSite(products[index].Code);

                            if (taskDetail.DownloadImages)
                            {
                                new SecLockSpider().DownloadProductImages(taskDetail, products[index]);
                            }

                            new InProductManager(Constants.ConnectionString).Save(products[index]);

                            FinalExport fe = new FinalExport();
                            fe.ExportSite  = Constants.SiteName.SECLOCK;
                            fe.ExportType  = Constants.ExportType.SECLOCK_CRAWL;
                            fe.ExportValue = products[index].Code;
                            exportManager.Insert(fe);
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            taskDetail.TaskStatusText = String.Format("{0} - {1}%", Constants.PROCESSING_TEXT, (index / totalProducts * 100).ToString("0"));
                            taskDetail.TaskStatus     = TaskDetailStatus.Processing;
                            taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
                        }
                    }
                    taskDetail.TaskStatusText = Constants.COMPLETED_TEXT;
                    taskDetail.TaskStatus     = TaskDetailStatus.Completed;
                    taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
                }
            }
            catch (TaskCanceledException ex)
            {
            }
            catch (Exception ex)
            {
                //Utility.ApplicationLog(String.Format("AdiGlobal product Crawling completed with errors for {0}", taskDetail.TaskNameText));
                String json = null;
                Utility.ErrorLog(ex, json);
                if (Settings.GetValue("MailErrors") == true)
                {
                    Utility.ApplicationLog(String.Format("{0}", ex.Message), Constants.EmailErrorFile);
                }
                taskDetail.TaskStatusText = Constants.COMPLETED_ERROR_TEXT;
                taskDetail.TaskStatus     = TaskDetailStatus.CompletedWithError;
                taskDetailManager.UpdateStatus(taskDetail.TaskID, taskDetail.TaskStatusText, taskDetail.TaskStatus);
            }
        }
Example #2
0
 public TasksScheduler()
 {
     detailManager = new TaskDetailManager(Constants.ConnectionString);
     thManager     = new TaskHeaderManager(Constants.ConnectionString);
 }