Exemple #1
0
        private void SavePriceHistory(GameItem game)
        {
            PriceHistroy ph = new PriceHistroy();

            ph.CheckDateTime = System.DateTime.Now.Year + "-" + DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Day.ToString("00") + " "
                               + DateTime.Now.Hour.ToString("00") + ":" + DateTime.Now.Minute.ToString("00") + ":" + DateTime.Now.Second.ToString("00");

            if (game.OriginalPrice == "")
            {
                ph.DiscountPrice = "";
                ph.OriginalPrice = game.FinalPrice;
            }
            else
            {
                ph.DiscountPrice = game.FinalPrice;
                ph.OriginalPrice = game.OriginalPrice;
            }


            ph.PSPlusPrice = game.PSPlusPrice;
            string gamehistorid            = SaveLoadUtils.GetGameNameID(game.Title);
            string jsongamehistoryFilePath = Path.Combine(_dataDirectory, gamehistorid + "_hist.json");

            SaveLoadUtils.SaveGamePriceHistroyToJson(ph, jsongamehistoryFilePath);
        }
Exemple #2
0
        private void DoAddGameFromUrl(string url)
        {
            GameItem game = new GameItem()
            {
                Title         = string.Empty,
                FinalPrice    = string.Empty,
                OriginalPrice = string.Empty,
                PSPlusPrice   = string.Empty,
                URL           = url
            };
            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(url);

            HtmlNodeCollection titleNodes = doc.DocumentNode.SelectNodes("//h1[@data-qa]");


            game.Title = titleNodes.FirstOrDefault().InnerHtml;

            ScrapePrices(game, doc);

            if (game.FinalPrice != "")
            {
                ImageSave(game, doc);
            }

            Games.Add(game);
            SavePriceHistory(game);
            SaveLoadUtils.SaveToJson(Games, _jsonFilePath);
            CheckIfGameIsOnSale();
        }
Exemple #3
0
        public void RemoveGameFromList(object game)
        {
            var gameItem = game as GameItem;

            if (gameItem == null)
            {
                return;
            }
            lock (_locker)
            {
                if (File.Exists(GetImagePath(gameItem.Title)))
                {
                    try
                    {
                        File.Delete(GetImagePath(gameItem.Title));
                    }
                    catch (Exception e)
                    {
                        ShowMessage(e.ToString(), MessageType.Error);
                    }
                }


                Games.Remove(gameItem);
                SaveLoadUtils.SaveToJson(Games, _jsonFilePath);
                CheckIfGameIsOnSale();
            }
        }
Exemple #4
0
        public void UpdateGamePrices()
        {
            lock (_locker)
            {
                IsBusy = true;
                foreach (var game in Games)
                {
                    try
                    {
                        HtmlWeb      web = new HtmlWeb();
                        HtmlDocument doc = web.Load(game.URL);
                        ScrapePrices(game, doc);

                        if (game.FinalPrice != "")
                        {
                            ImageSave(game, doc);
                        }

                        SavePriceHistory(game);
                    }
                    catch (Exception e)
                    {
                        ShowMessage(e.ToString(), MessageType.Error);
                    }
                }
                SaveLoadUtils.SaveToJson(Games, _jsonFilePath);
                CheckIfGameIsOnSale();
                IsBusy = false;
            }
        }
Exemple #5
0
        public PriceHistory(string gametitle)
        {
            InitializeComponent();

            string gamepricehistoryid = SaveLoadUtils.GetGameNameID(gametitle);

            _viewModel = new PriceHistoryViewModel(gamepricehistoryid);

            lvPrices.ItemsSource = _viewModel.Prices;
            txtTitle.Text        = gametitle;
        }
Exemple #6
0
        private string GetImagePath(string strTitle)
        {
            string imgname = SaveLoadUtils.GetGameNameID(strTitle);

            StringBuilder sb = new StringBuilder();

            sb.Append(_dataDirectory);
            sb.Append("\\");
            sb.Append(imgname);
            sb.Append(".png");
            return(sb.ToString());
        }
Exemple #7
0
        public PriceHistoryViewModel(string gamepricehistoryid)
        {
            string cwd           = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string dataDirectory = Path.Combine(cwd, "PSWishlist");

            Directory.CreateDirectory(dataDirectory);

            string jsonFilePath = Path.Combine(dataDirectory, gamepricehistoryid + "_hist.json");

            Prices = new List <PriceHistroy>();
            try
            {
                Prices = SaveLoadUtils.LoadPriceHistoryFromJson(jsonFilePath);
            }
            catch { }
        }
Exemple #8
0
        public WishlistViewModel()
        {
            CreateDataDirectory();

            Games = new List <GameItem>();
            try
            {
                lock (_locker)
                {
                    IsBusy = true;
                    Games  = SaveLoadUtils.LoadFromJson(_jsonFilePath);
                    foreach (var game in Games)
                    {
                        game.ImageSource = LoadImage(GetImagePath(game.Title));
                    }
                    IsBusy = false;
                }
            }
            catch (Exception e)
            {
                //ignore
            }
        }