Пример #1
0
 public static string CreateFeed(ProductInfoVoList productInfoVo)
 {
     try
     {
         //if (productInfoVo.title.Length > 100)
         //{
         //    productInfoVo.title = productInfoVo.title.Substring(0, 90) + "...";
         //}
         List <FeedContent> feedContent = new List <FeedContent>();
         feedContent.Add(new FeedContent(
                             productInfoVo.skuId,
                             productInfoVo.itemId,
                             productInfoVo.imageUrl
                             ));
         FeedDesc feedDesc = new FeedDesc();
         feedDesc.vi = new ViEn(
             productInfoVo.title,
             productInfoVo.title + "\n" + "Giá " + productInfoVo.discountPriceFormatted
             );
         feedDesc.en = feedDesc.vi;
         Feed feed = new Feed();
         feed.feedContent = feedContent;
         feed.feedDesc    = feedDesc;
         var data = Post(CREATE_FEED_URL, JsonConvert.SerializeObject(feed));
         return(data);
     }
     catch (Exception e)
     {
         Console.Write(e);
         return(null);
     }
 }
Пример #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            richTextBox1.AppendText("\r\nBắt đầu hẹn giờ và đăng dạo...");
            button2.Enabled = false;
            new Task(() =>
            {
                var sellerProductInfo = new List <SellerProductInfo>();
                var data = (List <ProductInfoVoList>)(productInfoVoListBindingSource.DataSource);
                sellerProductInfo.AddRange(data.Select(item => new SellerProductInfo
                {
                    SkuId                  = item.skuId,
                    SellerAccount          = currentUser,
                    DiscountPriceFormatted = item.discountPriceFormatted,
                    ImageUrl               = item.imageUrl,
                    ItemId                 = item.itemId,
                    Title                  = item.title,
                    QueueDate              = item.QueueDate.HasValue ? item.QueueDate.Value.ToUniversalTime() : (DateTime?)null
                }).ToList());
                _sellerProductInfoRepository.InsertSellerProductInfos(sellerProductInfo);

                new Task(() =>
                {
                    try
                    {
                        while (!IsClosed)
                        {
                            var productInfos = _sellerProductInfoRepository.GetAllQueue();
                            if (productInfos != null && productInfos.Count > 0)
                            {
                                var listGroup = productInfos.GroupBy(item => item.SellerAccountID).ToList();
                                listGroup.ForEach(item =>
                                {
                                    var account      = JsonConvert.DeserializeObject <List <SellerAccount> >(item.FirstOrDefault().SellerAccount).FirstOrDefault();
                                    APIHelper.cookie = account.Cookie;
                                    if (APIHelper.GetUserInfo() == null)
                                    {
                                        if (!APIHelper.Login(account.Account, CryptoHelper.Decrypt(account.Password)))
                                        {
                                            account.Cookie = APIHelper.cookie;
                                            _accountRepository.AddSellerAccount(new List <SellerAccount>
                                            {
                                                account
                                            });
                                        }
                                    }
                                    else
                                    {
                                        item.ToList().ForEach(p =>
                                        {
                                            var q = new ProductInfoVoList
                                            {
                                                title    = p.Title,
                                                imageUrl = p.ImageUrl,
                                                discountPriceFormatted = p.DiscountPriceFormatted,
                                                itemId = p.ItemId,
                                                skuId  = p.SkuId
                                            };

                                            var result = APIHelper.CreateFeed(q);
                                            if (result.IndexOf("success") > -1)
                                            {
                                                richTextBox1.SelectionColor = Color.Green;
                                                richTextBox1.AppendText("\r\nĐăng dạo sản phẩm " + p.Title + " thành công.");
                                                _sellerProductInfoRepository.UpdateStatus(p.ItemId, p.SkuId, true);
                                            }
                                            else if (result.IndexOf("has been posted") > -1)
                                            {
                                                richTextBox1.SelectionColor = Color.Green;
                                                richTextBox1.AppendText("\r\nSản phẩm này đã được đăng dạo rồi.");
                                            }
                                            else
                                            {
                                                richTextBox1.SelectionColor = Color.Green;
                                                richTextBox1.AppendText("\r\nKhông đăng dạo được.");
                                            }
                                        });
                                    }
                                });
                            }
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10));
                    }
                    catch (Exception ex)
                    {
                        richTextBox1.SelectionColor = Color.Red;
                        richTextBox1.AppendText("\r\n" + ex.Message);
                    }
                }).Start();
            }).Start();
        }