public void TestIsNotKnownInAny() {
            var state = new AsynchronousCommandStateModel();

            var commandModel = new AsynchronousCommandModel() {
                Command = new Command()
            };

            Assert.IsFalse(state.IsKnown(commandModel.Command.CommandGuid));
        }
        public void TestIsKnownInExecuted() {
            var state = new AsynchronousCommandStateModel();

            var commandModel = new AsynchronousCommandModel() {
                Command = new Command()
            };

            state.ExecutedCommandsPool.TryAdd(commandModel.Command.CommandGuid, commandModel);

            Assert.IsTrue(state.IsKnown(commandModel.Command.CommandGuid));
        }
        public void TestIsKnownInPending() {
            var state = new AsynchronousCommandStateModel();

            var commandModel = new AsynchronousCommandModel() {
                Command = new Command()
            };

            state.PendingCommandsQueue.Enqueue(commandModel);

            Assert.IsTrue(state.IsKnown(commandModel.Command.CommandGuid));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Long running loop to process commands when signaled that a new command(s) has been
        /// added to the queue.
        /// </summary>
        public virtual void ExecuteQueuedCommands() {
            while (this.AsyncStateModel.TaskQueueWaitCancellationTokenSource.IsCancellationRequested == false) {

                // Wait until we are poked that something has been added to the queue.
                this.AsyncStateModel.TaskQueueWait.WaitOne();

                // Dequeue and process a new command.
                AsynchronousCommandModel asynchronousCommand = null;

                if (this.AsyncStateModel.PendingCommandsQueue.TryDequeue(out asynchronousCommand) == true) {
                    // Add it so we can look for a reference when it comes back.
                    this.AsyncStateModel.ExecutedCommandsPool.TryAdd(asynchronousCommand.Command.CommandGuid, asynchronousCommand);

                    Task.Factory.StartNew(() => {
                        if (asynchronousCommand.IsTunneling == true) {
                            base.Tunnel(asynchronousCommand.Command);
                        }
                        else {
                            base.Bubble(asynchronousCommand.Command);
                        }
                    });
                }
            }

            // Cleanup
            this.AsyncStateModel.TaskQueueWaitCancellationTokenSource.Dispose();
            this.AsyncStateModel.TaskQueueWait.Dispose();

            this.AsyncStateModel.ExecutedCommandsPool.Clear();

            this.AsyncStateModel = null;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes the controller with the default values
 /// </summary>
 protected AsynchronousCoreController() : base() {
     this.AsyncStateModel = new AsynchronousCommandStateModel();
 }