예제 #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);
            }
        }
예제 #2
0
        public static void Export(ref ToolStripStatusLabel lbl)
        {
            //List<FinalExport> finalExportList = exportManager.GetBySite(Constants.SiteName.ADIGLOBAL);
            List <FinalExport> finalExportList = new List <FinalExport>();

            finalExportList.Add(exportManager.GetTopBySite(Constants.SiteName.SECLOCK));
            for (int index = 0; index < finalExportList.Count; index++)
            {
                FinalExport finalExport = finalExportList[index];
                if (finalExport == null)
                {
                    lbl.Text = String.Empty;
                    return;
                }
                if (!ReferenceEquals(lbl, null))
                {
                    lbl.Text = String.Format("Saving {0} {1} {2}", "SecLock", finalExport.ExportType, finalExport.ExportValue);
                }
                try
                {
                    if (finalExport.ExportType == Constants.ExportType.SECLOCK_MANUFACTURER)
                    {
                        // BRAND EXPORT
                        //Utility.ApplicationLog("Exporting Brands");
                        ExportManufacturers();
                        //Utility.ApplicationLog("Brands exported sucessfully");
                    }
                    else if (finalExport.ExportType == Constants.ExportType.SECLOCK_MANUFACTURER_SERIES)
                    {
                        ExportManufacturerSeries(finalExport.ExportValue);
                    }
                    else if (finalExport.ExportType == Constants.ExportType.SECLOCK_CATEGORY)
                    {
                        // CATEGORY EXPORT
                        //Utility.ApplicationLog("Exporting Categories");
                        ExportCategories();
                        //Utility.ApplicationLog("Categories exported sucessfully");
                    }
                    else if (finalExport.ExportType == Constants.ExportType.SECLOCK_CRAWL)
                    {
                        // PRODUCT CRAWLING
                        //Utility.ApplicationLog("Exproting product");
                        ExportProduct(finalExport.ExportValue);
                        //Utility.ApplicationLog("Product exported sucessfully");
                    }
                    else if (finalExport.ExportType == Constants.ExportType.SECLOCK_UPDATE)
                    {
                        // PRODUCT UPDATE
                        //Utility.ApplicationLog("Exporting product Update");
                        ExportProductUpdate(finalExport.ExportValue);
                        //Utility.ApplicationLog("Product update exported sucessfully");
                    }
                }
                catch (Exception ex)
                {
                    Utility.ApplicationLog(String.Format("Saving failed for {0} {1} {2}", finalExport.ExportSite, finalExport.ExportType, finalExport.ExportValue));
                    String json = null;
                    Utility.ErrorLog(ex, json);
                    if (Settings.GetValue("MailErrors") == true)
                    {
                        Utility.ApplicationLog(String.Format("Saving failed for {0} {1} {2}", finalExport.ExportSite, finalExport.ExportType, finalExport.ExportValue), Constants.EmailErrorFile);
                    }
                }
                finally
                {
                    exportManager.Delete(finalExport.ExportSite, finalExport.ExportType, finalExport.ExportValue, finalExport.CreatedDate);
                }
            }
        }
예제 #3
0
 public void Insert(FinalExport fe)
 {
     Insert(fe.ExportSite, fe.ExportType, fe.ExportValue);
 }