示例#1
0
 private void btnNotShowProduct_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Toàn bộ số công ty trong group sẽ bị ẩn. Đồng ý", "Queuesion", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
             == DialogResult.OK)
         {
             ProductAdapter productAdapter = new ProductAdapter(new Entities.Data.SqlDb(QT.Entities.Server.ConnectionString));
             int            TypeCompany    = Convert.ToInt32(lookUpEdit1.EditValue);
             if (TypeCompany > 0)
             {
                 DataTable tblCompanyNeedNotShow = productAdapter.GetListCompanyByStatus(TypeCompany);
                 if (tblCompanyNeedNotShow != null && tblCompanyNeedNotShow.Rows.Count > 0)
                 {
                     foreach (DataRow row in tblCompanyNeedNotShow.Rows)
                     {
                         bool bOK = productAdapter.UpdateNotShowProductForCompany(Convert.ToInt64(row["id"]), false);
                         if (bOK == false &&
                             MessageBox.Show("Xem log lỗi. Chạy tiếp compnay tiếp?", "Question", MessageBoxButtons.YesNo
                                             , MessageBoxIcon.Question) == DialogResult.Yes)
                         {
                             break;
                         }
                     }
                     MessageBox.Show("Success!");
                 }
             }
         }
     }
     catch (Exception ex01)
     {
         MessageBox.Show(ex01.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#2
0
        private static void ResesCacheProduct()
        {
            ProductAdapter productAdapter = new ProductAdapter(new SqlDb(Server.ConnectionString));

            Console.WriteLine("1- Reset all Companies)");
            Console.WriteLine("2- Reset for Company");
            Console.Write("Input choose:");
            int i = Convert.ToInt32(Console.ReadLine());

            switch (i)
            {
            case 1:
            {
                int countProduct = 0;
                var lstCompany   = productAdapter.GetAllCompanyIdCrawler();
                foreach (var companyID in lstCompany)
                {
                    ResetCacheProduct(companyID);
                    log.Info(string.Format("Complete Company: {0} {1}/{2}", companyID, countProduct++, lstCompany.Count));
                }
                log.Info("Complete all company");
            } break;

            case 2:
            {
                Console.Write("Input domain:");
                string strDomain = Console.ReadLine().Trim();
                long   companyID = productAdapter.GetCompanyIdByDomain(strDomain);
                ResetCacheProduct(companyID);
                log.Info(string.Format("Complete Company: {0}", companyID));
            } break;
            }
        }
示例#3
0
        public IActionResult Remove(int id)
        {
            ProductRepository         repo   = new ProductRepository();
            IProductsRepository       target = new ProductAdapter(repo);
            List <ShoppingBasketItem> basket = SessionHelper.GetObjectFromJson <List <ShoppingBasketItem> >(HttpContext.Session, "basket");
            int index   = isExist(id);
            var product = target.find(id);

            if (basket[index].Quantity > 1)
            {
                basket[index].Quantity--;
                product.ItemsLeft++;
                product.ItemsSold--;
            }
            else if (basket[index].Quantity == 1)
            {
                basket.RemoveAt(index);
                product.ItemsLeft++;
                product.ItemsSold--;
            }

            repo.Update(product);
            SessionHelper.SetObjectAsJson(HttpContext.Session, "basket", basket);
            return(RedirectToAction("Index"));
        }
示例#4
0
        public void push()
        {
            ProductAdapter pa = new ProductAdapter();

            tblCompany = sqldb.GetTblData(@"select a.ID
                                            from Company a
                                            inner join ManagerTypeRCompany b
                                            on a.ID = b.IDCompany 
                                            inner join ManagerType c
                                            on b.IDType = c.ID
                                            where c.ID = 228
                                            and a.TotalNewProduct > 5", CommandType.Text, new System.Data.SqlClient.SqlParameter[] { });

            foreach (DataRow RowCom in tblCompany.Rows)
            {
                CompanyID  = QT.Entities.Common.Obj2Int64(RowCom["ID"]);
                tblProduct = sqldb.GetTblData("select ID from Product where Company = @CompanyID", CommandType.Text, new System.Data.SqlClient.SqlParameter[] {
                    sqldb.CreateParamteter("@CompanyID", CompanyID, SqlDbType.BigInt)
                });
                foreach (DataRow RowPro in tblProduct.Rows)
                {
                    ProductID = QT.Entities.Common.Obj2Int64(RowPro["ID"]);
                    pa.PushQueueChangeChangeImage(new MQChangeImage()
                    {
                        ProductID = ProductID,
                        Type      = 2
                    });
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Product);
            ImageButton btnback = FindViewById <ImageButton>(Resource.Id.btnback);

            btnback.Click += Btnback_Click;

            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });

            rv = FindViewById <RecyclerView>(Resource.Id.recycle);
            //layoutmanager  = new LinearLayoutManager(this.Activity);
            layoutmanager = new GridLayoutManager(this, 2);

            adp            = new ProductAdapter(lstdata);
            adp.ItemClick += Adp_ItemClick;
            rv.SetAdapter(adp);
            rv.SetLayoutManager(layoutmanager);

            // Create your application here
        }
示例#6
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Username = Intent.GetStringExtra(nameof(Username));
            Password = Intent.GetStringExtra(nameof(Password));

            // var username = Intent.GetStringExtra("Username")
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);

            // Add floating action button
            var addFab = FindViewById <FloatingActionButton>(Resource.Id.add_fab);

            addFab.Click += AddFab_Click;

            // Recycler View
            var list = await Accounts();

            ProductAdapter            = new ProductAdapter(list);
            ProductAdapter.ItemClick += ProductAdapter_ItemClick;

            var recyclerView = FindViewById <RecyclerView>(Resource.Id.recycler_view);

            recyclerView.SetLayoutManager(new LinearLayoutManager(this));
            recyclerView.SetAdapter(ProductAdapter);
            recyclerView.AddItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.Vertical));
        }
