void LoadAdUnit(ActiveAdUnit newAdUnit, ICollection <ICreative> creativeSet) { // load companions CompanionAdsRequired required = CompanionAdsRequired.None; IEnumerable <ICompanionSource> companionsToLoad = Enumerable.Empty <ICompanionSource>(); var companions = creativeSet.OfType <CreativeCompanions>().FirstOrDefault(); if (companions != null) { companionsToLoad = companions.Companions.Cast <ICompanionSource>(); required = companions.Required; } else { // VPAID 2.0 supports companions that come from the VPAID player. // these are only to be used with the VAST file contains none. if (newAdUnit.Player is IVpaid2) { var companionData = ((IVpaid2)newAdUnit.Player).AdCompanions; if (!string.IsNullOrEmpty(companionData)) { CreativeCompanions vpaidCompanions; using (var stream = companionData.ToStream()) { vpaidCompanions = AdModelFactory.CreateCompanionsFromVast(stream); } companionsToLoad = vpaidCompanions.Companions.Cast <ICompanionSource>(); required = vpaidCompanions.Required; } } } try { OnActivateAd(newAdUnit, companionsToLoad, required); } catch (Exception ex) { throw new LoadException(ex); } }
static async Task ProcessPayload(IAdSource adSource) { if (adSource.Payload is Stream) { using (var stream = (Stream)adSource.Payload) { adSource.Payload = await AdModelFactory.CreateFromVast(stream, adSource.MaxRedirectDepth, adSource.AllowMultipleAds); } } else if (adSource.Payload is string) { using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes((string)adSource.Payload))) { adSource.Payload = await AdModelFactory.CreateFromVast(stream, adSource.MaxRedirectDepth, adSource.AllowMultipleAds); } } if (!(adSource.Payload is AdDocumentPayload)) { throw new ArgumentException("adSource must contain a payload of type Stream", "adPayload"); } }