private WebClient DownloadSource(VastAdUnit ad, Action <bool> Completed)
        {
            WebClient wc = new WebClient();

            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnSourceDownloadCompleted);
            Uri uri = ConversionHelper.GetAbsoluteUri(System.Windows.Application.Current.Host.Source, ad.Source.Uri);

            wc.DownloadStringAsync(uri, new Tuple <VastAdUnit, Action <bool> >(ad, Completed));
            return(wc);
        }
        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);
        }
        private void OnSourceDownloadCompleted(DownloadStringCompletedEventArgs e, VastAdUnit ad, Action <bool> Completed)
        {
#if LATENCYTEST
            var latencySimulatorTimer = new DispatcherTimer();
            latencySimulatorTimer.Interval = TimeSpan.FromSeconds(3);
            latencySimulatorTimer.Start();
            latencySimulatorTimer.Tick += (ts, te) => {
#endif
            if (e.Error == null)
            {
                Exception ex;
                VAST      vast;

                if (VAST.Deserialize(e.Result, out vast, out ex) && vast != null)
                {
                    var key = GetAdSourceKey(ad.Source);
                    if (!AvailableAds.ContainsKey(key))
                    {
                        AvailableAds.Add(key, vast);
                    }
                    ad.Vast = vast;

                    if (Completed != null)
                    {
                        Completed(true);
                    }
                }
                if (ex != null)
                {
                    if (Completed != null)
                    {
                        Completed(false);
                    }
                }
            }
            else
            {
                //Log.Output(OutputType.Error, "Unknown error handling VAST doc from source url: " + t.Source.uri);
                if (Completed != null)
                {
                    Completed(false);
                }
            }
#if LATENCYTEST
            latencySimulatorTimer.Stop();
        };
#endif
        }
        /// <summary>
        /// Populates an AdUnit with the VAST info, downloads the VAST doc if necessary
        /// </summary>
        /// <param name="ad">The VastAdUnit to be populated</param>
        /// <param name="Completed">Fired when the operation is complete, includes a status param</param>
        internal void LoadAdUnitAsync(VastAdUnit ad, Action <bool> Completed)
        {
            if (!string.IsNullOrEmpty(ad.Source.Uri))
            {
                var key = GetAdSourceKey(ad.Source);
                //look to see if we have a source already
                if (AvailableAds.ContainsKey(key))
                {
                    VAST vast = AvailableAds[key];
                    ad.Vast = vast;

                    if (Completed != null)
                    {
                        Completed(true);
                    }
                }
                else if (downloadingAds.ContainsKey(key))
                {
                    // piggy back on the currently downloading doc
                    var wc = downloadingAds[key];
                    wc.DownloadStringCompleted += (s, e) =>
                    {
                        OnSourceDownloadCompleted(e, ad, Completed);
                    };
                }
                else
                {
                    var wc = DownloadSource(ad, Completed);
                    downloadingAds.Add(key, wc);    // add the webclient to a dictionary
                }
            }
            else
            {
                if (Completed != null)
                {
                    Completed(false);
                }
            }
        }
Ejemplo n.º 6
0
 internal VastAdPod(VastAdUnit AdUnit, VastCreativeFactory AdModelFactory)
     : base()
 {
     this.AdUnit         = AdUnit;
     this.AdModelFactory = AdModelFactory;
 }
 internal VastAdPod(VastAdUnit AdUnit, VastCreativeFactory AdModelFactory)
     : base()
 {
     this.AdUnit = AdUnit;
     this.AdModelFactory = AdModelFactory;
 }
        private void OnSourceDownloadCompleted(DownloadStringCompletedEventArgs e, VastAdUnit ad, Action<bool> Completed)
        {
#if LATENCYTEST
            var latencySimulatorTimer = new DispatcherTimer();
            latencySimulatorTimer.Interval = TimeSpan.FromSeconds(3);
            latencySimulatorTimer.Start();
            latencySimulatorTimer.Tick += (ts, te) => {
#endif
            if (e.Error == null)
            {
                Exception ex;
                VAST vast;

                if (VAST.Deserialize(e.Result, out vast, out ex) && vast != null)
                {
                    var key = GetAdSourceKey(ad.Source);
                    if (!AvailableAds.ContainsKey(key))
                    {
                        AvailableAds.Add(key, vast);
                    }
                    ad.Vast = vast;

                    if (Completed != null) Completed(true);
                }
                if (ex != null)
                {
                    if (Completed != null) Completed(false);
                }
            }
            else
            {
                //Log.Output(OutputType.Error, "Unknown error handling VAST doc from source url: " + t.Source.uri);
                if (Completed != null) Completed(false);
            }
#if LATENCYTEST
            latencySimulatorTimer.Stop();
        };
#endif
        }
 private WebClient DownloadSource(VastAdUnit ad, Action<bool> Completed)
 {
     WebClient wc = new WebClient();
     wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(OnSourceDownloadCompleted);
     Uri uri = ConversionHelper.GetAbsoluteUri(System.Windows.Application.Current.Host.Source, ad.Source.Uri);
     wc.DownloadStringAsync(uri, new Tuple<VastAdUnit, Action<bool>>(ad, Completed));
     return wc;
 }
        /// <summary>
        /// Populates an AdUnit with the VAST info, downloads the VAST doc if necessary
        /// </summary>
        /// <param name="ad">The VastAdUnit to be populated</param>
        /// <param name="Completed">Fired when the operation is complete, includes a status param</param>
        internal void LoadAdUnitAsync(VastAdUnit ad, Action<bool> Completed)
        {
            if (!string.IsNullOrEmpty(ad.Source.Uri))
            {
                var key = GetAdSourceKey(ad.Source);
                //look to see if we have a source already
                if (AvailableAds.ContainsKey(key))
                {
                    VAST vast = AvailableAds[key];
                    ad.Vast = vast;

                    if (Completed != null) Completed(true);
                }
                else if (downloadingAds.ContainsKey(key))
                {
                    // piggy back on the currently downloading doc
                    var wc = downloadingAds[key];
                    wc.DownloadStringCompleted += (s, e) =>
                    {
                        OnSourceDownloadCompleted(e, ad, Completed);
                    };
                }
                else
                {
                    var wc = DownloadSource(ad, Completed);
                    downloadingAds.Add(key, wc);    // add the webclient to a dictionary
                }
            }
            else
            {
                if (Completed != null) Completed(false);
            }
        }