示例#7
0
        private void Calendar_DateChange(object sender, CalendarView.DateChangeEventArgs e)
        {
            lv.Visibility = ViewStates.Visible;
            string day   = "";
            string month = "";

            if (e.DayOfMonth < 10)
            {
                day = "0" + e.DayOfMonth.ToString();
            }
            else
            {
                day = e.DayOfMonth.ToString();
            }
            int monthInt = e.Month + 1;

            if (e.Month < 10)
            {
                month = "0" + monthInt.ToString();
            }
            else
            {
                month = monthInt.ToString();
            }

            string   changedDate = e.Year.ToString() + "-" + month + "-" + day;
            DateTime date        = DateTime.ParseExact(changedDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);

            adapter    = new ProductAdapter(context, pvm.FilteredProducts(date));
            lv.Adapter = adapter;
        }
        [HttpGet]       // GET /api/product
        public IActionResult Get()
        {
            List <ProductDto> result = new List <ProductDto>();

            Program.Products.ForEach(product => result.Add(ProductAdapter.ProductToProductDto(product)));
            return(Ok(result));
        }
示例#9
0
        public static void PushDownloadHtml(IEnumerable <string> domains)
        {
            SqlDb          sql            = new SqlDb(ConfigStatic.ProductConnection);
            ProductAdapter productAdapter = new ProductAdapter(sql);

            foreach (var domain in domains)
            {
                ProducerBasic producerBasic = new ProducerBasic(RabbitMQManager.GetRabbitMQServer(ConfigStatic.KeyRabbitMqCrlProductProperties),
                                                                ConfigStatic.GetQueueWaitDownloadHtml(domain));
                string queryData = string.Format(@"
                        Select Id, DetailUrl 
                        From Product 
                        Where Company = {0}
                        Order by Id
                        "
                                                 , productAdapter.GetCompanyIdByDomain(domain));
                sql.ProcessDataTableLarge(queryData,
                                          10000, (Row, iRow) =>
                {
                    producerBasic.PublishString(new JobDownloadHtml()
                    {
                        ProductId = Convert.ToInt64(Row["Id"]),
                        DetailUrl = Convert.ToString(Row["DetailUrl"]),
                        Domain    = domain
                    }.GetJson());
                });
            }
        }
