void adPod_RunCompleted(AdPod adPod, bool success) { adPod.RunCompleted -= adPod_RunCompleted; VastAdPod vastAdPod = adPod as VastAdPod; // unhook all the event handlers we added for the individual parts of the ad operation foreach (var vastAd in vastAdPod.Ads) { vastAd.RunCompleted -= vastAd_RunCompleted; foreach (var creativeSet in vastAd.CreativeSets) { creativeSet.RunStarting -= creativeSet_RunStarting; creativeSet.RunStarted -= creativeSet_RunStarted; creativeSet.RunCompleted -= creativeSet_RunCompleted; } } // clear out the current running AdSpot. This permits other ads to be handled. activeAdPod = null; // notify upstream if (!success) { vastAdPod.AdUnit.OnFail(); } vastAdPod.AdUnit.Deactivate(); OnHandleCompleted(new HandleCompletedEventArgs(vastAdPod.AdUnit.Source, success)); }
public ActiveCreative GetCompanionCreative(VastAdPod AdPod, VASTADInLine InlineAd, Companion_type Companion) { ICreativeSource PayloadSource = new CompanionSource(InlineAd, Companion); IAdTarget target = VastAdHandler.FindTarget(AdPod.AdUnit.Source, PayloadSource); if (target == null) { return null; } else { return GetCompanionCreative(PayloadSource, target); } }
protected override IAsyncAdPayload CreatePayload(IAdSource source) { // create the payload result. It will only contain vast based ads VastAdUnit result = new VastAdUnit(source); // create a model to hold the ad and tell it to load itself activeAdPod = new VastAdPod(result, adModelFactory); activeAdPod.FailurePolicy = FailurePolicy; activeAdPod.CloseCompanionsOnComplete = CloseCompanionsOnComplete; result.AdPod = activeAdPod; // remember the active adspot return result; }
protected override IAsyncAdPayload CreatePayload(IAdSource source) { // create the payload result. It will only contain vast based ads VastAdUnit result = new VastAdUnit(source); // create a model to hold the ad and tell it to load itself activeAdPod = new VastAdPod(result, adModelFactory); activeAdPod.FailurePolicy = FailurePolicy; activeAdPod.CloseCompanionsOnComplete = CloseCompanionsOnComplete; result.AdPod = activeAdPod; // remember the active adspot return(result); }
public ActiveCreative GetCompanionCreative(VastAdPod AdPod, VASTADInLine InlineAd, Companion_type Companion) { ICreativeSource PayloadSource = new CompanionSource(InlineAd, Companion); IAdTarget target = VastAdHandler.FindTarget(AdPod.AdUnit.Source, PayloadSource); if (target == null) { return(null); } else { return(GetCompanionCreative(PayloadSource, target)); } }
internal VastAd(VASTAD Ad, VastAdPod Parent) : base() { this.Ad = Ad; this.Parent = Parent; this.FailureStrategy = Parent.FailurePolicy; this.CloseCompanionsOnComplete = Parent.CloseCompanionsOnComplete; if (Ad.Item is VASTADInLine) { var inlineAd = (VASTADInLine)Ad.Item; foreach (var item in (inlineAd.Creatives.GroupBy(c => c.sequence.ToInt()).OrderBy(i => i.Key))) { base.CreativeSets.Add(new VastCreativeSet(item, this)); } } else { throw new ArgumentException("Ad can only contain Inline ads. Wrapper ads need to be processed beforehand"); } }
internal VastAd(VASTAD Ad, VastAdPod Parent) : base() { this.Ad = Ad; this.Parent = Parent; this.FailureStrategy = Parent.FailurePolicy; this.CloseCompanionsOnComplete = Parent.CloseCompanionsOnComplete; if (Ad.Item is VASTADInLine) { var inlineAd = (VASTADInLine)Ad.Item; foreach (var item in (inlineAd.Creatives.GroupBy(c => c.sequence.ToInt()).OrderBy(i => i.Key))) { base.CreativeSets.Add(new VastCreativeSet(item, this)); } } else { throw new ArgumentException("Ad can only contain Inline ads. Wrapper ads need to be processed beforehand"); } }
/// <summary> /// Processes any wrapper ads in the adpod by downloading and merging them. /// All adpods should go through this process before being run. /// </summary> /// <param name="adPod">The adpod to process.</param> /// <param name="Completed">A callback to notify when the operation is complete.</param> internal void UnWrapAdPod(VastAdPod adPod, Action Completed) { var wrapperAds = adPod.AdUnit.Vast.Ad.Where(a => a.Item is VASTADWrapper).ToList(); if (wrapperAds.Any()) { int loadingWrapperAds = 0; foreach (var ad in wrapperAds) { loadingWrapperAds++; DownloadWrappedAd(adPod.AdUnit.Source, ad, a => { MergeWrappedAd((VASTADWrapper)ad.Item, (VASTADInLine)a.Item); ad.Item = a.Item; // now that the essential wrapper info is applied, set the wrapper to the inline. loadingWrapperAds--; if (loadingWrapperAds == 0) { Completed(); } }, (a, e) => { //todo: log error ad.Item = null; loadingWrapperAds--; if (loadingWrapperAds == 0) { Completed(); } }); } } else { Completed(); } }
protected override bool ExecutePayload(IAsyncAdPayload Payload, IAdSource Source) { var result = Payload as VastAdUnit; var adPod = result.AdPod; bool needsRelease; Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Collapsed); if (((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)adHost).IsPlayBlocked) { // if we're already blocked, stick with it. AdHost.AddPlayBlock(loadBlocker); needsRelease = true; } else { Player.ActiveMediaPlugin.Pause(); needsRelease = false; } adPod.LoadAsync(success => { Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Visible); if (success) { // now that it is loaded, watch for each vastAd and CreativeSet to begin and complete running foreach (var vastAd in adPod.Ads) { vastAd.RunCompleted += vastAd_RunCompleted; foreach (var creativeSet in vastAd.CreativeSets) { creativeSet.RunStarting += creativeSet_RunStarting; creativeSet.RunStarted += creativeSet_RunStarted; creativeSet.RunCompleted += creativeSet_RunCompleted; } } // pass on that we are now running this ad. Note: It still could fail to run. result.OnStart(); // actually run the ad adPod.RunCompleted += new Action<AdPod, bool>(adPod_RunCompleted); adPod.ReleasePlayer += new Action<AdPod>(adPod_ReleasePlayer); adPod.RunAsync(); } else { // clear out the current running AdSpot. This permits other ads to be handled. activeCreativeSets.Clear(); activeAdPod = null; // notify upstream result.OnFail(); result.Deactivate(); base.ExecuteAdFailed(Source); if (!needsRelease) { Player.ActiveMediaPlugin.Play(); } } if (needsRelease) { adHost.ReleasePlayBlock(loadBlocker); } }); return true; }
/// <summary> /// Processes any wrapper ads in the adpod by downloading and merging them. /// All adpods should go through this process before being run. /// </summary> /// <param name="adPod">The adpod to process.</param> /// <param name="Completed">A callback to notify when the operation is complete.</param> internal void UnWrapAdPod(VastAdPod adPod, Action Completed) { var wrapperAds = adPod.AdUnit.Vast.Ad.Where(a => a.Item is VASTADWrapper).ToList(); if (wrapperAds.Any()) { int loadingWrapperAds = 0; foreach (var ad in wrapperAds) { loadingWrapperAds++; DownloadWrappedAd(adPod.AdUnit.Source, ad, a => { MergeWrappedAd((VASTADWrapper)ad.Item, (VASTADInLine)a.Item); ad.Item = a.Item; // now that the essential wrapper info is applied, set the wrapper to the inline. loadingWrapperAds--; if (loadingWrapperAds == 0) Completed(); }, (a, e) => { //todo: log error ad.Item = null; loadingWrapperAds--; if (loadingWrapperAds == 0) Completed(); }); } } else { Completed(); } }
void adPod_RunCompleted(AdPod adPod, bool success) { adPod.RunCompleted -= adPod_RunCompleted; VastAdPod vastAdPod = adPod as VastAdPod; // unhook all the event handlers we added for the individual parts of the ad operation foreach (var vastAd in vastAdPod.Ads) { vastAd.RunCompleted -= vastAd_RunCompleted; foreach (var creativeSet in vastAd.CreativeSets) { creativeSet.RunStarting -= creativeSet_RunStarting; creativeSet.RunStarted -= creativeSet_RunStarted; creativeSet.RunCompleted -= creativeSet_RunCompleted; } } // clear out the current running AdSpot. This permits other ads to be handled. activeAdPod = null; // notify upstream if (!success) vastAdPod.AdUnit.OnFail(); vastAdPod.AdUnit.Deactivate(); OnHandleCompleted(new HandleCompletedEventArgs(vastAdPod.AdUnit.Source, success)); }
protected override bool ExecutePayload(IAsyncAdPayload Payload, IAdSource Source) { var result = Payload as VastAdUnit; var adPod = result.AdPod; bool needsRelease; Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Collapsed); if (((Microsoft.SilverlightMediaFramework.Core.SMFPlayer)adHost).IsPlayBlocked) { // if we're already blocked, stick with it. AdHost.AddPlayBlock(loadBlocker); needsRelease = true; } else { Player.ActiveMediaPlugin.Pause(); needsRelease = false; } adPod.LoadAsync(success => { Player.ActiveMediaPlugin.VisualElement.IfNotNull(v => v.Visibility = System.Windows.Visibility.Visible); if (success) { // now that it is loaded, watch for each vastAd and CreativeSet to begin and complete running foreach (var vastAd in adPod.Ads) { vastAd.RunCompleted += vastAd_RunCompleted; foreach (var creativeSet in vastAd.CreativeSets) { creativeSet.RunStarting += creativeSet_RunStarting; creativeSet.RunStarted += creativeSet_RunStarted; creativeSet.RunCompleted += creativeSet_RunCompleted; } } // pass on that we are now running this ad. Note: It still could fail to run. result.OnStart(); // actually run the ad adPod.RunCompleted += new Action <AdPod, bool>(adPod_RunCompleted); adPod.ReleasePlayer += new Action <AdPod>(adPod_ReleasePlayer); adPod.RunAsync(); } else { // clear out the current running AdSpot. This permits other ads to be handled. activeCreativeSets.Clear(); activeAdPod = null; // notify upstream result.OnFail(); result.Deactivate(); base.ExecuteAdFailed(Source); if (!needsRelease) { Player.ActiveMediaPlugin.Play(); } } if (needsRelease) { adHost.ReleasePlayBlock(loadBlocker); } }); return(true); }