private void Run()
        {
            int count = 0;

            // We want the thread to continue running queued commands before
            // exiting so the user can close the install window without having to wait
            // for commands to complete.
            while (!_isDisposed || count > 0)
            {
                lock (_lock) {
                    while ((_commandQueue.Count == 0 && !_isDisposed) ||
                           null == _npmController ||
                           IsExecutingCommand)
                    {
                        Monitor.Wait(_lock);
                    }

                    if (_commandQueue.Count > 0)
                    {
                        _currentCommand = _commandQueue.Dequeue();
                    }
                    else
                    {
                        _currentCommand = null;
                    }
                    count = _commandQueue.Count;
                }

                if (null != _currentCommand)
                {
                    Execute(_currentCommand);
                    UpdateStatusMessageSafe();
                }
            }
        }
Example #2
0
        private void QueueCommand(QueuedNpmCommandInfo info)
        {
            if (this.commandQueue.IsAddingCompleted ||
                this.commandQueue.Contains(info) ||
                info.Equals(this.currentCommand))
            {
                return;
            }

            this.commandQueue.Add(info);
        }
        private void QueueCommand(QueuedNpmCommandInfo info)
        {
            lock (_lock) {
                if (_commandQueue.Contains(info) ||
                    info.Equals(_currentCommand))
                {
                    return;
                }
                _commandQueue.Enqueue(info);
                Monitor.PulseAll(_lock);
            }

            UpdateStatusMessageSafe();
            OnPropertyChanged("IsCancellable");
        }
Example #4
0
 private void Run()
 {
     // We want the thread to continue running queued commands before
     // exiting so the user can close the install window without having to wait
     // for commands to complete.
     while (!this.commandQueue.IsCompleted)
     {
         // The Take method will block the worker thread when there are no items left in the queue
         // and the thread will be signalled when new items are items to the queue, or the queue is
         // marked completed.
         if (this.commandQueue.TryTake(out var command, Timeout.Infinite) && command != null)
         {
             this.currentCommand = command;
             Execute(this.currentCommand);
         }
     }
 }
Example #5
0
        private async void Execute(QueuedNpmCommandInfo info)
        {
            IsExecutingCommand = true;
            INpmCommander cmdr = null;

            try {
                lock (_lock) {
                    cmdr = _npmController.CreateNpmCommander();
                    cmdr.OutputLogged     += commander_OutputLogged;
                    cmdr.ErrorLogged      += commander_ErrorLogged;
                    cmdr.ExceptionLogged  += commander_ExceptionLogged;
                    cmdr.CommandCompleted += commander_CommandCompleted;
                    _commander             = cmdr;
                }

                if (info.IsFreeformArgumentCommand)
                {
                    await cmdr.ExecuteNpmCommandAsync(info.Arguments);
                }
                else if (info.IsGlobalInstall)
                {
                    await cmdr.InstallGlobalPackageByVersionAsync(
                        info.Name,
                        info.Version);
                }
                else
                {
                    await cmdr.InstallPackageByVersionAsync(
                        info.Name,
                        info.Version,
                        info.DependencyType,
                        true);
                }
            } finally {
                lock (_lock) {
                    _commander = null;
                    if (null != cmdr)
                    {
                        cmdr.OutputLogged     -= commander_OutputLogged;
                        cmdr.ErrorLogged      -= commander_ErrorLogged;
                        cmdr.ExceptionLogged  -= commander_ExceptionLogged;
                        cmdr.CommandCompleted -= commander_CommandCompleted;
                    }
                }
            }
        }
Example #6
0
        private void Execute(QueuedNpmCommandInfo info)
        {
            // Wait on the command to complete.
            // this way we're sure there's only one command being executed,
            // since the only thread starting this commands is the worker thread
            Debug.Assert(Thread.CurrentThread == this.worker, "The worked thread should be executing the NPM commands.");

            var cmdr = this.npmController.CreateNpmCommander();

            try
            {
                cmdr.ExecuteNpmCommandAsync(info.Arguments).Wait();
            }
            catch (AggregateException e) when(e.InnerException is TaskCanceledException)
            {
                // TaskCanceledException is not un-expected,
                // and should not tear down this thread.
                // Other exceptions are handled higher up the stack.
            }
        }