示例#10
0
        public void Start()
        {
            ProductAdapter productAdapter       = new ProductAdapter(new SqlDb(Server.ConnectionString));
            List <long>    lstCOmpanyDownloaded = productAdapter.GetCOmpanyDownloadedHTML();

            foreach (long companyID in productAdapter.GetAllCompanyIdCrawler())
            {
                if (!lstCOmpanyDownloaded.Contains(companyID))
                {
                    lst.Enqueue(companyID);
                }
            }
            int MaxThread = 100;

            for (int i = 0; i < MaxThread; i++)
            {
                int jThread = i;
                Task.Factory.StartNew(() =>
                {
                    WorkerExportHtml worker   = new WorkerExportHtml(jThread);
                    worker.eventGetCompanyID += new WorkerExportHtml.GetCompanyId(GetCompanyCrawler);
                    worker.eventProcessHtml  += new WorkerExportHtml.DelegateProcessHtml(SaveHtml);
                    worker.eventWhenFinish   += new WorkerExportHtml.DelegateWhenFinish(EventWhenFinsih);
                    worker.Start();
                });
            }
        }
        private void LoadData()
        {
            ProductAdapter productAdapter = new ProductAdapter();

            RelatedProductsRepeater.DataSource = productAdapter.GetRelatedProducts(ProductId);
            RelatedProductsRepeater.DataBind();
        }
        private void ParseRecieptJSON(JsonValue json)
        {
            // Extract the array of name/value results for the field name "weatherObservation".
            JsonValue     productsResults = json;
            List <string> itemList        = new List <string>();
            // Extract the "stationName" (location string) and write it to the location TextBox:
            bool isSuccess = productsResults["IsSuccess"];

            if (isSuccess)
            {
                JsonArray         recieptArray = (JsonArray)productsResults["products"];
                List <ProductDTO> output       = new List <ProductDTO>();
                foreach (JsonValue item in recieptArray)
                {
                    ProductDTO d = new ProductDTO();
                    d.Name     = item["Name"];
                    d.Quantity = item["Quantity"];
                    output.Add(d);
                }
                mlist = output;
                var listView = FindViewById <ListView>(Resource.Id.listProduct);
                productAdapter   = new ProductAdapter(this, mlist);
                listView.Adapter = productAdapter;
                Toast.MakeText(this, "Product recieved successfully.", ToastLength.Short).Show();
            }
            else
            {
                string errorMessage = productsResults["Message"];
                Toast.MakeText(this, errorMessage, ToastLength.Short).Show();
            }
        }
示例#13
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Activity_Product);

            CurrentPlatform.Init();

            // Create the client instance, using the mobile app backend URL.
            client = new MobileServiceClient(applicationURL);

            productTable = client.GetTable <Products>();

            pro_name     = FindViewById <EditText>(Resource.Id.pro_name);
            pro_calories = FindViewById <EditText>(Resource.Id.pro_calories);
            pro_proteins = FindViewById <EditText>(Resource.Id.pro_proteins);
            pro_carbs    = FindViewById <EditText>(Resource.Id.pro_carbs);
            pro_fats     = FindViewById <EditText>(Resource.Id.pro_fats);

            // Create an adapter to bind the items with the view
            adapter = new ProductAdapter(this, Resource.Layout.Row_List_Product);
            var listViewProdct = FindViewById <ListView>(Resource.Id.listViewProducts);

            listViewProdct.Adapter = adapter;

            // Load the items from the mobile app backend.
            OnRefreshItemsSelected();
        }
示例#14
0
        public IQueryable <HsrOrderApp.BL.DomainModel.Product> GetAll()
        {
            var Products = from c in this.db.ProductSet.AsEnumerable()
                           select ProductAdapter.AdaptProduct(c);

            return(Products.AsQueryable());
        }
示例#15
0
        private static void ExportDescription()
        {
            int            countCompany   = 0;
            StreamWriter   outfile        = new StreamWriter("ShortDescription.txt");
            List <string>  lst            = new List <string>();
            ProductAdapter productAdapter = new ProductAdapter(new SqlDb(Server.ConnectionString));
            List <long>    companyIds     = productAdapter.GetAllCompanyIdSystem();

            foreach (long companyID in companyIds)
            {
                foreach (DataRow rowInfo in productAdapter.GetDescriptionData(companyID).Rows)
                {
                    if (rowInfo["ShortDescription"] != DBNull.Value)
                    {
                        string data = rowInfo["ShortDescription"].ToString().Trim();
                        if (!string.IsNullOrEmpty(data))
                        {
                            outfile.Write(data + "\n:::::\n");
                        }
                    }
                }
                log.Info(string.Format("Success compay {0}/{1}", countCompany++, companyIds.Count));
            }
            outfile.Close();
            log.Info("OK");
        }
示例#16
0
        public void PushClassificationForCompany(long companyID, ProductAdapter productAdapter, IDatabase redisDatabase)
        {
            DataTable tblClassification = productAdapter.GetTblClassificationPushRedisForCompany(companyID);

            foreach (DataRow rowClassification in tblClassification.Rows)
            {
                long ClassificationID = Convert.ToInt64(rowClassification["ID"]);
                int  count            = 0;
                while (true)
                {
                    try
                    {
                        redisDatabase.SetAdd("classification", ClassificationID.ToString());
                        break;
                    }
                    catch (Exception ex)
                    {
                        count++;
                        if (count > 5)
                        {
                            break;
                        }
                        else
                        {
                            Thread.Sleep(1000);
                        }
                    }
                }
            }
            productAdapter.UpdateLastSyncClassificationRedisForCompany(companyID);
        }
