예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            url = url1;

            if (Request["v"] == "2")
            {
                url     = url2;
                version = "2.0";
                Console.WriteLine("Using 2.0");
            }

            Console.WriteLine("using url = " + url);
            ArrayList sites = null;
            DateTime  now   = DateTime.Now;

            if (GetLastUpdateTime(version).AddMinutes(30) > now)             // If cache is newer than 30 mins, use it.
            {
                Console.WriteLine("Reading data from cache");
                sites = GetDataFromFile(version);
            }
            else
            {
                Console.WriteLine("Reading data from url");
                UpdateTimeStamp(now, version);
                sites = MoonParser.ParseURL(url);
                WriteDataToFile(sites, version);
            }


            string html = getHeader();

            foreach (MoonSite site in sites)
            {
                html += site.ToHtml();
            }

            html += getFooter();

            MoonContent.InnerHtml = html;
        }
예제 #2
0
        //This method reads serialized data (an ArrayList) from file. Data is not cached as text!
        private ArrayList GetDataFromFile(string version)
        {
            string    f    = cacheFile + version;
            ArrayList list = null;

            if (File.Exists(f))
            {
                FileStream reader    = new FileStream(f, FileMode.Open, FileAccess.Read);
                IFormatter formatter = new BinaryFormatter();
                list = (ArrayList)formatter.Deserialize(reader);
                reader.Close();
            }
            else
            {
                //get data from url
                UpdateTimeStamp(DateTime.Now, version);
                list = MoonParser.ParseURL(url);
                WriteDataToFile(list, version);
            }

            return(list);
        }