Example #7
0
        private void Execute(QueuedNpmCommandInfo info)
        {
            // Wait on the command to complete.
            // this way we're sure there's only one command being executed,
            // since the only thread starting this commands is the worker thread
            Debug.Assert(Thread.CurrentThread == this.worker, "The worked thread should be executing the NPM commands.");

            var cmdr = this.npmController.CreateNpmCommander();

            cmdr.CommandStarted   += Cmdr_CommandStarted;
            cmdr.CommandCompleted += Cmdr_CommandCompleted;
            try
            {
                cmdr.ExecuteNpmCommandAsync(info.Arguments, showConsole: false).Wait();
            }
            catch (AggregateException e) when(e.InnerException is TaskCanceledException)
            {
                // TaskCanceledException is not un-expected,
                // and should not tear down this thread.
                // Other exceptions are handled higher up the stack.
            }
            finally
            {
                cmdr.CommandStarted   -= Cmdr_CommandStarted;
                cmdr.CommandCompleted -= Cmdr_CommandCompleted;
            }

            void Cmdr_CommandStarted(object sender, NpmCommandStartedEventArgs e)
            {
                this.CommandStarted?.Invoke(this, e);
            }

            void Cmdr_CommandCompleted(object sender, NpmCommandCompletedEventArgs e)
            {
                this.CommandCompleted?.Invoke(this, e);
            }
        }
Example #8
0
 public bool Equals(QueuedNpmCommandInfo other)
 {
     return(StringComparer.CurrentCulture.Equals(this.ToString(), other?.ToString()));
 }
 public bool Equals(QueuedNpmCommandInfo other) {
     return null != other && StringComparer.CurrentCulture.Compare(ToString(), other.ToString()) == 0;
 }
Example #10
0
        private void Run() {
            int count = 0;
            // We want the thread to continue running queued commands before
            // exiting so the user can close the install window without having to wait
            // for commands to complete.
            while (!_isDisposed || count > 0) {
                lock (_lock) {
                    while ((_commandQueue.Count == 0 && !_isDisposed)
                        || null == _npmController
                        || IsExecutingCommand) {
                        Monitor.Wait(_lock);
                    }

                    if (_commandQueue.Count > 0) {
                        _currentCommand = _commandQueue.Dequeue();
                    } else {
                        _currentCommand = null;
                    }
                    count = _commandQueue.Count;
                }

                if (null != _currentCommand) {
                    Execute(_currentCommand);
                    UpdateStatusMessageSafe();
                }
            }
        }
Example #11
0
        private async void Execute(QueuedNpmCommandInfo info) {
            IsExecutingCommand = true;
            INpmCommander cmdr = null;
            try {
                lock (_lock) {
                    cmdr = _npmController.CreateNpmCommander();
                    cmdr.OutputLogged += commander_OutputLogged;
                    cmdr.ErrorLogged += commander_ErrorLogged;
                    cmdr.ExceptionLogged += commander_ExceptionLogged;
                    cmdr.CommandCompleted += commander_CommandCompleted;
                    _commander = cmdr;
                }

                if (info.IsFreeformArgumentCommand) {
                    await cmdr.ExecuteNpmCommandAsync(info.Arguments);
                } else if (info.IsGlobalInstall) {
                    await cmdr.InstallGlobalPackageByVersionAsync(
                            info.Name,
                            info.Version);
                } else {
                    await cmdr.InstallPackageByVersionAsync(
                                info.Name,
                                info.Version,
                                info.DependencyType,
                                true);
                }
            } finally {
                lock (_lock) {
                    _commander = null;
                    if (null != cmdr) {
                        cmdr.OutputLogged -= commander_OutputLogged;
                        cmdr.ErrorLogged -= commander_ErrorLogged;
                        cmdr.ExceptionLogged -= commander_ExceptionLogged;
                        cmdr.CommandCompleted -= commander_CommandCompleted;
                    }
                }
            }
        }
Example #12
0
        private void QueueCommand(QueuedNpmCommandInfo info) {
            lock (_lock) {
                if (_commandQueue.Contains(info)
                    || info.Equals(_currentCommand)) {
                    return;
                }
                _commandQueue.Enqueue(info);
                Monitor.PulseAll(_lock);
            }

            UpdateStatusMessageSafe();
            OnPropertyChanged("IsCancellable");
        }
Example #13
0
 public bool Equals(QueuedNpmCommandInfo other)
 {
     return(null != other && StringComparer.CurrentCulture.Compare(ToString(), other.ToString()) == 0);
 }