public static async Task<AdDocumentPayload> GetAdDocumentPayload(FWTemporalAdSlot adSlot, FWAdResponse adResponse, CancellationToken c)
#endif
        {
            var payload = new AdDocumentPayload();
            var adPod = new AdPod();
            payload.AdPods.Add(adPod);
            foreach (var adReference in adSlot.SelectedAds)
            {
                var ad = await CreateAd(adResponse, adReference);
                adPod.Ads.Add(ad);

                foreach (var fallbackAdReference in adReference.FallbackAds)
                {
                    var fallbackAd = await CreateAd(adResponse, fallbackAdReference);
                    ad.FallbackAds.Add(fallbackAd);
                }
            }
            return payload;
        }
 /// <summary>
 /// Creates an AdDocumentPayload from a SmartXML ad slot.
 /// </summary>
 /// <param name="adSlot">The FWTemporalAdSlot object defining the ad payload</param>
 /// <param name="adResponse">The entire SmartXML document (required for cross referencing)</param>
 /// <returns>An AdDocumentPayload object that can be played by the AdHandlerPlugin.</returns>
 public static IAsyncOperation<AdDocumentPayload> GetAdDocumentPayload(FWTemporalAdSlot adSlot, FWAdResponse adResponse)
 {
     return AsyncInfo.Run(c => GetAdDocumentPayload(adSlot, adResponse, c));
 }
        /// <summary>
        /// Creates an AdDocumentPayload from a SmartXML ad slot.
        /// </summary>
        /// <param name="adSlot">The FWTemporalAdSlot object defining the ad payload</param>
        /// <param name="adResponse">The entire SmartXML document (required for cross referencing)</param>
        /// <returns>An AdDocumentPayload object that can be played by the AdHandlerPlugin.</returns>
#if NETFX_CORE
        internal static async Task<AdDocumentPayload> GetAdDocumentPayload(FWTemporalAdSlot adSlot, FWAdResponse adResponse, CancellationToken c)
        internal static FWTemporalAdSlot LoadTemporalAdSlot(XElement element)
        {
            var result = new FWTemporalAdSlot();
            var height = (string)element.Attribute("height");
            if (height != null) result.Height = int.Parse(height);
            var width = (string)element.Attribute("width");
            if (width != null) result.Width = int.Parse(width);
            result.CompatibleDimensions = (string)element.Attribute("compatibleDimensions");
            result.AdUnit = (string)element.Attribute("adUnit");
            result.CustomId = (string)element.Attribute("customId");
            result.Source = (string)element.Attribute("source");
            result.MaxSlotDuration = TimeSpan.FromSeconds(element.GetIntAttribute("maxSlotDuration"));

            var timePositionXml = (string)element.Attribute("timePosition");
            if (timePositionXml != null) result.TimePosition = TimeSpan.FromSeconds(float.Parse(timePositionXml));
            result.TimePositionSequence = element.GetIntAttribute("timePositionSequence");
            result.TimePositionClass = (string)element.Attribute("timePositionClass");

            var adsXml = element.Element("selectedAds");
            if (adsXml != null)
            {
                foreach (var adReferenceXml in adsXml.Elements("adReference"))
                {
                    result.SelectedAds.Add(LoadAdReference(adReferenceXml));
                }
            }

            var eventCallbacksXml = element.Element("eventCallbacks");
            if (eventCallbacksXml != null)
            {
                foreach (var eventCallbackXml in eventCallbacksXml.Elements("eventCallback"))
                {
                    result.EventCallbacks.Add(LoadEventCallback(eventCallbackXml));
                }
            }

            var parametersXml = element.Element("parameters");
            if (parametersXml != null)
            {
                foreach (var parameterXml in parametersXml.Elements("parameter"))
                {
                    result.Parameters.Add(LoadParameter(parameterXml));
                }
            }

            return result;
        }