Esempio n. 1
0
        static HandShakeKeeper Create(string token)
        {
            var instance = new HandShakeKeeper();

            instance.Token = token;

            instance.HandShakeTask = Task.Run(async() =>
            {
                var handShake = new EvoApiRequester <
                    evoapi.ProtocolModels.HandShake.HandShake.Request,
                    Response>();

                while (true)
                {
                    var res = await handShake.PostAsync($"{token}");

                    if (res.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        break;
                    }
                    if (res.Payload.pushCode == "Close")
                    {
                        break;
                    }
                    if (instance.Cancelled)
                    {
                        break;
                    }
                }
            });

            instance.LogoutTask = Task.Run(async() =>
            {
                var logout = new EvoApiRequester <
                    evoapi.ProtocolModels.Auth.Logout.Request,
                    evoapi.ProtocolModels.Auth.Logout.Response>();

                while (true)
                {
                    if (instance.Cancelled)
                    {
                        var res = await logout.PostAsync($"{token}");
                        break;
                    }

                    await Task.Delay(1000);
                }
            });

            return(instance);
        }
Esempio n. 2
0
        public static async Task <HandShakeKeeper> CreateAsync(string account, string password,
                                                               string authToken = "", evolib.Account.Type accountType = evolib.Account.Type.Dev1)
        {
            var login = new EvoApiRequester <
                evoapi.ProtocolModels.Auth.Login.Request,
                evoapi.ProtocolModels.Auth.Login.Response>();

            login.request.account        = account;
            login.request.password       = password;
            login.request.authToken      = authToken;
            login.request.accountType    = accountType;
            login.request.packageVersion = new int[] { 99, };
            var resLogin = await login.PostAsync();

            if (resLogin.StatusCode != System.Net.HttpStatusCode.OK ||
                string.IsNullOrEmpty(resLogin.Payload.token))
            {
                return(null);
            }

            return(Create(resLogin.Payload.token));
        }