Esempio n. 1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            UserSessionService userSessionService = UserSessionService.GetInstance();

            if (!isLogedIn_)
            {
                if (!short.TryParse(textBox3.Text, out short port))
                {
                    port          = 9000;
                    textBox3.Text = "" + port;
                }

                try {
                    button1.Enabled = false;
                    await userSessionService.LoginAsync(new NvrSessionInfo()
                    {
                        IPAddress    = textBox4.Text,
                        PortNumber   = port,
                        UserName     = textBox1.Text,
                        UserPassword = textBox2.Text
                    });
                } catch (Exception ex) {
                    appendLogOnUiThread(null, $"{ex.Message}\n\n");
                    return;
                } finally {
                    button1.Enabled = true;
                }

                comboBox1.Items.Clear();
                userSessionService.CameraChannels.ForEach(chan => comboBox1.Items.Add(chan));
                comboBox1.SelectedIndex = userSessionService.CameraSelectedChannel;

                isLogedIn_           = true;
                button1.Text         = "Logout";
                previewPanel.Enabled = isLogedIn_;
                updateAppConfiguration("NvrIp", textBox4.Text);
                updateAppConfiguration("NvrPort", textBox3.Text);
                updateAppConfiguration("NvrUserName", textBox1.Text);
                updateAppConfiguration("NvrUserPassword", textBox2.Text);
            }
            else
            {
                button1.Enabled = false;

                {
                    if (isPreviewRunning_)
                    {
                        await stopLiveViewAsync();
                    }

                    userSessionService.Logout();
                    isLogedIn_           = false;
                    button1.Text         = "Login";
                    previewPanel.Enabled = isLogedIn_;
                }

                button1.Enabled = true;
            }
        }