public void SendCommand(QuotationCommand quotationCommand = null, Command command = null)
        {
            if (_ClientsProcessor.IsEmpty())
            {
                return;
            }
            var target = new CommandForClient(quotationCommand: quotationCommand, command: command);

            _CommandTransfer.Send(target);
        }
Example #2
0
 public void Send(CommandForClient command)
 {
     if (this._IsClosed)
     {
         return;
     }
     lock (this._QueueLock)
     {
         this._Queue.Enqueue(command);
         if (!_IsSendingData)
         {
             this._IsSendingData = true;
             Write();
         }
     }
 }
Example #3
0
        private void WriteForQuotation()
        {
            Token       token;
            TraderState state = SessionManager.Default.GetTokenAndState(this._Id, out token);

            if (state == null || token == null)
            {
                Write();
                return;
            }
            this._QuotationQueue.Clear();
            this._QuotationQueue.Add(this._CurrentCommand.Quotation.QuotationCommand);
            while (this._Queue.Count > 0)
            {
                CommandForClient item = this._Queue.Peek();
                if (item.CommandType != DataType.Quotation)
                {
                    break;
                }
                item = this._Queue.Dequeue();
                this._QuotationQueue.Add(item.Quotation.QuotationCommand);
            }
            byte[] content;
            if (this._QuotationQueue.Count == 1)
            {
                content = this._CurrentCommand.Quotation.GetPriceInBytes(token, state);
            }
            else
            {
                QuotationCommand command = new QuotationCommand();
                command.Merge(this._QuotationQueue);
                content = QuotationTranslator.GetPriceInBytes(token, state, command, this._QuotationQueue[0].Sequence, this._QuotationQueue[this._QuotationQueue.Count - 1].Sequence);
            }
            if (content == null)
            {
                Write();
                return;
            }
            this._CurrentPacket = SerializeManager.Default.SerializePrice(content);
            this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length);
        }
Example #4
0
 private void Write()
 {
     try
     {
         lock (this._QueueLock)
         {
             if (this._Queue.Count == 0)
             {
                 this._IsSendingData = false;
                 return;
             }
             this._CurrentCommand = this._Queue.Dequeue();
             if (this._CurrentCommand.CommandType == DataType.Command)
             {
                 WriteForCommand();
             }
             else if (this._CurrentCommand.CommandType == DataType.Response)
             {
                 this._CurrentPacket = this._CurrentCommand.Data;
                 this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length);
             }
             else if (this._CurrentCommand.CommandType == DataType.Quotation)
             {
                 WriteForQuotation();
             }
             else
             {
                 throw new ArgumentException(string.Format("Unrecognize DataType:{0}", this._CurrentCommand.CommandType));
             }
         }
     }
     catch (Exception ex)
     {
         _Logger.Error("Write", ex);
         this.Close();
     }
 }
Example #5
0
 public void Send(CommandForClient command)
 {
     _Commands.Enqueue(command);
     _SendQuotationEvent.Set();
 }