Example #1
0
        public async Task <Response <SocketClientTest> > ConnectAndLogin(string user, string pws)
        {
            var tcs = new TaskCompletionSource <Response <SocketClientTest> >();

            try
            {
                SocketClientTest test = new SocketClientTest(user, pws);
                test.Connect();
                // mockSend.SetSocketClient()
                test.OnLoginSuccess += (a, b) =>
                {
                    Console.WriteLine("data ok={0}", a);
                    string m = "test me...";
                    test.SendData(Encoding.ASCII.GetBytes(m));
                    tcs.SetResult(new Response <SocketClientTest> {
                        IsError = false, Result = test
                    });
                };
                test.OnLoginFailed += (a) =>
                {
                    Console.WriteLine("data error={0}", a);
                    tcs.SetResult(new Response <SocketClientTest> {
                        IsError = true, Message = a
                    });
                };
                test.Login(true);
            }
            catch (Exception ee)
            {
                tcs.SetException(ee);
            }

            return(await tcs.Task);
        }
Example #2
0
        public async Task <ResponseAppMessanger> SetSocketClient(SignUpSender sender, bool canExcute = true)
        {
            ResponseAppMessanger response = new ResponseAppMessanger();

            response.Result = this;
            if (_test != null)
            {
                return(response);
            }

            var authenticationManager = GetAuthenticationManager();
            var token = await authenticationManager.GetToken(sender);

            if (token == null)
            {
                response.IsAutorize = false;
                response.IsError    = false;
            }
            else
            {
                response.IsAutorize = true;
                SenderMessagesFactory sendFactory = new SenderMessagesFactory(this.Context);
                var respndFactory = await sendFactory.ConnectAndLogin(sender.UserId, token.Token);

                if (respndFactory.IsError)
                {
                    response.IsAutorize = true;
                    response.IsError    = true;
                    response.Message    = respndFactory.Message;
                }
                else
                {
                    _test = respndFactory.Result;
                }
            }
            return(response);
        }