Example #1
0
        /// <summary>
        /// Extract ad wrapper
        /// </summary>
        /// <param name="wrapper"></param>
        private void ExtractWrapper(Wrapper wrapper)
        {
            // Create wrapper
            VWrapper wr = new VWrapper();

            wr.AdSystem     = wrapper.AdSystem.Text;
            wr.VASTAdTagURI = wrapper.AdTagURI.Text;
            if (wrapper.Error != null)
            {
                wr.ErrorURI = wrapper.Error.Text;
            }

            for (int i = 0; i < wrapper.Impressions.Length; i++)
            {
                wr.Impressions.Add(i, wrapper.Impressions[i].URL);
            }

            for (int i = 0; i < wrapper.Creatives.Creative.Length; i++)
            {
                VCreative vc = new VCreative();
                vc.ID       = string.Empty;
                vc.Sequence = string.Empty;

                if (wrapper.Creatives.Creative[i].LinearAds[0] != null)
                {
                    vc.Type     = "Linear";
                    vc.Duration = string.Empty;

                    // Get tracking events
                    if (wrapper.Creatives != null && wrapper.Creatives.Creative[i] != null)
                    {
                        if (wrapper.Creatives.Creative[i].TrackingEvents != null)
                        {
                            for (int k = 0; k < wrapper.Creatives.Creative[i].TrackingEvents.Length; k++)
                            {
                                Tracking[] tracking = wrapper.Creatives.Creative[i].TrackingEvents[k].Tracking;
                                for (int j = 0; j < tracking.Length; j++)
                                {
                                    if (vc.TrackingEvents.ContainsKey(tracking[j].EventType))
                                    {
                                        vc.TrackingEvents[tracking[j].EventType].Add(tracking[j].EventURL);
                                    }
                                    else
                                    {
                                        vc.TrackingEvents.Add(tracking[j].EventType, new List <string>()
                                        {
                                            tracking[j].EventURL
                                        });
                                    }
                                }
                            }
                        }

                        if (wrapper.Creatives.Creative[i].VideoClicks != null)
                        {
                            VideoClicks clicks = wrapper.Creatives.Creative[i].VideoClicks;
                            if (clicks.ClickThrough != null && !string.IsNullOrEmpty(clicks.ClickThrough.Text))
                            {
                                vc.VideoClicks.Add(VStrings.Ad_ClickThrough, clicks.ClickThrough.Text);
                            }
                            if (clicks.ClickTracking != null && !string.IsNullOrEmpty(clicks.ClickTracking.Text))
                            {
                                vc.VideoClicks.Add(VStrings.Ad_ClickTracking, clicks.ClickTracking.Text);
                            }
                            if (clicks.CustomClick != null && !string.IsNullOrEmpty(clicks.CustomClick.Text))
                            {
                                vc.VideoClicks.Add(VStrings.Ad_CustomClick, clicks.CustomClick.Text);
                            }
                        }
                    }
                }
                else if (wrapper.Creatives.Creative[i].NonLinearAds[0] != null)
                {
                    // TODO: Handling for nonlinear
                    vc.Type     = "NonLinear";
                    vc.Duration = string.Empty;
                }
                else if (wrapper.Creatives.Creative[i].CompanionAds[0] != null)
                {
                    // TODO: Handling for companions
                    vc.Type     = "CompanionAd";
                    vc.Duration = "0";
                }

                wr.Creatives.Add(vc);
            }

            m_wrapperList.Add(wr);
            m_wrapperCount++;

            RequestAd();
        }
