private static CreativeCompanions LoadCompanions(XElement vastCompanions) { var companionCreative = new CreativeCompanions(); companionCreative.Required = (vastCompanions.Attribute("required") != null) ? (CompanionAdsRequired)Enum.Parse(typeof(CompanionAdsRequired), (string)vastCompanions.Attribute("required"), true) : CompanionAdsRequired.None; foreach (var vastCompanion in vastCompanions.Elements("Companion")) { var companion = new Companion(); foreach (var trackingEvent in GetTrackingEvents(vastCompanion).Where(t => t.Type == TrackingType.CreativeView)) { companion.ViewTracking.Add(trackingEvent.Value); } if (vastCompanion.Elements("AdParameters").Any()) { var xmlEncoded = (bool?)vastCompanion.Element("AdParameters").Attribute("xmlEncoded") ?? false; companion.AdParameters = xmlEncoded ? XmlDecode((string)vastCompanion.Element("AdParameters")) : (string)vastCompanion.Element("AdParameters"); } companion.AdSlotId = (string)vastCompanion.Attribute("adSlotId") ?? string.Empty; companion.AltText = (string)vastCompanion.Element("AltText") ?? string.Empty; companion.ApiFramework = (string)vastCompanion.Attribute("apiFramework") ?? string.Empty; companion.AssetHeight = (int?)vastCompanion.Attribute("assetHeight"); companion.AssetWidth = (int?)vastCompanion.Attribute("assetWidth"); companion.ClickThrough = GetUriValue(vastCompanion.Element("CompanionClickThrough")); // TODO: this is not in the schema //foreach (var vastTracking in vastCompanion.CompanionClickTracking) //{ // companion.ClickTracking.Add(new Uri(vastTracking)); //} if (vastCompanion.Elements("CreativeExtensions").Any()) { foreach (var vastExtension in vastCompanion.Element("CreativeExtensions").Elements("CreativeExtension")) { companion.Extensions.Add(new Extension()); // TODO } } companion.ExpandedHeight = (int?)vastCompanion.Attribute("expandedHeight"); companion.ExpandedWidth = (int?)vastCompanion.Attribute("expandedWidth"); companion.Height = (int?)vastCompanion.Attribute("height") ?? 0; companion.Width = (int?)vastCompanion.Attribute("width") ?? 0; companion.Item = GetResources(vastCompanion).FirstOrDefault(); companionCreative.Companions.Add(companion); } return(companionCreative); }
private static CreativeCompanions LoadCompanions(XElement vastCompanions) { var companionCreative = new CreativeCompanions(); companionCreative.Required = (vastCompanions.Attribute("required") != null) ? (CompanionAdsRequired)Enum.Parse(typeof(CompanionAdsRequired), (string)vastCompanions.Attribute("required"), true) : CompanionAdsRequired.None; foreach (var vastCompanion in vastCompanions.Elements("Companion")) { var companion = new Companion(); foreach (var trackingEvent in GetTrackingEvents(vastCompanion).Where(t => t.Type == TrackingType.CreativeView)) companion.ViewTracking.Add(trackingEvent.Value); if (vastCompanion.Elements("AdParameters").Any()) { var xmlEncoded = (bool?)vastCompanion.Element("AdParameters").Attribute("xmlEncoded") ?? false; companion.AdParameters = xmlEncoded ? XmlDecode((string)vastCompanion.Element("AdParameters")) : (string)vastCompanion.Element("AdParameters"); } companion.AdSlotId = (string)vastCompanion.Attribute("adSlotId") ?? string.Empty; companion.AltText = (string)vastCompanion.Element("AltText") ?? string.Empty; companion.ApiFramework = (string)vastCompanion.Attribute("apiFramework") ?? string.Empty; companion.AssetHeight = (int?)vastCompanion.Attribute("assetHeight"); companion.AssetWidth = (int?)vastCompanion.Attribute("assetWidth"); companion.ClickThrough = GetUriValue(vastCompanion.Element("CompanionClickThrough")); // TODO: this is not in the schema //foreach (var vastTracking in vastCompanion.CompanionClickTracking) //{ // companion.ClickTracking.Add(new Uri(vastTracking)); //} if (vastCompanion.Elements("CreativeExtensions").Any()) { foreach (var vastExtension in vastCompanion.Element("CreativeExtensions").Elements("CreativeExtension")) { companion.Extensions.Add(new Extension()); // TODO } } companion.ExpandedHeight = (int?)vastCompanion.Attribute("expandedHeight"); companion.ExpandedWidth = (int?)vastCompanion.Attribute("expandedWidth"); companion.Height = (int?)vastCompanion.Attribute("height") ?? 0; companion.Width = (int?)vastCompanion.Attribute("width") ?? 0; companion.Item = GetResources(vastCompanion).FirstOrDefault(); companionCreative.Companions.Add(companion); } return companionCreative; }
public static CreativeCompanions CreateCompanionAds(FWAd source, FWAdReference reference) { var result = new CreativeCompanions(); foreach (var creative in source.Creatives) { var companion = new Companion(); result.Companions.Add(companion); companion.AdSlotId = reference.SlotId ?? string.Empty; var rendition = creative.CreativeRenditions.OrderByDescending(cr => cr.Preference).FirstOrDefault(c => c.Asset.MimeType.ToLowerInvariant().StartsWith("image/")); if (rendition != null) { var asset = rendition.Asset; if (asset != null) { companion.Item = new StaticResource() { Value = new Uri(asset.Url), CreativeType = asset.MimeType }; companion.Width = rendition.Width; companion.Height = rendition.Height; companion.Id = asset.Id ?? string.Empty; } } var allCallbacks = reference.EventCallbacks; foreach (var url in allCallbacks.Where(ec => ec.Type == FWCallbackType.Click && !ec.ShowBrowser).SelectMany(ec => ec.GetUrls())) { companion.ClickTracking.Add(url); } var clickUrl = allCallbacks.Where(ec => ec.Type == FWCallbackType.Click && ec.ShowBrowser).SelectMany(ec => ec.GetUrls()).FirstOrDefault(); if (clickUrl != null) { companion.ClickThrough = new Uri(clickUrl); } } return result; }