private static void LoginCheck(TaskDetail taskDetail) { if (!taskDetail.IncognitoMode && !SecLockSpider.IsLoggedIn()) { Login(); } }
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); } }
private void bwReloadSecLockManufacturers_DoWork(object sender, DoWorkEventArgs e) { ClearTreeNodes(tvSecLockManufacturers); var manufacturers = new SecLockSpider().ReloadAllManufacturers(); for (int i = 0; i < manufacturers.Count(); i++) { var manufacturer = manufacturers[i]; TreeNode node = new TreeNode(); node.Tag = manufacturer.Code; node.Text = manufacturer.Name; AddTreeRootNode(tvSecLockManufacturers, node); } }
private void bwReloadSecLockCategories_DoWork(object sender, DoWorkEventArgs e) { ClearTreeNodes(tvSecLockCategories); var categories = new SecLockSpider().GetCategories(); for (int i = 0; i < categories.Count(); i++) { var category = categories[i]; if (category.Name.Trim().ToUpper() == "ALL CATEGORIES") continue; TreeNode tn = new TreeNode(); tn.Tag = category.Code; tn.Text = category.Name; AddTreeRootNode(tvSecLockCategories, tn); } }
private void seclockManufacturerWorker_DoWork(object sender, DoWorkEventArgs e) { var manufacturers = new SecLockSpider().GetManufacturers(); for (int i = 0; i < manufacturers.Count(); i++) { var manufacturer = manufacturers[i]; TreeNode node = new TreeNode(); node.Tag = manufacturer.Code; node.Text = manufacturer.Name; //node.Nodes.Add("Loading"); AddTreeRootNode(tvSecLockManufacturers, node); } }
private void SecLockCategoryWorker_DoWork(object sender, DoWorkEventArgs e) { var categories = new SecLockSpider().GetCategories(); for (int i = 0; i < categories.Count(); i++) { var category = categories[i]; TreeNode tn = new TreeNode(); tn.Tag = category.Code ; tn.Text = category.Name; //tvSecLockCategories.Nodes.Add(category.Code, category.Name); AddTreeRootNode(tvSecLockCategories, tn); //SecLockSpider.GetCategoryProducts(category); } }
public void LoadSecLockUpdateProducts() { var products = new SecLockSpider().GetUpdateProducts(); foreach (var p in products) { TreeNode tn = new TreeNode(); tn.Text = p.Name; tn.Tag = p.Code; AddTreeRootNode(tvsecLockProducts, 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); } }