Esempio n. 1
0
        //#
        //[TestMethod()]
        //public void AccessTokenTest()
        //{
        //    var completion = new ManualResetEvent(false);
        //    var repOfaccessToken = new WebexApiEventArgs<string>();

        //    var auth = new JWTAuthenticator();
        //    Assert.IsTrue(LoginWithTryTimes(auth, 5));

        //    auth.AccessToken(r =>
        //    {
        //        repOfaccessToken = r;
        //        completion.Set();
        //    });
        //    if (!completion.WaitOne(30000))
        //    {
        //        Assert.Fail();
        //        return;
        //    }

        //    Assert.IsTrue(repOfaccessToken.IsSuccess);
        //    Assert.IsNotNull(repOfaccessToken.Data);
        //    Assert.IsNull(repOfaccessToken.Error);

        //    Assert.IsTrue(Logout(auth));

        //    Thread.Sleep(30000);
        //}

        //[TestMethod()]
        //public void AccessTokenTestUnexpirAccessToken()
        //{
        //    var completion = new ManualResetEvent(false);
        //    var repOfaccessToken = new WebexApiEventArgs<string>();

        //    var auth = new JWTAuthenticator();
        //    Assert.IsTrue(LoginWithTryTimes(auth, 5));

        //    auth.AccessToken(r =>
        //    {
        //        repOfaccessToken = r;
        //        completion.Set();
        //    });
        //    if (!completion.WaitOne(30000))
        //    {
        //        Assert.Fail();
        //        return;
        //    }

        //    Assert.IsTrue(repOfaccessToken.IsSuccess);
        //    Assert.IsNotNull(repOfaccessToken.Data);
        //    Assert.IsNull(repOfaccessToken.Error);


        //    //get unexpired access token, it is the same of last one.
        //    completion.Reset();

        //    var newAccessToken = new WebexApiEventArgs<string>();
        //    auth.AccessToken(r =>
        //    {
        //        newAccessToken = r;
        //        completion.Set();
        //    });
        //    if (!completion.WaitOne(30000))
        //    {
        //        Assert.Fail();
        //        return;
        //    }

        //    Assert.IsTrue(newAccessToken.IsSuccess);
        //    Assert.AreEqual(repOfaccessToken.Data, newAccessToken.Data);

        //    Assert.IsTrue(Logout(auth));
        //    Thread.Sleep(30000);
        //}

        //[TestMethod()]
        //public void LoginLogoutManytimes()
        //{
        //    var auth = new JWTAuthenticator();
        //    int count = 3;
        //    while (count > 0)
        //    {
        //        count--;
        //        Console.WriteLine($"loginLogoutManytimes[{count}]");
        //        Assert.IsTrue(loginWithTryTimes(auth, 10));
        //        logout(auth);
        //    }
        //}

        private bool CheckAuthorized(JWTAuthenticator auth)
        {
            var completion = new ManualResetEvent(false);
            var response   = new WebexApiEventArgs();

            auth.Authorized(r =>
            {
                response = r;
                completion.Set();
            });

            if (!completion.WaitOne(30000))
            {
                Assert.Fail();
                return(false);
            }
            return(response.IsSuccess);
        }
        void TryToLoginByJWT()
        {
            this.IsBusy = true;
            var auth         = new JWTAuthenticator();
            var sparkManager = new SparkManager(auth);

            ApplicationController.Instance.CurSparkManager = sparkManager;
            auth.Authorized(r =>
            {
                this.IsBusy = false;
                if (r.IsSuccess)
                {
                    ApplicationController.Instance.ChangeState(State.Main);
                }
                else
                {
                    ApplicationController.Instance.ChangeState(State.LoginByJWT);
                }
            });
        }
        void TryToLoginByJWT()
        {
            this.IsBusy = true;
            var auth         = new JWTAuthenticator();
            var sparkManager = new SparkManager(auth);

            ApplicationController.Instance.CurSparkManager = sparkManager;
            sparkManager.CurSpark.Logger = ApplicationController.Instance.ShellViewModel;
            ApplicationController.Instance.AppLogOutput("check if authorized");
            auth.Authorized(r =>
            {
                this.IsBusy = false;
                if (r.IsSuccess)
                {
                    ApplicationController.Instance.AppLogOutput("authorize success!");
                    ApplicationController.Instance.ChangeState(State.Main);
                }
                else
                {
                    ApplicationController.Instance.ChangeState(State.LoginByJWT);
                }
            });
        }