コード例 #1
0
        /// <summary>
        /// Opens the specified URI.
        /// The command is processed in a Thread Pool Thread.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The awaitable Open operation</returns>
        public DispatcherOperation Open(Uri uri)
        {
            // Check Uri Argument
            if (uri == null)
            {
                MediaElement?.Logger.Log(
                    MediaLogMessageType.Warning,
                    $"{nameof(MediaCommandManager)}.{nameof(Open)}: '{nameof(uri)}' cannot be null");

                return(Dispatcher.CurrentDispatcher.CreatePumpOperation());
            }

            if (CanExecuteCommands == false)
            {
                return(Dispatcher.CurrentDispatcher.CreatePumpOperation());
            }
            else
            {
                IsOpening.Value = true;
            }

            var command = new OpenCommand(this, uri);

            ExecutingCommand = command;
            ClearCommandQueue();

            var backgroundTask = Task.Run(() =>
            {
                try
                {
                    if (command.HasCompleted)
                    {
                        return;
                    }
                    command.Execute();
                }
                catch (Exception ex)
                {
                    MediaElement?.Logger.Log(
                        MediaLogMessageType.Error,
                        $"{nameof(MediaCommandManager)}.{nameof(Open)}: {ex.GetType()} - {ex.Message}");
                }
                finally
                {
                    ExecutingCommand?.Complete();
                    ExecutingCommand = null;
                    IsOpening.Value  = false;
                }

                System.Diagnostics.Debug.Assert(
                    MediaElement.IsOpen == true && MediaElement.IsOpening == false && command.HasCompleted,
                    "Synchronous conditions not met");
            });

            var operation = Dispatcher.CurrentDispatcher.CreateAsynchronousPumpWaiter(backgroundTask);

            return(operation);
        }
コード例 #2
0
        /// <summary>
        /// Opens the specified URI.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns></returns>
        public async Task Open(Uri uri)
        {
            lock (SyncLock)
            {
                Commands.Clear();
            }

            var command = new OpenCommand(this, uri);
            await command.ExecuteAsync();
        }
コード例 #3
0
        /// <summary>
        /// Opens the specified URI.
        /// This command gets processed in a threadpool thread asynchronously.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The asynchronous task</returns>
        public async Task OpenAsync(Uri uri)
        {
            // Check Uri Argument
            if (uri == null)
            {
                MediaCore?.Log(
                    MediaLogMessageType.Warning,
                    $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: '{nameof(uri)}' cannot be null");

                return; // Task.CompletedTask;
            }

            if (CanExecuteCommands == false)
            {
                return; // Task.CompletedTask;
            }
            else
            {
                IsOpening.Value = true;
            }

            var command = new OpenCommand(this, uri);

            ExecutingCommand = command;
            ClearCommandQueue();

            var action = new Action(() =>
            {
                try
                {
                    if (command.HasCompleted)
                    {
                        return;
                    }
                    command.RunSynchronously();
                }
                catch (Exception ex)
                {
                    MediaCore?.Log(
                        MediaLogMessageType.Error,
                        $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: {ex.GetType()} - {ex.Message}");
                }
                finally
                {
                    ExecutingCommand?.Complete();
                    ExecutingCommand = null;
                    IsOpening.Value  = false;
                }
            });

            await TaskEx.Run(action);
        }
コード例 #4
0
        /// <summary>
        /// Opens the specified URI.
        /// The command is processed in a Thread Pool Thread.
        /// </summary>
        /// <param name="uri">The URI.</param>
        public void Open(Uri uri)
        {
            lock (SyncLock)
            {
                Commands.Clear();
            }

            // Process the command in a background thread as opposed
            // to in the thread that it was called to prevent blocking.
            var command = new OpenCommand(this, uri);

            ExecuteAndWaitFor(command);

            // Debug.Assert(MediaElement.IsOpen == true && MediaElement.IsOpening == false && command.HasCompleted, "Synchronous conditions");
        }
コード例 #5
0
        /// <summary>
        /// Opens the specified URI.
        /// The command is processed in a Thread Pool Thread.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The awaitable task</returns>
        public async Task Open(Uri uri)
        {
            lock (SyncLock)
            {
                Commands.Clear();
            }

            // Process the command in a background thread as opposed
            // to in the thread that it was called to prevent blocking.
            await Task.Run(async() =>
            {
                var command = new OpenCommand(this, uri);
                await command.ExecuteAsync();
            });
        }
コード例 #6
0
        /// <summary>
        /// Opens the specified custom input stream.
        /// This command gets processed in a threadpool thread asynchronously.
        /// </summary>
        /// <param name="stream">The custom input stream.</param>
        /// <returns>
        /// The asynchronous task
        /// </returns>
        public async Task OpenAsync(IMediaInputStream stream)
        {
            // Check Uri Argument
            if (stream == null)
            {
                MediaCore?.Log(
                    MediaLogMessageType.Warning,
                    $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: '{nameof(stream)}' cannot be null");

                return;
            }

            if (CanExecuteCommands == false)
            {
                return;
            }
            else
            {
                IsOpening.Value = true;
            }

            var command = new OpenCommand(this, stream);

            ExecutingCommand = command;
            ClearCommandQueue();

            try
            {
                if (command.HasCompleted)
                {
                    return;
                }

                await command.StartAsync();
            }
            catch (Exception ex)
            {
                MediaCore?.Log(
                    MediaLogMessageType.Error,
                    $"{nameof(MediaCommandManager)}.{nameof(OpenAsync)}: {ex.GetType()} - {ex.Message}");
            }
            finally
            {
                ExecutingCommand?.Complete();
                ExecutingCommand = null;
                IsOpening.Value  = false;
            }
        }