Esempio n. 1
0
		private BannerDataHolder PickBannerK(Identity id, BannerQuerySetInfo info)
		{
			int? indexOfBannerToReturn = null;
			double target = ThreadSafeRandom.NextDouble() * info.TotalRemainingImpressionsForTheCurrentTimeSlot;
			Stack<int> suitableBannersIndexes = new Stack<int>();
			for (int i = 0; i < info.Banners.Count && indexOfBannerToReturn == null; i++)
			{
				long remainingHits = info.GetRemainingHits(i);
				if (remainingHits == 0) { continue; }
				target -= remainingHits;
				suitableBannersIndexes.Push(i);
				if (target <= 0)
				{
					indexOfBannerToReturn = ReturnFirstBannerThatNeedsAHit(id, suitableBannersIndexes, info);
				}
			}
			if (indexOfBannerToReturn.HasValue)
			{
				return info.Banners[indexOfBannerToReturn.Value];
			}
			else
			{
				return null;
			}
		}
Esempio n. 2
0
		private static void SetUpRequestRules(Bobs.Banner.Positions position, bool isHttpsContext, Identity id, RequestRules requestRules)
		{
			requestRules.Add(new BannerPositionRule(position));
			requestRules.Add(id.IdentityRules);
			requestRules.Add(new Rules.TypesOfRule.BannerIsLiveRule());
			if (isHttpsContext)
			{
				requestRules.Add(new BannerIsNotHtmlRule());
			}
		}
Esempio n. 3
0
		private void AddBanners(int numberOfBannersToGet, Identity id, BannerQuerySetInfo info, List<BannerDataHolder> chosenBanners)
		{
			for (int i = 0; i < numberOfBannersToGet - chosenBanners.Count; i++)
			{
				BannerDataHolder banner = PickBannerK(id, info);
				if (banner != null)
				{
					chosenBanners.Add(banner);
				}
			}
		}
Esempio n. 4
0
		private void MakeBannerServerCall(Identity id, Banner.Positions position)
		{
		
			Server server = new Server();
			
			BannerDataHolder bdh = server.GetBanner(position, false, id, new Bobs.BannerServer.Rules.RequestRules());
			if (bdh != null)
			{
				LogBannerHit(id, bdh);
			}
			else
			{
				Timeslots.GetCurrentTimeslot().TotalNotShown().Increment();
			}
		}
Esempio n. 5
0
		private void Page_Init(object sender, System.EventArgs e)
		{
			if (DontRenderBannerBecauseAjaxPartialPageRequestOrCrawler)
			{
				return;
			}
			if (ContainerPage.Url.HasObjectFilter && ContainerPage.Url.ObjectFilterBob is IRelevanceContributor)
				((IRelevanceContributor) ContainerPage.Url.ObjectFilterBob).AddRelevant(ContainerPage);
			//ScriptManager.RegisterClientScriptInclude(this.Page, typeof (Page), "FlashReplace", "/Misc/FlashReplace.js");

			this.identity = Identity.Current;
			if (!ShowLinkedBanner && !ShowLinkedWootUkBanner && !ShowRoadblockedGroupPageBanner)
			{
				this.timeThatBannnerRequestThreadWasStarted = Time.Now;
				bannerRequestThread = Utilities.GetSafeThread(this.GetBannerFromBannerServer);

				//this.mainThread = System.Threading.Thread.CurrentThread;
				bannerRequestThread.Start();
			}
		}
Esempio n. 6
0
		public List<BannerDataHolder> GetBanners(Bobs.Banner.Positions position, bool isHttpsContext, int numberOfBannersToGet, Identity id, RequestRules rules)
		{
			Timeslot currentTimeslot = Timeslots.GetCurrentTimeslot();
			currentTimeslot.CallsToBannerServer().Increment();

			SetUpRequestRules(position, isHttpsContext, id, rules);

			List<BannerDataHolder> chosenBanners = new List<BannerDataHolder>(numberOfBannersToGet);

			foreach (BannerQuerySetInfo bannerQuerySetInfo in rules.BannerQuerySetInfosInDescendingPriorityOrder(currentTimeslot))
			{
				AddBanners(numberOfBannersToGet, id, bannerQuerySetInfo, chosenBanners);
				if (chosenBanners.Count == chosenBanners.Capacity) { return chosenBanners; }
			}
			#region REMOVED DUE TO BANNER SERVER BUG
			//rules.RemoveBannersWhichHaveReachedTargetsFromCachedQuery(currentTimeslot);
			#endregion
			PadOutChosenBannersWithNulls(chosenBanners);
			return chosenBanners;
		}
Esempio n. 7
0
		public BannerDataHolder GetBanner(Bobs.Banner.Positions position, bool isHttpsContext, Identity identity, RequestRules requestRules)
		{
			List<BannerDataHolder> banners = GetBanners(position, isHttpsContext, 1, identity, requestRules);
			return banners[0];
		}
Esempio n. 8
0
		bool BannerHasBeenShownToAParticularIdentityTooManyTimesToday(BannerDataHolder bdh, Identity id)
		{
			if (bdh.FrequencyCapPerIdentifierPerDay > -1)
			{
				long numberOfTimesBannerHasBeenShownToUser = Timeslots.Today.BannerHitsForIdentity(bdh.K, id.Guid).Value;
				if (numberOfTimesBannerHasBeenShownToUser >= bdh.FrequencyCapPerIdentifierPerDay)
				{
					return true;
				}
			}
			return false;
		}
Esempio n. 9
0
		private int? ReturnFirstBannerThatNeedsAHit(Identity id, Stack<int> suitableBanners,  BannerQuerySetInfo info)
		{
			double hitProportion = Common.ThreadSafeRandom.NextDouble();
			while (suitableBanners.Count > 0)
			{
				int index = suitableBanners.Peek();
				BannerDataHolder banner = info.Banners[index];
				
				if (BannerHasBeenShownToAParticularIdentityTooManyTimesToday(banner, id) || info.BannerNeedsToDropAHit(index, hitProportion))
				{
					suitableBanners.Pop();
					continue;
				}
				return suitableBanners.Peek();
			}
			return null;
		}
Esempio n. 10
0
		private static void LogBannerHit(Identity id, BannerDataHolder bdh)
		{
			Banner b = new Banner(bdh.K);

			b.RegisterHit(id);
		}
Esempio n. 11
0
		public void RegisterHit(Identity id)
		{
			Timeslot currentTimeslot = Timeslots.GetCurrentTimeslot();
			BannerTimeslotInfo bannerTimeslotInfo = new BannerTimeslotInfo(K, currentTimeslot);
			bannerTimeslotInfo.ActualHits.Increment();
			bool isUniqueVisitorHit = Timeslots.Today.BannerHitsForIdentity(K, id.Guid).Increment() == 1;
			this.TotalHitsCounter.Increment();
			Bobs.BannerStat.Log(this.K, this.Position, DateTime.Today, 1, isUniqueVisitorHit ? 1 : 0, 0);
			
		}