コード例 #1
0
        /// <summary>
        /// Loads ads from a source URI. Note, this is called automatically if you set the source before the MediaLoading event fires and normally does not need to be called.
        /// </summary>
        /// <param name="source">The VMAP source URI</param>
        /// <param name="c">A cancellation token that allows you to cancel a pending operation</param>
        /// <returns>A task to await on.</returns>
        public async Task LoadAds(Uri source, CancellationToken c)
        {
            adBreaks.Clear();
            var cancellationToken = CancellationTokenSource.CreateLinkedTokenSource(c, cts.Token).Token;

#if SILVERLIGHT
            var vmap = await VmapFactory.LoadSource(source, cancellationToken);
#else
            var vmap = await VmapFactory.LoadSource(source).AsTask(cancellationToken);
#endif
            foreach (var adBreak in vmap.AdBreaks)
            {
                CreateAdvertisement(adBreak);
            }
        }
コード例 #2
0
        async void timer_Tick(object sender, object e)
        {
            try
            {
#if SILVERLIGHT
                var vmap = await VmapFactory.LoadSource(Source, cts.Token);
#else
                var vmap = await VmapFactory.LoadSource(Source).AsTask(cts.Token);
#endif
                // remove all ads that were not found new info
                foreach (var adBreak in adBreaks.Where(existingBreak => !vmap.AdBreaks.Any(newBreak => newBreak.BreakId == existingBreak.Value.BreakId)))
                {
                    Advertisements.Remove(adBreak.Key);
                }
                // create new ads for those that do not already exist
                foreach (var adBreak in vmap.AdBreaks.Where(newBreak => !adBreaks.Values.Any(existingBreak => existingBreak.BreakId == newBreak.BreakId)))
                {
                    CreateAdvertisement(adBreak);
                }
            }
            catch { /* ignore */ }
        }