Example #1
0
        static VmapAdSource LoadAdSource(XElement adSourceXml)
        {
            var result = new VmapAdSource();

            result.Id = (string)adSourceXml.Attribute("id") ?? string.Empty;
            result.AllowMultipleAds = adSourceXml.GetBoolAttribute("allowMultipleAds", true);
            result.FollowsRedirect  = adSourceXml.GetBoolAttribute("followRedirects", true);
            var vastDataXml = adSourceXml.Element(ns + "VASTAdData") ?? adSourceXml.Element(ns + "VASTData"); // HACK: VASTData is a typeo in VMAP spec so it may be phased out eventually.

            if (vastDataXml != null)
            {
                var innerVastDataXml = vastDataXml.Elements().FirstOrDefault();
                if (innerVastDataXml != null)
                {
                    result.VastData = innerVastDataXml.ToString() ?? string.Empty;
                }
            }

            var customAdDataXml = adSourceXml.Element(ns + "CustomAdData");

            if (customAdDataXml != null)
            {
                result.CustomAdData             = customAdDataXml.Value ?? string.Empty;
                result.CustomAdDataTemplateType = (string)customAdDataXml.Attribute("templateType") ?? string.Empty;
            }

            var adTagXml = adSourceXml.Element(ns + "AdTagURI");

            if (adTagXml != null)
            {
                if (!string.IsNullOrEmpty(adTagXml.Value))
                {
                    result.AdTag = new Uri(adTagXml.Value);
                }
                result.AdTagTemplateType = (string)adTagXml.Attribute("templateType") ?? string.Empty;
            }

            return(result);
        }
        static VmapAdSource LoadAdSource(XElement adSourceXml)
        {
            var result = new VmapAdSource();

            result.Id = (string)adSourceXml.Attribute("id") ?? string.Empty;
            result.AllowMultipleAds = adSourceXml.GetBoolAttribute("allowMultipleAds", true);
            result.FollowsRedirect = adSourceXml.GetBoolAttribute("followRedirects", true);
            var vastDataXml = adSourceXml.Element(ns + "VASTAdData") ?? adSourceXml.Element(ns + "VASTData"); // HACK: VASTData is a typeo in VMAP spec so it may be phased out eventually.
            if (vastDataXml != null)
            {
                var innerVastDataXml = vastDataXml.Elements().FirstOrDefault();
                if (innerVastDataXml != null)
                {
                    result.VastData = innerVastDataXml.ToString() ?? string.Empty;
                }
            }

            var customAdDataXml = adSourceXml.Element(ns + "CustomAdData");
            if (customAdDataXml != null)
            {
                result.CustomAdData = customAdDataXml.Value ?? string.Empty;
                result.CustomAdDataTemplateType = (string)customAdDataXml.Attribute("templateType") ?? string.Empty;
            }

            var adTagXml = adSourceXml.Element(ns + "AdTagURI");
            if (adTagXml != null)
            {
                if (!string.IsNullOrEmpty(adTagXml.Value))
                {
                    result.AdTag = new Uri(adTagXml.Value);
                }
                result.AdTagTemplateType = (string)adTagXml.Attribute("templateType") ?? string.Empty;
            }

            return result;
        }
        /// <summary>
        /// Creates an IAdSource from a VMAP AdSource (required for the AdHandlerPlugin to play the ad).
        /// </summary>
        /// <param name="source">The VMAP AdSource object</param>
        /// <returns>An IAdSource object that can be played by the AdHandlerPlugin. Returns null if insufficient data is available.</returns>
        public static IAdSource GetAdSource(VmapAdSource source)
        {
            IAdSource result = null;
            if (!string.IsNullOrEmpty(source.VastData))
            {
                result = new AdSource(source.VastData, VastAdPayloadHandler.AdType);
            }
            else if (!string.IsNullOrEmpty(source.CustomAdData))
            {
                result = new AdSource(source.CustomAdData, source.CustomAdDataTemplateType);
            }
            else if (source.AdTag != null)
            {
                result = new RemoteAdSource(source.AdTag, source.AdTagTemplateType);
            }

            if (result != null)
            {
                result.AllowMultipleAds = source.AllowMultipleAds;
                result.MaxRedirectDepth = source.FollowsRedirect ? new int?() : 0;
            }

            return result;
        }