Ejemplo n.º 1
0
        private Task MessageParserToEventsAsync(string message)
        {
            Task <bool> t1 = new TaskFactory <bool>().StartNew(() =>
            {
                var userResponseObject = FIXMLManager.ParseUserResponseMessege(message);
                if (userResponseObject != null)
                {
                    UserResponseEvent?.Invoke(userResponseObject);
                    return(true);
                }
                return(false);
            });

            Task <bool> t2 = new TaskFactory <bool>().StartNew(() =>
            {
                var rejectResponseObject = FIXMLManager.ParseBusinessMessageRejectMessage(message);
                if (rejectResponseObject != null)
                {
                    BusinessMessageRejectEvent?.Invoke(rejectResponseObject);
                    return(true);
                }
                return(false);
            });

            return(Task.WhenAll <bool>(new Task <bool>[] { t1, t2 }).ContinueWith(resultList =>
            {
                if (resultList.Result.All(x => x == false))
                {
                    UnknownMessageTypeEvent?.Invoke(message);
                }
            }));
        }
Ejemplo n.º 2
0
        public void UserStatusCanBecheckedAfterLogin()
        {
            string currentID;

            //prepare config
            using (var IDGen = IdGenerator.GetIDGenerator())
            {
                currentID = IDGen.CurrentID;

                Nol3ConfigurationManager.SaveConfiguration(new Tools.Model.Nol3Configuration
                {
                    ID       = Convert.ToInt32(IDGen.ID),
                    Login    = "******",
                    Password = "******"
                });
            }
            string response;

            using (var client =
                       Nol3.SendRequestSynch(
                           new Nol3Request(
                               FIXMLManager.GenerateUserLoginRequest()
                               )))
            {
                response = Nol3.ReciveResponse(client);
            }

            using (var client =
                       Nol3.SendRequestSynch(
                           new Nol3Request(
                               FIXMLManager.GenerateUserStatusRequest()
                               )))
            {
                response = Nol3.ReciveResponse(client);
            }

            //cleanup - logout
            using (var client = Nol3.SendRequestSynch(new Nol3Request(
                                                          FIXMLManager.GenerateUserLogoutRequest()
                                                          )))
            {
            }

            var userResponseObject = FIXMLManager.ParseUserResponseMessege(response);

            Assert.That(userResponseObject, Is.TypeOf <UserResponse>());
            Assert.That(userResponseObject.Username, Is.EqualTo("BOS"));
            Assert.That(userResponseObject.UserStatus, Is.EqualTo(UserStatus.LoggedIn));
            Assert.That(userResponseObject.MarketDepth, Is.EqualTo(1));
        }
Ejemplo n.º 3
0
        public void LoginNol3()
        {
            string responseMessage;

            using (var socket = _nol3Connector.SendRequestSynch(new Nol3Request(FIXMLManager.GenerateUserLoginRequest())))
            {
                responseMessage = _nol3Connector.ReciveResponse(socket);
                MessageParserToEventsAsync(responseMessage).Wait();
            }
            if (FIXMLManager.ParseUserResponseMessege(responseMessage)
                .UserStatus == UserStatus.LoggedIn)
            {
                //TODO : probably memeory leek from Socket
                AsyncPortListener(_nol3Connector.GetAsynchClinet(),
                                  _asyncPortListenerToken);
            }
        }