예제 #1
0
        public void TestConnections()
        {
            var p          = new PasswordAuthProvider(new Uri("http://localhost:9001/"));
            var adminToken = p.Login(new PasswordAuthRequest <PasswordAuthData>()
            {
                RequestData = new PasswordAuthData()
                {
                    Password = "******", Usename = "admin"
                }
            }).Result;

            var connectionsList = new PasswordOAuthContext[10000];

            for (int conn = 0; conn < 10000; conn++)
            {
                try
                {
                    var registerRes = Register(adminToken, conn).Result;
                }
                catch (Exception ex)
                {
                    Debug.Write(ex.Message);
                }

                connectionsList[conn] = PostAuth(conn).Result;
            }
            Array.ForEach(new[] { 1, 10, 100, 1000, 10000 }, connectionsNumber =>
            {
                Debug.WriteLine("Connections number: {0}", connectionsNumber);

                var sw = Stopwatch.StartNew();
                for (int i = 0; i < connectionsNumber; i++)
                {
                    var x = GetData(connectionsList[i]).Result;
                }
                Debug.WriteLine("Single: {0}", sw.Elapsed);
                Debug.WriteLine("");
            });

            Array.ForEach(new[] { 1, 10, 100, 1000, 10000 }, connectionsNumber =>
            {
                Debug.WriteLine("Connections number: {0}", connectionsNumber);
                var sw = Stopwatch.StartNew();
                List <Task> taskList = new List <Task>();
                for (var i = 0; i < connectionsNumber; ++i)
                {
                    taskList.Add(GetData(connectionsList[i]));
                }
                Task.WhenAll(taskList);
                Debug.WriteLine("Parallel: {0}", sw.Elapsed);
                Debug.WriteLine("");
            });
        }
예제 #2
0
        private async static Task <PasswordOAuthContext> PostAuth(int index)
        {
            var p = new PasswordAuthProvider(new Uri("http://localhost:9001/"));

            return(await p.Login(new PasswordAuthRequest <PasswordAuthData>()
            {
                RequestData = new PasswordAuthData()
                {
                    Password = "******", Usename = "userok" + index
                }
            }));
        }
예제 #3
0
        public static async Task <Tuple <PasswordOAuthContext, string> > UserLogin(string[] serversList, int port, string userName, string password)
        {
            var serverInfoUrl = GetApiServerUri(serversList, userName, port);

            var p   = new PasswordAuthProvider(serverInfoUrl);
            var res = await p.Login(new PasswordAuthRequest <PasswordAuthData>()
            {
                RequestData = new PasswordAuthData()
                {
                    Password = password, Usename = userName
                }
            });

            return(new Tuple <PasswordOAuthContext, string>(res, userName));
        }
예제 #4
0
        public Task <Tuple <PerformanceCounter, ClientConnectionInfo> > Login(string login, string password)
        {
            var serverUri = GetApiServerUri(_serviceUriList, login);
            var p         = new PasswordAuthProvider(serverUri, _logger);

            return(DoPerformanceMeasureAction(async() =>
            {
                var token = await p.Login(new PasswordAuthRequest <PasswordAuthData>()
                {
                    RequestData = new PasswordAuthData()
                    {
                        Password = password, Usename = login
                    }
                });
                return new ClientConnectionInfo {
                    Login = login, Context = token
                };
            }, serverUri.ToString()));
        }