コード例 #1
0
        private void UnWrapAd(IAdSource Source, VASTAD ad, Action <VASTAD> OnComplete, Action <VASTAD, Exception> OnError, VAST vast)
        {
            // there has to be a one to one relationship between wrapped ads and what their linear counterpart. However, a wrapped ad can point to an entire VAST doc which can contain many ads. Therefore, always just take the first one.
            var newAd = vast.Ad.FirstOrDefault(a => a.Item != null);

            if (newAd == null)
            {
                OnError(ad, new Exception("Wrapped ad was empty"));
            }
            else if (newAd.Item is VASTADWrapper)
            {
                DownloadWrappedAd(Source, newAd, OnComplete, OnError);
            }
            else
            {
                // plug the ad back into the parent
                OnComplete(newAd);
            }
        }
コード例 #2
0
        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");
            }
        }
コード例 #3
0
        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");
            }
        }
コード例 #4
0
        private void DownloadWrappedAd(IAdSource Source, VASTAD ad, Action <VASTAD> OnComplete, Action <VASTAD, Exception> OnError)
        {
            var wrapperAd = (VASTADWrapper)ad.Item;
            var url       = wrapperAd.VASTAdTagURI;

            //look to see if we have a source already
            var key = GetAdSourceKey(url, Source.AltReference);

            if (AvailableAds.ContainsKey(key))
            {
                VAST vast = AvailableAds[key];
                UnWrapAd(Source, ad, OnComplete, OnError, vast);
            }
            else
            {
                WebClient wc = new WebClient();
                wc.DownloadStringCompleted += OnWrappedAdDownloadCompleted;
                Uri uri = new Uri(url, UriKind.Absolute);
                wc.DownloadStringAsync(uri, new Tuple <IAdSource, VASTAD, Action <VASTAD>, Action <VASTAD, Exception> >(Source, ad, OnComplete, OnError));
            }
        }
 private void UnWrapAd(IAdSource Source, VASTAD ad, Action<VASTAD> OnComplete, Action<VASTAD, Exception> OnError, VAST vast)
 {
     // there has to be a one to one relationship between wrapped ads and what their linear counterpart. However, a wrapped ad can point to an entire VAST doc which can contain many ads. Therefore, always just take the first one.
     var newAd = vast.Ad.FirstOrDefault(a => a.Item != null);
     if (newAd == null)
     {
         OnError(ad, new Exception("Wrapped ad was empty"));
     }
     else if (newAd.Item is VASTADWrapper)
     {
         DownloadWrappedAd(Source, newAd, OnComplete, OnError);
     }
     else
     {
         // plug the ad back into the parent
         OnComplete(newAd);
     }
 }
        private void DownloadWrappedAd(IAdSource Source, VASTAD ad, Action<VASTAD> OnComplete, Action<VASTAD, Exception> OnError)
        {
            var wrapperAd = (VASTADWrapper)ad.Item;
            var url = wrapperAd.VASTAdTagURI;

            //look to see if we have a source already
            var key = GetAdSourceKey(url, Source.AltReference);
            if (AvailableAds.ContainsKey(key))
            {
                VAST vast = AvailableAds[key];
                UnWrapAd(Source, ad, OnComplete, OnError, vast);
            }
            else
            {
                WebClient wc = new WebClient();
                wc.DownloadStringCompleted += OnWrappedAdDownloadCompleted;
                Uri uri = new Uri(url, UriKind.Absolute);
                wc.DownloadStringAsync(uri, new Tuple<IAdSource, VASTAD, Action<VASTAD>, Action<VASTAD, Exception>>(Source, ad, OnComplete, OnError));
            }
        }