Exemple #1
0
        public static void CrawlProduct(Object objItem)
        {
            TaskDetailManager taskDetailManager = new TaskDetailManager(Constants.ConnectionString);
            ADIProductManager adiProductManager = new ADIProductManager(Constants.ConnectionString);
            AdiMode mode = AdiMode.CRAWL;
            bool HasError = false;
            TaskDetail taskDetail = (TaskDetail)objItem;
            //Utility.ApplicationLog(String.Format("AdiGlobal product Crawling started for {0}, Ignito Mode - {1}, Download Images - {2}", taskDetail.TaskNameText, taskDetail.IgnitoMode, taskDetail.DownloadImages));
            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<AdiProduct> products = new List<AdiProduct>();
                    if (taskDetail.TaskType == Constants.ADICatagory)
                        products = AdiSpider.ParseCatagoryProducts(taskDetail.TaskNameValue);
                    else
                        products = AdiSpider.GetBrandProducts(taskDetail.TaskNameValue);

                    double totalProducts = products.Count;

                    for (int index = 0; index < products.Count; index++)
                    {
                        AdiProduct p = products[index];
                        //Utility.ApplicationLog(String.Format("Processing Adi Product {0} {1}", p.AdiNumber, p.ProductDescription));
                        try
                        {
                            PingCheck();
                            AdiSpider.SaveProduct(p, mode);
                            AdiSpider.GetProductDetails(p, taskDetail.DownloadImages);
                            if (taskDetail.IncognitoMode == false)
                            {
                                AdiSpider.GetProductInventory(p, mode);
                            }
                            exportManager.Insert(Constants.SiteName.ADIGLOBAL, Constants.ExportType.ADI_PRODUCT_CRAWL, p.AdiNumber);

                        }
                        catch (Exception ex)
                        {
                            //Utility.ApplicationLog(String.Format("Error Processing Adi Product {0} {1}", p.AdiNumber, p.ProductDescription));
                            String json = JsonConvert.SerializeObject(p, Formatting.None);
                            Utility.ErrorLog(ex, json);
                            if (Settings.GetValue("MailErrors") == true)
                            {
                                Utility.ApplicationLog(String.Format("{0} {1}", p.PartNumber, ex.Message), Constants.EmailErrorFile);
                            }
                            HasError = true;
                        }
                        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);
                    //Utility.ApplicationLog(String.Format("AdiGlobal product Crawling complete for {0}",taskDetail.TaskNameText));
                }
                //if (HasError) throw new Exception();
            }
            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);
            }
        }
 public TasksScheduler()
 {
     detailManager = new TaskDetailManager(Constants.ConnectionString);
     thManager = new TaskHeaderManager(Constants.ConnectionString);
 }
Exemple #3
0
        public static void ProcessProductLeastCount()
        {
            TaskDetailManager taskDetailManager = new TaskDetailManager(Constants.ConnectionString);
            ADIProductManager adiProductManager = new ADIProductManager(Constants.ConnectionString);
            AdiMode mode = AdiMode.CRAWL;
            bool HasError = false;
            //Utility.ApplicationLog(String.Format("AdiGlobal product Crawling started for {0}, Ignito Mode - {1}, Download Images - {2}", taskDetail.TaskNameText, taskDetail.IgnitoMode, taskDetail.DownloadImages));
            try
            {
                LoginCheck(new TaskDetail() { IncognitoMode = false });

                List<AdiProduct> products = new List<AdiProduct>();
                products = adiProductManager.GetAllPriorityProducts();

                double totalProducts = products.Count;

                for (int index = 0; index < products.Count; index++)
                {
                    AdiProduct p = products[index];
                    //Utility.ApplicationLog(String.Format("Processing Adi Product {0} {1}", p.AdiNumber, p.ProductDescription));
                    try
                    {
                        PingCheck();
                        AdiSpider.SaveProduct(p, mode);
                        AdiSpider.GetProductDetails(p, false);
                        double totalInventory = AdiSpider.GetProductInventory(p, mode);
                        if (totalInventory <= p.LeastCount)
                        {
                            //Send Mail
                            Utility.SendAlertMail("Stock Alert", "Product- " + p.AdiNumber + " Live Stock Quantity- " + totalInventory.ToString());
                            //Utility.LogFile(fileName, "Mail Send-" + productsList[index].AdiNumber);
                        }
                        //exportManager.Insert(Constants.SiteName.ADIGLOBAL, Constants.ExportType.ADI_PRODUCT_CRAWL, p.AdiNumber);

                    }
                    catch (Exception ex)
                    {
                        //Utility.ApplicationLog(String.Format("Error Processing Adi Product {0} {1}", p.AdiNumber, p.ProductDescription));
                        String json = JsonConvert.SerializeObject(p, Formatting.None);
                        Utility.ErrorLog(ex, json);
                        if (Settings.GetValue("MailErrors") == true)
                        {
                            Utility.ApplicationLog(String.Format("{0} {1}", p.PartNumber, ex.Message), Constants.EmailErrorFile);
                        }
                        HasError = true;
                    }
                }
            }
            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);
            }
        }
Exemple #4
0
 private void InitTasks()
 {
     TaskDetailManager tdMgr = new TaskDetailManager(Constants.ConnectionString);
     tdMgr.DeleteByHeaderId(-1);
 }
Exemple #5
0
 private void AddToCategory(TreeNode tNode, List<AdiCategory> oCategories, String taskMode)
 {
     TaskDetailManager mgr = new TaskDetailManager(Constants.ConnectionString);
     foreach (AdiCategory c in oCategories)
     {
         TreeNode tn = new TreeNode();
         tn.Text = c.DisplayName;
         tn.Tag = c.Value;
         tn.Checked = (mgr.GetDataByTaskDetail(-1, Constants.SiteName.ADIGLOBAL, taskMode, Constants.TaskType.ADI_CATEGORY, c.Value).Count() == 1);
         if (ReferenceEquals(tNode, null))
             //treeCatagory.Nodes.Add(tn);
             AddTreeRootNode(treeCatagory, tn);
         else
             //tNode.Nodes.Add(tn);
             AddTreeSubNode(tNode, tn);
         if (c.SubCategory.Count > 0)
             AddToCategory(tn, c.SubCategory, taskMode);
     }
 }
Exemple #6
0
 private void AddToBrand(TreeNode tNode, List<AdiBrand> oBrands, String taskMode)
 {
     TaskDetailManager mgr = new TaskDetailManager(Constants.ConnectionString);
     foreach (AdiBrand b in oBrands)
     {
         TreeNode tn = new TreeNode();
         tn.Text = b.DisplayName;
         tn.Tag = b.Value;
         tn.Checked = (mgr.GetDataByTaskDetail(-1, Constants.SiteName.ADIGLOBAL, taskMode, Constants.TaskType.ADI_BRAND, b.Value).Count() == 1);
         if (ReferenceEquals(tNode, null))
             //treeCatagory.Nodes.Add(tn);
             AddTreeRootNode(treeViewBrands, tn);
         else
             //tNode.Nodes.Add(tn);
             AddTreeSubNode(tNode, tn);
     }
 }
        public static void Crawl(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;
                    }
                    double totalProducts = products.Count();
                    for (int index = 0; index < totalProducts; index++)
                    {
                        try
                        {
                            products[index] = new SecLockSpider().GetProductFromSite(products[index].Code, taskDetail.IncognitoMode);

                            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);
            }
        }