Exemplo n.º 1
0
        internal UACAd(AdPackage Ad, UACAdPod Parent)
            : base()
        {
            this.Ad = Ad;
            this.ParentAdPod = Parent;
            this.FailureStrategy = Parent.FailurePolicy;
            this.CloseCompanionsOnComplete = Parent.CloseCompanionsOnComplete;

            // for now we just have a single linear ad per ad.
            // in a full VAST implemenation we might have groups based on sequence numbers.
            base.CreativeSets.Add(new UACCreativeSet(new AdPackage[] { Ad }, this));
        }
Exemplo n.º 2
0
        protected override bool ExecutePayload(IAsyncAdPayload Payload, IAdSource Source)
        {
            var result = Payload as UACAdUnit;
            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 Ad and CreativeSet to begin and complete running
                    foreach (var ad in adPod.Ads)
                    {
                        ad.RunCompleted += ad_RunCompleted;
                        foreach (var creativeSet in ad.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<Microsoft.SilverlightMediaFramework.Plugins.Advertising.VAST.AdPod, bool>(adPod_RunCompleted);
                    adPod.ReleasePlayer += new Action<Microsoft.SilverlightMediaFramework.Plugins.Advertising.VAST.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();
                        Player.ActiveMediaPlugin.AutoPlay = true;
                    }
                }

                if (needsRelease)
                {
                    adHost.ReleasePlayBlock(loadBlocker);
                }

            });
            return true;
        }
Exemplo n.º 3
0
        void adPod_RunCompleted(Microsoft.SilverlightMediaFramework.Plugins.Advertising.VAST.AdPod adPod, bool success)
        {
            adPod.RunCompleted -= adPod_RunCompleted;

            var uacAdPod = adPod as UACAdPod;
            // unhook all the event handlers we added for the individual parts of the ad operation
            foreach (var ad in uacAdPod.Ads)
            {
                ad.RunCompleted -= ad_RunCompleted;
                foreach (var creativeSet in ad.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) uacAdPod.AdUnit.OnFail();
            uacAdPod.AdUnit.Deactivate();

            OnHandleCompleted(new HandleCompletedEventArgs(uacAdPod.AdUnit.Source, success));
        }
Exemplo n.º 4
0
        protected override IAsyncAdPayload CreatePayload(IAdSource source)
        {
            // create the payload result. It will only contain UAC based ads
            var result = new UACAdUnit(source);

            // create a model to hold the ad and tell it to load itself
            activeAdPod = new UACAdPod(result, adModelFactory);
            activeAdPod.FailurePolicy = FailurePolicy;
            activeAdPod.CloseCompanionsOnComplete = CloseCompanionsOnComplete;
            result.AdPod = activeAdPod; // remember the active adspot

            return result;
        }