示例#17
0
        private void btnPush_Click(object sender, EventArgs e)
        {
            ProductAdapter pt = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));

            string[] arData       = txtCompanyDomain.Text.Split(new char[] { }, 500, StringSplitOptions.RemoveEmptyEntries);
            int      countCompany = 0;

            foreach (var strCompany in arData)
            {
                long companyID = 0;
                if (long.TryParse(strCompany, out companyID))
                {
                    queueCompany.Enqueue(companyID);
                    countCompany++;
                }
                else
                {
                    companyID = pt.GetCompanyIDFromDomain(strCompany);
                    if (companyID > 0)
                    {
                        queueCompany.Enqueue(companyID);
                    }
                    countCompany++;
                }
            }

            if (countCompany > 0)
            {
                this.txtCompanyDomain.Clear();
                this.lblQueueCount.Text = string.Format("Q:{0}", queueCompany.Count);
                MessageBox.Show(string.Format("Added {0} companys", countCompany));
            }
        }
示例#18
0
        public void TestProductsToDtos()
        {
            Product product = new Product()
            {
                ProductId = 1, Name = "FakeProduct", Category = "FakeCategory", ListUnitPrice = (decimal)123.21, QuantityPerUnit = 100.2, ProductNumber = "FakeProductNumber", UnitsOnStock = 10, Version = 0
            };

            Assert.AreEqual(true, product.IsValid);

            IQueryable <Product> products = new List <Product>()
            {
                product
            }.AsQueryable();
            IList <ProductDTO> productDtos = ProductAdapter.ProductsToDtos(products);

            Assert.AreEqual <int>(1, productDtos.Count());

            ProductDTO dto = productDtos.First();

            Assert.AreEqual <int>(product.ProductId, dto.Id);
            Assert.AreEqual <string>(product.Name, dto.Name);
            Assert.AreEqual <string>(product.Category, dto.Category);
            Assert.AreEqual <double>(product.QuantityPerUnit, dto.QuantityPerUnit);
            Assert.AreEqual <decimal>(product.ListUnitPrice, dto.ListUnitPrice);
            Assert.AreEqual(true, dto.IsValid);
        }
示例#19
0
        public IQueryable <HsrOrderApp.BL.DomainModel.Product> GetAll()
        {
            var products = from p in this.db.Products
                           select ProductAdapter.AdaptProduct(p);

            return(products);
        }
示例#20
0
 private void PuschClassification()
 {
     while (true)
     {
         try
         {
             IDatabase redisDatabase  = this.connectionMutilexer.GetDatabase(8);
             var       productAdapter = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));
             DataTable tbl            = productAdapter.GetListCompanySynClassification();
             if (tbl.Rows.Count == 0)
             {
                 return;
             }
             foreach (DataRow row in tbl.Rows)
             {
                 long   companyID = Convert.ToInt64(row["ID"]);
                 string domain    = Convert.ToString(row["Domain"]);
                 this.Invoke(new Action(() =>
                 {
                     lblCompanyClasification.Text = domain;
                 }));
                 PushClassificationForCompany(companyID, productAdapter, redisDatabase);
             }
         }
         catch (ThreadAbortException ex)
         {
             return;
         }
         catch (Exception ex1)
         {
             Thread.Sleep(1000);
         }
     }
 }
示例#21
0
        public void Add(ProductDto entity)
        {
            var adapter = ProductAdapter.BuildProduct(entity);

            _repository.Add(adapter);
            entity.Code = adapter.Code;
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View v = inflater.Inflate(Resource.Layout.ProviderProductFragment, container, false);

            rv            = v.FindViewById <RecyclerView>(Resource.Id.recycle);
            btnadd        = v.FindViewById <ImageButton>(Resource.Id.btnAdd);
            btnadd.Click += Btnadd_Click;

            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product4, title = "Duos Shampoo og Basim 2x750ml", price = 60
            });
            lstdata.Add(new Product()
            {
                imgid = Resource.Drawable.product3, title = "Vitamino color mask 200ml", price = 40
            });

            //layoutmanager  = new LinearLayoutManager(this.Activity);
            layoutmanager = new GridLayoutManager(this.Activity, 2);

            adp            = new ProductAdapter(lstdata);
            adp.ItemClick += Adp_ItemClick;
            rv.SetAdapter(adp);
            rv.SetLayoutManager(layoutmanager);

            return(v);
        }
示例#23
0
        public ActionResult <string> Get()
        {
            var products = _service.GetProducts();
            var adapter  = new ProductAdapter(products);
            var xml      = adapter.GetXml().InnerXml;

            return(Content(xml, "application/xml"));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            ProductRepository   repo   = new ProductRepository();
            IProductsRepository target = new ProductAdapter(repo);
            await target.Delete(id);

            return(RedirectToAction(nameof(Index)));
        }
