bool FadeToBlack()
        {
            if (ActiveHandler == null)
            {
                return(false);
            }

            _logger.Log("Fading to black");

            ActiveHandler.ToBlack();
            return(true);
        }
        bool FadeFromBlack()
        {
            if (ActiveHandler == null)
            {
                return(false);
            }

            _logger.Log("Fading from black");

            ActiveHandler.FromBlack();
            return(true);
        }
        bool FadeToggle()
        {
            if (ActiveHandler == null)
            {
                return(false);
            }

            _logger.Log("Toggling fade");

            ActiveHandler.FromBlack();
            return(true);
        }
Esempio n. 4
0
        private void DisposeContext( )
        {
            if (!ContextHandle.Pointer.IsNull())
            {
                NativeMethods.ContextSetDiagnosticHandler(ContextHandle, IntPtr.Zero, IntPtr.Zero);
                ActiveHandler.Dispose( );

                lock ( ContextCache )
                {
                    ContextCache.Remove(ContextHandle);
                }

                NativeMethods.ContextDispose(ContextHandle);
                ContextHandle = default(LLVMContextRef);
            }
        }
        public void DoFade(FadeDirection direction, float delaySeconds = 0f)
        {
            switch (direction)
            {
            case FadeDirection.FromBlack:
                ActiveHandler?.Invoke(nameof(FadeHandler.FromBlack), delaySeconds);
                break;

            case FadeDirection.ToBlack:
                ActiveHandler?.Invoke(nameof(FadeHandler.ToBlack), delaySeconds);
                break;

            case FadeDirection.Toggle:
                ActiveHandler?.Invoke(nameof(FadeHandler.ToBlack), delaySeconds);
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Parses the streams records.
        /// </summary>
        public virtual void Parse()
        {
            while (Header.Stream.BeginRecord())
            {
                Opcodes op = Header.Stream.Opcode;

                if (GlobalHandler.Handles(op))                 // Check global handler
                {
                    if (!GlobalHandler.Handle(op))
                    {
                        break;
                    }
                }
                else if (ActiveHandler.Handles(op))                 // Try the active handler
                {
                    if (!ActiveHandler.Handle(op))
                    {
                        break;
                    }
                }
                else
                {
                    if (ActiveHandler.ThrowBackUnhandled || ActiveHandler.ThrowBacks.Contains(op))                     // Do we throw back the record to be handled by the parent?
                    {
                        //Log.Write( string.Format( "{0} throwing back - {1}", GetType().Name, op ) );
                        // Mark the record to be repeated by our parent.
                        Header.Stream.Repeat = true;
                        break;
                    }
                    else
                    {
                        // Just ignore the record.
                        Log.Write(string.Format("{0} not handled record - {1}", GetType().Name, op));
                    }
                }
            }
        }
Esempio n. 7
0
        internal async Task PlayAdAsync(IAdSource adSource, CancellationToken cancellationToken, IProgress <AdStatus> progress)
#endif
        {
            try
            {
                if (ActiveHandler != null)
                {
                    if (!await ActiveHandler.CancelAd(false))
                    {
                        throw new Exception("Ad in progress and cannot be canceled.");
                    }
                }

                DateTime startTime = DateTime.Now;

                using (var timeoutTokenSource = new CancellationTokenSource())
                {
                    if (StartTimeout.HasValue)
                    {
                        timeoutTokenSource.CancelAfter(StartTimeout.Value);
                    }
                    var timeoutToken = timeoutTokenSource.Token;
                    using (var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutToken))
                    {
                        IsAdvertising = true;
                        var adContext = activeAdContext = new object();

                        progress.Report(AdStatus.Loading);

                        try
                        {
                            ActiveHandler = AdPayloadHandlers.Where(h => h.SupportedTypes.Contains(adSource.Type)).FirstOrDefault();
                            if (ActiveHandler == null)
                            {
                                throw new ArgumentException("No suitable handler was found to play this ad", "source");
                            }

                            // resolve the source
                            if (adSource is IResolveableAdSource)
                            {
                                var resolveableAdSource = adSource as IResolveableAdSource;
                                try
                                {
#if SILVERLIGHT
                                    await resolveableAdSource.LoadPayload(cancellationTokenSource.Token);
#else
                                    await resolveableAdSource.LoadPayload().AsTask(cancellationTokenSource.Token);
#endif
                                }
                                catch (OperationCanceledException)
                                {
                                    if (timeoutToken.IsCancellationRequested)
                                    {
                                        throw new TimeoutException();
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                            }

                            TimeSpan?timeRemaining = null;
                            if (StartTimeout.HasValue)
                            {
                                var timeElapsed = DateTime.Now.Subtract(startTime);
                                timeRemaining = StartTimeout.Value.Subtract(timeElapsed);
                            }

                            //var handlerProgress = new Progress<AdStatus>();
                            //handlerProgress.ProgressChanged += (s, e) => Progress_Handle(adContext, progress, e);
                            var handlerProgress = new Progress <AdStatus>(s => Progress_Handle(adContext, progress, s));
#if SILVERLIGHT && !WINDOWS_PHONE || WINDOWS_PHONE7
                            await ActiveHandler.PlayAdAsync(adSource, timeRemaining, cancellationToken, handlerProgress);

                            await TaskEx.Yield(); // let evertyhing complete before finishing
#elif WINDOWS_PHONE
                            await ActiveHandler.PlayAdAsync(adSource, timeRemaining, cancellationToken, handlerProgress);

                            await Task.Yield(); // let evertyhing complete before finishing
#else
                            await ActiveHandler.PlayAdAsync(adSource, timeRemaining).AsTask(cancellationToken, handlerProgress);

                            await Task.Yield(); // let evertyhing complete before finishing
#endif
                            // leave the progress handler alone, it reports on secondary task which could still be running.
                        }
                        catch
                        {
                            TeardownAd();
                            progress.Report(AdStatus.Unloaded);
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (AdFailure != null)
                {
                    AdFailure(this, new AdFailureEventArgs(adSource, ex));
                }
                throw;
            }
        }