Example #2
0
        /// <summary>
        /// Get all the needed info for playable ad.
        /// </summary>
        /// <param name="inline"></param>
        /// <returns></returns>
        private VPlayableAd ParseInline(InLine inline)
        {
            VPlayableAd ad = new VPlayableAd();

            ad.AdSystem        = inline.AdSystem.Text;
            ad.AdSystemVersion = inline.AdSystem.Version;
            ad.AdTitle         = inline.AdTitle.Text;

            // add impressions
            for (int i = 0; i < inline.Impressions.Length; i++)
            {
                ad.Impressions.Add(i, inline.Impressions[i].URL);
            }

            // create creatives
            for (int i = 0; i < inline.Creatives.Creative.Length; i++)
            {
                VCreative vc = new VCreative();
                vc.ID       = inline.Creatives.Creative[i].Id;
                vc.Sequence = inline.Creatives.Creative[i].Sequence;

                if (inline.Creatives.Creative[i].LinearAds != null)
                {
                    foreach (var linear in inline.Creatives.Creative[i].LinearAds)
                    {
                        vc.Type = "Linear";
                        if (linear.SkipOffset != null)
                        {
                            vc.SkipOffset = linear.SkipOffset;
                            vc.Skippable  = true;
                        }
                        vc.Duration = linear.Duration;

                        if (linear.TrackingEvents != null)
                        {
                            // Get tracking events
                            Tracking[] tracking = linear.TrackingEvents.Tracking;
                            for (int j = 0; j < tracking.Length; j++)
                            {
                                if (vc.TrackingEvents.ContainsKey(tracking[j].EventType))
                                {
                                    vc.TrackingEvents[tracking[j].EventType].Add(tracking[j].EventURL);
                                }
                                else
                                {
                                    vc.TrackingEvents.Add(tracking[j].EventType, new List <string>()
                                    {
                                        tracking[j].EventURL
                                    });
                                }
                            }
                        }

                        if (linear.VideoClicks != null)
                        {
                            // Get click events
                            VideoClicks clicks = linear.VideoClicks;
                            if (clicks != null)
                            {
                                if (clicks.ClickThrough != null && !string.IsNullOrEmpty(clicks.ClickThrough.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_ClickThrough, clicks.ClickThrough.Text);
                                }
                                if (clicks.ClickTracking != null && !string.IsNullOrEmpty(clicks.ClickTracking.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_ClickTracking, clicks.ClickTracking.Text);
                                }
                                if (clicks.CustomClick != null && !string.IsNullOrEmpty(clicks.CustomClick.Text))
                                {
                                    vc.VideoClicks.Add(VStrings.Ad_CustomClick, clicks.CustomClick.Text);
                                }
                            }
                        }

                        if (linear.MediaFiles != null)
                        {
                            // Get playable media file
                            MediaFile[] media = linear.MediaFiles.MediaFile;
                            if (media != null)
                            {
                                for (int j = 0; j < media.Length; j++)
                                {
                                    vc.MediaFiles.Add(media[j].MimeType, media[j].MediaUrl.Trim());
                                }
                            }
                        }
                    }
                }
                else if (inline.Creatives.Creative[i].NonLinearAds != null)
                {
                    vc.Type = "NonLinear";
                    Debug.Log("NonLinearAds are not supported");
                }
                else if (inline.Creatives.Creative[i].CompanionAds != null && !m_isMidRoll)
                {
                    vc.Type = "CompanionAd";

                    // TODO: calculate space for banner based on image size in UI
                    Companion companion = FindSuitableCompanion(inline.Creatives.Creative[i].CompanionAds, 300, 250);
                    if (companion != null)
                    {
                        vc.StaticImageUrl        = companion.StaticResourceURL.Text;
                        vc.CompanionClickThrough = companion.ClickThrough.Text;

                        // get creative view events
                        if (companion.TrackingEvents != null && companion.TrackingEvents.Tracking.Length > 0)
                        {
                            for (int j = 0; j < companion.TrackingEvents.Tracking.Length; j++)
                            {
                                if (vc.TrackingEvents.ContainsKey(companion.TrackingEvents.Tracking[j].EventType))
                                {
                                    vc.TrackingEvents[companion.TrackingEvents.Tracking[j].EventType].Add(companion.TrackingEvents.Tracking[j].EventURL);
                                }
                                else
                                {
                                    vc.TrackingEvents.Add(companion.TrackingEvents.Tracking[j].EventType, new List <string>()
                                    {
                                        companion.TrackingEvents.Tracking[j].EventURL
                                    });
                                }
                            }
                        }
                    }
                }

                ad.Creatives.Add(vc);
            }

            if (inline.Extensions != null && inline.Extensions.Extension != null)
            {
                if (inline.Extensions.Extension.Length > 0)
                {
                    for (int i = 0; i < inline.Extensions.Extension.Length; i++)
                    {
                        ad.Extensions.Add(inline.Extensions.Extension[i].Type, inline.Extensions.Extension[i].Value);
                    }
                }
            }

            return(ad);
        }