Пример #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);
        }
Пример #2
0
        public static void SaveGamePriceHistroyToJson(PriceHistroy priceHist, string fileName)
        {
            List <PriceHistroy> lph;

            if (System.IO.File.Exists(fileName))
            {
                lph = LoadPriceHistoryFromJson(fileName);
                lph.Add(priceHist);
            }
            else
            {
                lph = new List <PriceHistroy>();
                lph.Add(priceHist);
            }

            string json = JsonConvert.SerializeObject(lph, Formatting.Indented);

            using (StreamWriter sw = new StreamWriter(fileName))
            {
                sw.WriteLine(json);
            }
        }