Example #1
0
        private async void OnLoginButton(object sender, EventArgs e)
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                UserDialogs.Instance.ShowLoading();
            });
            try
            {
                string username = UsernameEntry.Text;
                string password = PasswordEntry.Text;

                sessionView = await client.CreateSessionChannelAsync(index, username, password);
            }
            catch (BadUserException p)
            {
                IsEnabled = false;
                IsVisible = false;
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });
                await DisplayAlert("Error", p.Message, "ok");

                return;
            }
            catch (NotImplementedException)
            {
                IsEnabled = false;
                IsVisible = false;
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });
                await DisplayAlert("Error", "The Endpoint is not supported!", "ok");

                return;
            }
            if (sessionView == null)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });
                IsEnabled = false;
                IsVisible = false;

                await DisplayAlert("Error", "Cannot connect to an OPC UA Server", "OK");
            }
            else
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    UserDialogs.Instance.HideLoading();
                });

                IsEnabled = false;
                IsVisible = false;

                await DisplayAlert("Info", "Session created successfully", "Ok");

                ContentPage sessionPage = new SessionPage(client, sessionView);
                sessionPage.Title = "OPC Session Services";
                await Navigation.PushAsync(sessionPage);
            }
        }
Example #2
0
        async void OnSelected(object sender, ItemTappedEventArgs e)
        {
            EndpointView selected = e.Item as EndpointView;

            int    i      = storedList.endpointList.IndexOf(selected);
            string action = null;

            try
            {
                action = await DisplayActionSheet("Select authentication mode: ", "cancel", null, "Anonymous", "Username & Password");

                if (action.Equals("Anonymous"))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        UserDialogs.Instance.ShowLoading();
                    });

                    try
                    {
                        sessionView = await Task.Run(() => client.CreateSessionChannelAsync(i));
                    }
                    catch (NotImplementedException)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UserDialogs.Instance.HideLoading();
                        });
                        await DisplayAlert("Error", "The Endpoint is not supported!", "ok");

                        return;
                    }
                    catch (UnsupportedEndpointException p)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UserDialogs.Instance.HideLoading();
                        });


                        await DisplayAlert("Error", p.Message, "ok");

                        return;
                    }
                    if (sessionView == null)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UserDialogs.Instance.HideLoading();
                        });
                        await DisplayAlert("Error", "Cannot connect to an OPC UA Server!", "OK");
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            UserDialogs.Instance.HideLoading();
                        });

                        await DisplayAlert("Info", "Session created successfully!", "Ok");

                        ContentPage sessionPage = new SessionPage(client, sessionView);
                        sessionPage.Title = "OPC Session Services";

                        await Navigation.PushAsync(sessionPage);
                    }
                }

                else if (action.Equals("Username & Password"))
                {
                    var _loginPopup = new LoginPopupPage(client, i, sessionView);

                    await Navigation.PushPopupAsync(_loginPopup);
                }
            }
            catch (NullReferenceException)
            {
            }
        }