コード例 #1
0
        public void Test_Parser(int countProduct, string nameShope, string typeFile, string typeTest)
        {
            string sourse = null;

            try
            {
                managerShope             = new ManagerShope();
                shopeSetings             = managerShope.GetShope(nameShope);
                connectorShope           = new ConnectorShope(shopeSetings.urlShope, shopeSetings.prefPage, shopeSetings.typeReqvest);
                ManagerShope.listProduct = new List <Product>();
                sourse = GetDocument(typeFile, typeTest);
                shopeSetings.Parser(sourse, ref countProduct);
                Assert.AreEqual(test_Products.Count, ManagerShope.listProduct.Count);
                for (int i = 0; i < test_Products.Count; i++)
                {
                    Assert.AreEqual(test_Products[i].id, ManagerShope.listProduct[i].id);
                    Assert.AreEqual(test_Products[i].nameProduct, ManagerShope.listProduct[i].nameProduct);
                    Assert.AreEqual(test_Products[i].price, ManagerShope.listProduct[i].price);
                }
            }
            catch (InvalidDataException) { }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
コード例 #2
0
 public WorkerParser(IShopeSetings shopeSetings)
 {
     if (shopeSetings != null)
     {
         this.shopeSetings = shopeSetings;
         connectorShope    = new ConnectorShope(shopeSetings.urlShope, shopeSetings.prefPage, shopeSetings.typeReqvest);
     }
 }
コード例 #3
0
        public async Task GetAllProduct(string nameShope)
        {
            bool isShopeDB = default;

            isShopeDB    = _dAOEntity_Framfork.CheckNameShopeInDb(nameShope);
            shope        = GetShope(nameShope);
            workerParser = new WorkerParser(shope);
            if (isShopeDB)
            {
                bool isCurentDay = _dAOEntity_Framfork.CheckInDbOnDate(nameShope, DateTime.Today.ToLongDateString());
                var  listXz      = _dAOEntity_Framfork.GetAllProduct(nameShope, isCurentDay);
                if (listXz != null)
                {
                    try
                    {
                        workerParser.UpdateProduct(listXz);
                        await Task.Run(() =>
                        {
                            _dAOEntity_Framfork.UpdateProduct(nameShope);
                        });
                    }
                    catch (HttpRequestException)
                    {
                        _dAOEntity_Framfork.GetAllProduct(nameShope, true);
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                }
            }
            else
            {
                try
                {
                    workerParser.GetProducts();
                    await Task.Run(async() =>
                    {
                        await _dAOEntity_Framfork.AddAllProductInDB(nameShope);
                    });
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
コード例 #4
0
        public IShopeSetings GetShope(string nameShope)
        {
            IShopeSetings shope = null;

            try
            {
                if (nameShope == null)
                {
                    throw new ArgumentNullException("Object reference is not specified");
                }

                switch (nameShope)
                {
                case "AKS":
                {
                    shope = new ShopeAKS("AKS", "https://www.aks.ua", "catalog/notebook/page/", "parse");
                    break;
                }

                case "Fashionup":
                {
                    shope = new ShopeFashionup("Fashionup", "https://fashionup.ua", "api.php?act=pages&brand=KiDS%20UP&page=1&format=YML", "api");
                    break;
                }

                default:
                {
                    throw new ArgumentNullException();
                }
                }
            }
            catch (ArgumentNullException e)
            {
                throw new ArgumentNullException(e.Message);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(shope);
        }
コード例 #5
0
 public void Test_GetShope(string nameShope, string url, string pref, string typeReqvest)
 {
     managerShope = new ManagerShope();
     try
     {
         shopeSetings = managerShope.GetShope(nameShope);
         if (shopeSetings != null)
         {
             Assert.AreEqual(url, shopeSetings.urlShope);
             Assert.AreEqual(pref, shopeSetings.prefPage);
             Assert.AreEqual(typeReqvest, shopeSetings.typeReqvest);
             Assert.AreEqual(nameShope, shopeSetings.nameShop);
         }
         else
         {
             Assert.Fail();
         }
     }
     catch (ArgumentNullException) { }
     catch (Exception e)
     {
         Assert.Fail(e.Message);
     }
 }