private void ApplicationBarIconButtonSave_Click(object sender, EventArgs e)
        {
            Uri tempUri;

            if (String.IsNullOrEmpty(ServiceUrl.Text) || String.IsNullOrEmpty(Username.Text) || String.IsNullOrEmpty(Password.Password) || !Uri.TryCreate(ServiceUrl.Text, UriKind.Absolute, out tempUri))
            {
                MessageBox.Show("Some data is missing. Verify all inputs.");
                return;
            }

            ShowProgress();

            Settings.CachedAuthenticationToken = null;

            AuthenticationServiceClient authenticationService =
                new AuthenticationServiceClient(
                    GetBinding(),
                    new EndpointAddress(String.Format(CultureInfo.InvariantCulture, "{0}/Authentication/basic", ServiceUrl.Text)));

            authenticationService.AuthenticateCompleted +=
                (o1, e1) =>
            {
                if (e1.Error != null)
                {
                    HideProgress();

                    MessageBox.Show(e1.Error.Message);
                }
                else
                {
                    Settings.CachedAuthenticationToken = e1.Result.AuthenticationToken;

                    Dictionary <string, string> endpoints = new Dictionary <string, string>();
                    foreach (var ae in e1.Result.AvailableEndpoints)
                    {
                        endpoints.Add(ae.Name, ae.BasicUrl);
                    }
                    Settings.Endpoints = endpoints;

                    Settings.ServiceUrl = ServiceUrl.Text;
                    Settings.Username   = Username.Text;
                    Settings.Password   = Password.Password;

                    Settings.Save();

                    HideProgress();

                    NavigationService.GoBack();
                }
            };

            authenticationService.AuthenticateAsync(Username.Text, Password.Password);
        }
Example #2
0
        protected void GetAuthenticationToken(Action del)
        {
            AuthenticationServiceClient authenticationService =
                new AuthenticationServiceClient(
                    GetBinding(),
                    new EndpointAddress(String.Format(CultureInfo.InvariantCulture, "{0}/Authentication/basic", Settings.ServiceUrl)));

            authenticationService.AuthenticateCompleted +=
                (o1, e1) =>
            {
                if (e1.Error != null)
                {
                    // TODO:
                    MessageBox.Show(e1.Error.Message);
                }
                else
                {
                    Settings.CachedAuthenticationToken = e1.Result.AuthenticationToken;

                    Dictionary <string, string> endpoints = new Dictionary <string, string>();
                    foreach (var ae in e1.Result.AvailableEndpoints)
                    {
                        endpoints.Add(ae.Name, ae.BasicUrl);
                    }
                    Settings.Endpoints = endpoints;

                    Settings.Save();

                    if (del != null)
                    {
                        del();
                    }
                }
            };

            authenticationService.AuthenticateAsync(Settings.Username, Settings.Password);
        }
Example #3
0
 private void Login()
 {
     _service.AuthenticateAsync(txtUsername.Text, txtPassword.Password);
     btnLogin.IsEnabled = false;
 }