Exemplo n.º 1
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //Inizialize Authentication api (Authentication api not require authentication token)
                var authApi = new IO.Swagger.Api.AuthenticationApi(ApiUrl);
                //Login to obtain a valid token (and a refresh token)
                var reqdto = new AuthenticationTokenRequestDTO(
                    textBoxUsername.Text, // Username
                    textBoxPassword.Text, // Password
                    AppName,              // Application name
                    AppSecret);           // Application secret
                AuthenticationTokenDTO resultToken = authApi.AuthenticationGetToken(reqdto);

                _authToken    = resultToken.AccessToken;
                _refreshToken = resultToken.RefreshToken;

                MessageBox.Show("Succes login!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        private Task TaskWebApi()
        {
            var task = new Task(() =>
            {
                DispatcherHelper.UIDispatcher.Invoke(() => IsBusy = true);

                var listTaskTest = new List <Task>();

                DispatcherHelper.UIDispatcher.BeginInvoke((Action)(() => { _logger.Info("Execute login test"); }));


                try
                {
                    var authApi = new IO.Swagger.Api.AuthenticationApi(Url);

                    var tokenRequestDto = new AuthenticationTokenRequestDTO(Username, Password, CLIENTID, CLIENTSECRET, null, null, null, null, null, null, null);
                    var tokenResponse   = authApi.AuthenticationGetToken(tokenRequestDto);

                    var configuration = new IO.Swagger.Client.Configuration()
                    {
                        ApiKey = new Dictionary <string, string>()
                        {
                            { "Authorization", tokenResponse.AccessToken }
                        },
                        ApiKeyPrefix = new Dictionary <string, string>()
                        {
                            { "Authorization", "Bearer" }
                        },
                        BasePath = Url
                    };

                    for (int i = 0; i < ThreadCount; i++)
                    {
                        DispatcherHelper.UIDispatcher.BeginInvoke((Action)(() => { _logger.Info(string.Format(" - Create procedure connection {0} of {1}", (i + 1), ThreadCount)); }));

                        var taskClient = new Task(() => TestProcedureApi(configuration, string.Format("Thread{0}", i + 1)), TaskCreationOptions.LongRunning);

                        taskClient.Start();
                        listTaskTest.Add(taskClient);

                        Thread.Sleep(1000);
                    }

                    listTaskTest.ForEach(x => x.Wait());

                    DispatcherHelper.UIDispatcher.BeginInvoke((Action)(() =>
                    {
                        _logger.Info(string.Format("REPORT\r\nMASK\r\n{0}\r\nSTORE\r\n{1}\r\nSEARCH\r\n{2}\r\nF2\r\n{3}\r\nCycle\r\n{4}",
                                                   TimeCalculator.EvaluateTime(_timeMask.ToArray()).ToString(),
                                                   TimeCalculator.EvaluateTime(_timeStore.ToArray()).ToString(),
                                                   TimeCalculator.EvaluateTime(_timeSearch.ToArray()).ToString(),
                                                   TimeCalculator.EvaluateTime(_timeF2.ToArray()).ToString(),
                                                   TimeCalculator.EvaluateTime(_timeTestProcedure.ToArray()).ToString()
                                                   ));
                    }));

                    MessageBox.Show("Test procedure completed", "Execute completed", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                catch (Exception exception)
                {
                    DispatcherHelper.UIDispatcher.BeginInvoke((Action)(() =>
                    {
                        _logger.Error(exception.Message);
                    }));

                    MessageBox.Show(exception.Message, "Execute error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                finally
                {
                    DispatcherHelper.UIDispatcher.Invoke(() => IsBusy = false);
                }
            }
                                );

            return(task);
        }