Пример #1
0
        public void Load()
        {
            if (ProductId == null)
            {
                return;
            }
            var path = Constants.Envpath + "\\DataCache\\" + ProductId.MakeFileSystemSafe().Replace("-", String.Empty) + ".pid";

            try
            {
                if (File.Exists(path))
                {
                    string       json       = File.ReadAllText(path);
                    SaveLoadData loadedData = JsonConvert.DeserializeObject <SaveLoadData>(json);
                    //todo:Fix the Get/Set Parameters of SaveLoadData So they no longer point to a possible null object
                    if (loadedData.Offers.Count > 1)
                    {
                        loadedData.Offers.RemoveAt(0);
                    }
                    _productId = loadedData._productId;
                    Offers     = loadedData.Offers;

                    /*
                     * if (loadedData.Offers.Any(offer => offer.ContentId != null))
                     * {
                     *  Offers = loadedData.Offers.FindAll(offer => offer.ContentId != null);
                     *  Reason = loadedData.Offers.Find(offer => offer.ContentId != null).Reason;
                     * }
                     * else if(loadedData.Offers.Any(offer => offer.Reason != "Unchecked"))
                     * {
                     *  Offers = loadedData.Offers.FindAll(offer => offer.Reason != "Unchecked");
                     *  Reason = loadedData.Offers[0].Reason;
                     * }
                     * else
                     * {
                     *  Offers = loadedData.Offers;
                     *  Reason = loadedData.Offers[0].Reason;
                     * }
                     */
                    //_urlchecked = loadedData._urlchecked;
                    //_downloadurl = loadedData._downloadurl;
                    _dataLoaded = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
        }
Пример #2
0
        public void Save()
        {
            //todo:Change Save Method to Single File, Scan Line by line for product ID If Product ID Exists Do nothing Else append to the end of the file
            //todo:Only Save Offers That are Valid
            if (ProductId == null)
            {
                return;
            }
            var path = Constants.Envpath + "\\DataCache\\" + ProductId.MakeFileSystemSafe().Replace("-", String.Empty) + ".pid";

            Directory.CreateDirectory(Path.GetDirectoryName(path));
            string json = JsonConvert.SerializeObject(this);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            using (StreamWriter file = File.CreateText(path))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, this);
            }
            //File.WriteAllText(path, json);
        }