コード例 #1
0
        private Ads GetAds()
        {
            DateTime expiration = GetExpirationDate();
            if (expiration < DateTime.Now)
                Cache.Remove(ADSCACHE);

            Ads retVal = Cache.Get(ADSCACHE) as Ads;

            if (retVal == null)
            {
                try
                {
                    if (!File.Exists(FullPath) || expiration < DateTime.Now)
                        RetrieveAdsFromServer();
                    retVal = LoadAdsFromFile();
                    Cache.Insert(ADSCACHE, retVal, new System.Web.Caching.CacheDependency(FullPath));
                }
                catch (Exception e)
                {
                    retVal = new Ads();
                    retVal.adspace = new TextLink[1];
                    retVal.adspace[0] = new TextLink();
                    retVal.adspace[0].text = e.Message;
                    retVal.adspace[0].prefix = "Error:";
                    retVal.adspace[0].url = "#";
                }
            }
            return retVal;
        }
コード例 #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Ads adsConfig;
     if(String.IsNullOrEmpty(FileName))
     {
         adsConfig = new Ads();
         adsConfig.adspace = new TextLink[1];
         adsConfig.adspace[0] = new TextLink();
         adsConfig.adspace[0].text = "FileName is missing";
         adsConfig.adspace[0].prefix = "Error:";
         adsConfig.adspace[0].url = "#";
     }
     else
         adsConfig = GetAds();
     if (adsConfig != null && adsConfig.adspace.Length > 0)
     {
         links.DataSource = adsConfig.adspace;
         links.DataBind();
     }
     else
         Visible = false;
 }