Пример #1
0
        private bool readFromCache(string href)
        {
            string cachedFile = CachePath + Epg.validateFileName(href + ".dat");

            if (File.Exists(cachedFile))
            {
                FileStream fs = null;
                try
                {
                    fs = new FileStream(cachedFile, FileMode.Open);
                    BinaryFormatter formatter = new BinaryFormatter();
                    result.EpgData = (string[])formatter.Deserialize(fs);
                    fs.Close();
                    return(true);
                }
                catch
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
            return(false);
        }
Пример #2
0
        private void cacheData(string href)
        {
            // Cache received data
            if (!Directory.Exists(CachePath))
            {
                Directory.CreateDirectory(CachePath);
            }

            FileStream fs = new FileStream(CachePath + Epg.validateFileName(href + ".dat"), FileMode.Create);

            try
            {
                //save to disk
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(fs, result.EpgData);
                fs.Close();
            }
            catch
            {
                fs.Close();
            }
        }