Exemple #1
0
    public void ReadData()
    {
        try
        {
            if (System.IO.File.Exists(path))
            {
                string      contents = System.IO.File.ReadAllText(path);
                ShopWrapper wrapper  = JsonUtility.FromJson <ShopWrapper>(contents);
                if (wrapper.shopData.stock.Count < 1)
                {
                    SaveData();
                }
                else
                {
                    shopData = wrapper.shopData;
                }
            }
            else
            {
                Debug.Log("Unable to read the save data, file does not exist... creating new data");

                //If there's no data then we need to create some new data.
                //If there's no stock already premade, we create some empty data.
                //This should not happen as we can set up the default instance of stock in the inspector.
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex.Message);
        }
    }
Exemple #2
0
        public IEnumerable <Product> GetProducts([FromBody] ParseDomainParams pdp)
        {
            if (pdp != null)
            {
                System.Diagnostics.Debug.WriteLine("Parse enums:" + pdp.DescriptionGetKind + " " + pdp.SearchPriceKind);
            }
            //var pdp1 = new ParseDomainParams("https://www.olx.ua", new HashSet<string>(), new HashSet<string>(), new string[] { "" }, "", 0, 0);
            if (pdp != null && Uri.TryCreate(pdp.Domain, UriKind.Absolute, out Uri uri))
            {
                var shopWrapper = new ShopWrapper(pdp);

                var products = shopWrapper.WrapShop();

                foreach (var product in products)
                {
                    //adding new images to database:

                    foreach (var image in product.Images)
                    {
                        db.Images.Add(image);
                    }

                    //TODO: Add try catch exception
                    var p = db.Products.Any() ? db.Products.Where(x => x.Description == product.Description && x.Domain == product.Domain && x.Currency.Code == product.Currency.Code).SingleOrDefault() : null;

                    if (p != null)
                    {
                        db.LoadConnections(p);

                        List <Image> oldImages = p.Images.ToList();

                        oldImages.ForEach(img => p.Images.Remove(img));

                        foreach (var img in product.Images)
                        {
                            p.Images.Add(img);
                        }

                        p.DeltaPrice = p.Price - product.Price;
                        p.Price      = product.Price;
                        p.Currency   = db.FindCurrency(p.Currency.Code);
                        db.Products.Attach(p);
                    }
                    else
                    {
                        product.Currency = db.FindCurrency(product.Currency.Code);
                        db.Products.Add(product);
                    }
                }
                db.SaveChanges();
            }
            var list = db.Products.ToList();

            list.ForEach(x => db.LoadCurrency(x));
            return(list);
        }
Exemple #3
0
    public void SaveData()
    {
        ShopWrapper wrapper = new ShopWrapper();

        wrapper.shopData = shopData;

        string contents = JsonUtility.ToJson(wrapper, true);

        System.IO.File.WriteAllText(path, contents);
    }