Exemplo n.º 1
0
        public Task ConnectAsync(CancellationToken cancellationToken)
        {
            if (!(State == FixConnectorState.Disconnected || State == FixConnectorState.NotConnected))
            {
                throw new InvalidOperationException($"Unable to connect. Current state {State}");
            }
            _connectionCompletionSource = new TaskCompletionSource <bool>();
            SubscribeOnCancelEvent(_connectionCompletionSource, cancellationToken);

            _log.WriteInfoAsync(nameof(ConnectAsync), string.Join("/n", _config.FixConfig), "Starting fix connection with configuration").GetAwaiter().GetResult();
            _socketInitiator.Start();
            _log.WriteInfoAsync(nameof(ConnectAsync), string.Empty, "Fix connection started").GetAwaiter().GetResult();
            return(_connectionCompletionSource.Task);
        }
 public void ToAdmin(Message message, SessionID sessionId)
 {
     if (message is Logon logon)
     {
         logon.Password = new Password(_config.Password);
         State          = FixConnectorState.Connecting;
     }
     else if (message is Logout logout)
     {
         State = FixConnectorState.Disconnecting;
         if (logout.IsSetText())
         {
             Log.WriteInfoAsync(nameof(Logout), string.Empty, logout.Text.Obj).GetAwaiter().GetResult();;
         }
     }
 }