/// <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);
        }
 void mainsail_ActivateTrigger(object sender, TriggerEventArgs e)
 {
     if (IsEnabled)
     {
         var trigger = e.Trigger;
         if (trigger.Sources.Any())
         {
             var source            = trigger.Sources.First();
             var remoteSource      = new RemoteAdSource(new Uri(source.Uri), source.Format);
             var cancellationToken = new CancellationTokenSource();
             var progress          = new Progress <AdStatus>();
             var task = MediaPlayer.PlayAd(remoteSource, progress, cancellationToken.Token);
             activeTriggers.Add(trigger, cancellationToken);
             if (capturetriggerTask)
             {
                 triggerTask = task;
             }
         }
     }
 }