예제 #1
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);
                }
            }
        }
        public void GetAllProduct(string nameShope, bool isShopDB)
        {
            ManagerShope.listProduct = new List <Product>();
            try
            {
                dAOEntity_ = new DAOEntity_Framfork();
                object result = dAOEntity_.GetAllProduct(nameShope, isShopDB);

                if (isShopDB)
                {
                    Assert.IsNull(result);
                }
                else
                {
                    Assert.IsNotNull(result);
                }
            }
            catch (ArgumentNullException) { }
            catch (Exception)
            {
                Assert.Fail();
            }
        }