Example #1
0
        /// <summary> Sends the commands from queue. All commands will be combined until either
        ///            the SendBufferMaxLength  has been reached or if a command requires an acknowledge
        ///            </summary>
        private void SendCommandsFromQueue()
        {
            _commandCount = 0;
            _sendBuffer   = "";
            CommandStrategy eventCommandStrategy = null;

            while (_sendBuffer.Length < _sendBufferMaxLength && Queue.Count != 0)          // while maximum buffer string is not reached, and command in queue, AND
            {
                lock (Queue)
                {
                    var commandStrategy = Queue.Count != 0 ? Queue.Peek() : null;
                    if (commandStrategy != null)
                    {
                        if (commandStrategy.Command != null)
                        {
                            var sendCommand = (SendCommand)commandStrategy.Command;

                            if (sendCommand.ReqAc)
                            {
                                if (_commandCount > 0)
                                {
                                    break;
                                }
                                SendSingleCommandFromQueue(commandStrategy);
                            }
                            else
                            {
                                eventCommandStrategy = commandStrategy;
                                AddToCommandsString(commandStrategy);
                            }
                        }
                    }
                }
                // event callback outside lock for performance
                if (eventCommandStrategy != null)
                {
                    if (NewLineSent != null)
                    {
                        NewLineSent(this, new NewLineEvent.NewLineArgs(eventCommandStrategy.Command));
                    }
                    eventCommandStrategy = null;
                }
            }

            // Now check if a command string has been filled
            if (_sendBuffer.Length > 0)
            {
                _sender.ExecuteSendString(_sendBuffer, SendQueue.InFrontQueue);
            }
        }
Example #2
0
 /// <summary> Sends a float command from the queue. </summary>
 /// <param name="commandStrategy"> The command strategy to send. </param>
 private void SendSingleCommandFromQueue(CommandStrategy commandStrategy)
 {
     // Dequeue
     lock (Queue)
     {
         commandStrategy.DeQueue();
         // Process all generic dequeue strategies
         foreach (var generalStrategy in GeneralStrategies)
         {
             generalStrategy.OnDequeue();
         }
     }
     // Send command
     if (commandStrategy != null && commandStrategy.Command != null)
     {
         _sender.ExecuteSendCommand((SendCommand)commandStrategy.Command, SendQueue.InFrontQueue);
     }
 }
Example #3
0
        /// <summary> Queue the send command wrapped in a command strategy. </summary>
        /// <param name="commandStrategy"> The command strategy. </param>
        public override void QueueCommand(CommandStrategy commandStrategy)
        {
            while (Queue.Count > MaxQueueLength)
            {
                Thread.Yield();
            }
            lock (Queue)
            {
                // Process commandStrategy enqueue associated with command
                commandStrategy.CommandQueue   = Queue;
                commandStrategy.ThreadRunState = ThreadRunState;

                commandStrategy.Enqueue();

                // Process all generic enqueue strategies
                foreach (var generalStrategy in GeneralStrategies)
                {
                    generalStrategy.OnEnqueue();
                }
            }
        }
Example #4
0
 /// <summary> Adds a commandStrategy to the commands string.  </summary>
 /// <param name="commandStrategy"> The command strategy to add. </param>
 private void AddToCommandsString(CommandStrategy commandStrategy)
 {
     // Dequeue
     lock (Queue)
     {
         commandStrategy.DeQueue();
         // Process all generic dequeue strategies
         foreach (var generalStrategy in GeneralStrategies)
         {
             generalStrategy.OnDequeue();
         }
     }
     // Add command
     if (commandStrategy != null && commandStrategy.Command != null)
     {
         _commandCount++;
         _sendBuffer += commandStrategy.Command.CommandString();
         if (Command.PrintLfCr)
         {
             _sendBuffer += Environment.NewLine;
         }
     }
 }
Example #5
0
 /// <summary> Queue the command wrapped in a command strategy. </summary>
 /// <param name="commandStrategy"> The command strategy. </param>
 public virtual void QueueCommand(CommandStrategy commandStrategy)
 {
 }
Example #6
0
 /// <summary> Queue the command wrapped in a command strategy. </summary>
 /// <param name="commandStrategy"> The command strategy. </param>
 public virtual void QueueCommand(CommandStrategy commandStrategy)
 {
 }
Example #7
0
 /// <summary> Put  a command wrapped in a strategy at the back of the sent queue.</summary>
 /// <param name="commandStrategy"> The command strategy. </param>
 public void QueueCommand(CommandStrategy commandStrategy)
 {
     _sendCommandQueue.QueueCommand(commandStrategy);
 }
Example #8
0
 /// <summary> Put  a command wrapped in a strategy at the back of the sent queue.</summary>
 /// <param name="commandStrategy"> The command strategy. </param>
 public void QueueCommand(CommandStrategy commandStrategy)
 {
     _sendCommandQueue.QueueCommand(commandStrategy);
 }
Example #9
0
        /// <summary> Queue the send command wrapped in a command strategy. </summary>
        /// <param name="commandStrategy"> The command strategy. </param>
        public override void QueueCommand(CommandStrategy commandStrategy)
        {
            while (Queue.Count > MaxQueueLength)
            {
                Thread.Yield();
            }
            lock (Queue)
            {
                // Process commandStrategy enqueue associated with command
                commandStrategy.CommandQueue = Queue;
                commandStrategy.ThreadRunState = ThreadRunState;

                commandStrategy.Enqueue();

                // Process all generic enqueue strategies
                foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnEnqueue(); }
            }
        }
Example #10
0
 /// <summary> Sends a float command from the queue. </summary>
 /// <param name="commandStrategy"> The command strategy to send. </param>
 private void SendSingleCommandFromQueue(CommandStrategy commandStrategy)
 {
     // Dequeue
     lock (Queue)
     {
         commandStrategy.DeQueue();
         // Process all generic dequeue strategies
         foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnDequeue(); }
     }
     // Send command
     if (commandStrategy != null && commandStrategy.Command != null)
         _sender.ExecuteSendCommand((SendCommand)commandStrategy.Command, SendQueue.InFrontQueue);
 }
Example #11
0
 /// <summary> Adds a commandStrategy to the commands string.  </summary>
 /// <param name="commandStrategy"> The command strategy to add. </param>
 private void AddToCommandsString(CommandStrategy commandStrategy)
 {
     // Dequeue
     lock (Queue)
     {
         commandStrategy.DeQueue();
         // Process all generic dequeue strategies
         foreach (var generalStrategy in GeneralStrategies) { generalStrategy.OnDequeue(); }
     }
     // Add command
     if (commandStrategy != null && commandStrategy.Command != null) {
             _commandCount++;
             _sendBuffer += commandStrategy.Command.CommandString();
             if (Command.PrintLfCr) { _sendBuffer +=  Environment.NewLine; }
     }
 }