示例#25
0
        private void waitFindNewDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProductAdapter sqlDb = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));
            var            row   = this.gridView1.GetRow(this.gridView1.FocusedRowHandle) as DataRowView;

            sqlDb.UpdateToWaitFindNew(Convert.ToInt64(row["ID"]));
            MessageBox.Show("OK");
        }
示例#26
0
        public FrmPushJobCrawler()
        {
            InitializeComponent();

            this.productAdapter = new ProductAdapter(new Entities.Data.SqlDb(QT.Entities.Server.ConnectionString));

            this.crawlerAdapter = new CrawlerProductAdapter(new SqlDb(QT.Entities.Server.ConnectionStringCrawler));
        }
示例#27
0
        private void btnRefreshData_Click(object sender, EventArgs e)
        {
            Wait.Show("Đang xử lí dữ liệu");
            ProductAdapter productAdapter = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));

            this.gridControl1.DataSource = productAdapter.GetReportTrackCrawlerProperties();
            Wait.Close();
        }
示例#28
0
        public void GetConfigurationHotProductByTest()
        {
            QT.Entities.Server.ConnectionString = "Data Source=42.112.28.93;Initial Catalog=QT_2;Persist Security Info=True;User ID=wss_price;Password=HzlRt4$$axzG-*UlpuL2gYDu;connection timeout=200";
            ProductAdapter pa   = new ProductAdapter(new SqlDb(QT.Entities.Server.ConnectionString));
            var            conf = pa.GetConfigurationHotProductBy(8220568010056870095);

            Assert.IsNotNull(conf);
        }
示例#29
0
        protected override void OnStart(string[] args)
        {
            log.Info("Start service");
            try
            {
                InitializeComponent();
                cancelTokenSource = new CancellationTokenSource();
                string rabbitMQServerName = ConfigurationManager.AppSettings["rabbitMQServerName"];
                workers        = new Worker[workerCount];
                rabbitMQServer = RabbitMQManager.GetRabbitMQServer(rabbitMQServerName);

                string connectToSQL        = @"Data Source=172.22.30.86,1455;Initial Catalog=QT_2;Persist Security Info=True;User ID=qt_vn;Password=@F4sJ=l9/ryJt9MT;connection timeout=200";
                string connectToConnection = @"Data Source=42.112.28.93;Initial Catalog=QT_2;Persist Security Info=True;User ID=wss_price;Password=HzlRt4$$axzG-*UlpuL2gYDu;connection timeout=200";
                CrawlerProductAdapter crawlerProductAdapter = new CrawlerProductAdapter(new SqlDb(connectToSQL));
                ProductAdapter        productAdapter        = new ProductAdapter(new SqlDb(connectToConnection));

                Encoding enc = new UTF8Encoding(true, true);
                for (int i = 0; i < workerCount; i++)
                {
                    log.InfoFormat("Start worker {i}", i.ToString());
                    var worker = new Worker(AddProductToSqlJobName, false, rabbitMQServer);
                    workers[i] = worker;
                    var  token      = this.cancelTokenSource.Token;
                    Task workerTask = new Task(() =>
                    {
                        worker.JobHandler = (downloadImageJob) =>
                        {
                            try
                            {
                                token.ThrowIfCancellationRequested();
                                string strData          = enc.GetString(downloadImageJob.Data);
                                JobRabbitAddProduct job = JsonConvert.DeserializeObject <JobRabbitAddProduct>(strData);
                                if (job.DateAdd == DateTime.MinValue)
                                {
                                    job.DateAdd = productAdapter.GetLastChangeOfProduct(job.ProductID);
                                }
                                crawlerProductAdapter.SaveLogAddProduct(job.ProductID, job.DetailUrl, job.IDCompnay, job.Name, job.DateAdd);
                                log.Info(string.Format("Log for {0}", strData));
                                return(true);
                            }
                            catch (OperationCanceledException opc)
                            {
                                log.Info("End worker");
                                return(false);
                            }
                        };
                        worker.Start();
                    }, token);
                    workerTask.Start();
                    log.InfoFormat("Worker {0} started", i);
                }
            }
            catch (Exception ex)
            {
                log.Error("Start error", ex);
                throw;
            }
        }
示例#30
0
        public CategoryViewHolder(View view, CategoryAdapter adapter) : base(view)
        {
            _parentAdapter = adapter;
            _childAdapter  = new ProductAdapter(view.Context);
            _layoutManager = new LinearLayoutManager(view.Context);
            _parent        = view;

            BindViews(_parent);
        }