Ejemplo n.º 1
0
	public AppCache()
	{
		using (GmConnection conn = Global.CreateConnection())
		{
			// Banners
			int count = (int)conn.ExecuteScalar("select count(*) from Banners where Status>0");
			banners = new Dictionary<int, Banner>(count);
			using (DbDataReader dr = conn.ExecuteReader("select * from Banners where Status>0"))
			{
				while (dr.Read())
				{
					Banner banner = new Banner(dr);
					banners.Add(banner.Id, banner);
				}
			}

			// BannerTopics
			count = (int)conn.ExecuteScalar("select count(*) from BannerTopics");
			bannerTopics = new Dictionary<int, BannerTopic>(count);
			using (DbDataReader dr = conn.ExecuteReader("select * from BannerTopics"))
			{
				while (dr.Read())
				{
					BannerTopic bannerTopic = new BannerTopic(dr);
					bannerTopics.Add(bannerTopic.Id, bannerTopic);
				}
			}
			if (bannerTopics.ContainsKey(Constants.defaultBannerTopicId))
			{
				defaultBannerTopic = bannerTopics[Constants.defaultBannerTopicId];
			}
			//if (defaultBannerTopic == null) throw new TargetLabsException("defaultBannerTopic not found.");

			// Pages
			count = (int)conn.ExecuteScalar("select count(*) from Pages");
			pages = new Dictionary<int, WebPage>(count);
			pagesByName = new Dictionary<string, WebPage>(count);
			using (DbDataReader dr = conn.ExecuteReader("select * from Pages"))
			{
				while (dr.Read())
				{
					WebPage page = new WebPage(dr);
					pages.Add(page.Id, page);
					pagesByName.Add(page.name.Trim().ToLower(), page);
				}
			}
			if (pages.ContainsKey(Constants.defaultPageId))
			{
				defaultPage = pages[Constants.defaultPageId];
			}
			//if (defaultPage == null) throw new TargetLabsException("defaultPage not found.");
		}
	}
Ejemplo n.º 2
0
 private void AddBanners(WebPage webPage, AppCache appCache)
 {
     if (webPage != null && webPage.bannerTopicId > 0)
     {
         BannerTopic bt = appCache.GetBannerTopic(webPage.bannerTopicId);
         if (bt != null)
         {
             int[] bannerIds = { bt.b1, bt.b2, bt.b3, bt.b4, bt.b5, bt.b6, bt.b7, bt.b8, bt.b9 };
             for (int i = 0; i < bannerIds.Length; i++)
             {
                 int bannerIndex = i + 1;
                 int bannerId    = bannerIds[i];
                 if (bannerId > 0 && !banners.ContainsKey(bannerIndex))
                 {
                     Banner banner = appCache.GetBanner(bannerId);
                     if (banner != null)
                     {
                         banners.Add(bannerIndex, banner);
                     }
                 }
             }
         }
     }
 }