/// <summary> /// Send outgoing message and raise <see cref="MessageAdapter.NewOutMessage"/> event. /// </summary> /// <param name="message">Message.</param> public virtual void SendOutMessage(Message message) { InitMessageLocalTime(message); if (message.IsBack && message.Adapter == null) { message.Adapter = this; } if (_prevTime != DateTimeOffset.MinValue) { var diff = message.LocalTime - _prevTime; _secLookupTimeOut .ProcessTime(diff) .ForEach(id => SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = id })); _pfLookupTimeOut .ProcessTime(diff) .ForEach(id => SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = id })); } _prevTime = message.LocalTime; NewOutMessage?.Invoke(message); }
public void Open() { _messageQueue.Open(); ThreadingHelper .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() => { while (!_messageQueue.IsClosed) { try { var sended = _historyMessageAdapter.SendOutMessage(); var processed = false; while (_messageQueue.TryDequeue(out var message, true, false)) { NewOutMessage?.Invoke(message); processed = true; } if (!sended && !processed && !_messageQueue.IsClosed) { Thread.Sleep(100); } } catch (Exception ex) { _errorHandler(ex); } } })) .Name("History emulation channel thread.") .Launch(); }
public void Open() { _messageQueue.Open(); ThreadingHelper .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() => { while (!_messageQueue.IsClosed) { try { var sended = _historyMessageAdapter.SendOutMessage(); Message message; if (!_messageQueue.TryDequeue(out message, true, !sended)) { if (!sended) { break; } } else { NewOutMessage?.Invoke(message); } } catch (Exception ex) { _errorHandler(ex); } } })) .Name("History emulation channel thread.") .Launch(); }
/// <summary> /// Open channel. /// </summary> public void Open() { _messageQueue.Open(); ThreadingHelper .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() => { while (!_messageQueue.IsClosed) { try { Message message; if (!_messageQueue.TryDequeue(out message)) { break; } //if (!(message is TimeMessage) && message.GetType().Name != "BasketMessage") // Console.WriteLine("<< ({0}) {1}", System.Threading.Thread.CurrentThread.Name, message); _msgStat.Remove(message); NewOutMessage?.Invoke(message); } catch (Exception ex) { _errorHandler(ex); } } Closed?.Invoke(); })) .Name($"{Name} channel thread.") //.Culture(CultureInfo.InvariantCulture) .Launch(); }
/// <summary> /// To call the event <see cref="NewOutMessage"/>. /// </summary> /// <param name="message">The message.</param> protected void RaiseNewOutMessage(Message message) { NewOutMessage?.Invoke(message); }