private void ServerTimer_Tick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(ViewModel.SelectedVpnFriendlyName) &&
                !string.IsNullOrEmpty(ViewModel.VpnUsername) &&
                !string.IsNullOrEmpty(ViewModel.VpnPassword))
            {
                try
                {
                    RasEntry entry = new RasEntry()
                    {
                        FriendlyName = ViewModel.SelectedVpnFriendlyName,
                        UserName     = ViewModel.VpnUsername,
                        Password     = ViewModel.VpnPassword
                    };
                    RequestStatus result = _client.CheckRequestStatus();
                    if (result.RequestVpnStatus)
                    {
                        if (!entry.Connected)
                        {
                            if (entry.Connect())
                            {
                                if (!result.RemoteServerConnected)
                                {
                                    _client.SetRemoteServerStatus("1");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (entry.Connected)
                        {
                            if (entry.Disconnect())
                            {
                                if (result.RemoteServerConnected)
                                {
                                    _client.SetRemoteServerStatus("0");
                                }
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (!string.IsNullOrEmpty(ViewModel.CameraSource) && !string.IsNullOrEmpty(ViewModel.PushUrl))
            {
                try
                {
                    RequestStatus result = _client.CheckRequestStatus();
                    if (result.RequestIPCamera)
                    {
                        if (!_streamer.IsStarted)
                        {
                            RtmpConfig rtmpConfig = new RtmpConfig()
                            {
                                Width     = ViewModel.Width,
                                Height    = ViewModel.Height,
                                FrameRate = ViewModel.FPS
                            };
                            _streamer = new BitmapStreamer
                            {
                                PushUrl = ViewModel.PushUrl,
                                Config  = rtmpConfig
                            };
                            _streamer.StartPush();
                            VideoCapture capture    = new VideoCapture(ViewModel.CameraSource);
                            Stopwatch    fpsStopper = new Stopwatch();
                            _streamCts = new CancellationTokenSource();
                            Task.Run(async() =>
                            {
                                while (!_streamCts.IsCancellationRequested)
                                {
                                    try
                                    {
                                        fpsStopper.Restart();
                                        using (Image <Bgr, byte> frame = CaptureBGR(capture))
                                        {
                                            _streamer.AddImage(frame.Bitmap);
                                        }

                                        int elapsedMilliseconds = (int)fpsStopper.ElapsedMilliseconds;
                                        if (elapsedMilliseconds < (1000 / ViewModel.FPS))
                                        {
                                            await Task.Delay((1000 / ViewModel.FPS) - elapsedMilliseconds);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                capture.Dispose();
                            });
                        }
                    }
                    else
                    {
                        if (_streamer.IsStarted)
                        {
                            _streamCts.Cancel();
                            _streamer.Stop();
                        }
                    }
                }
                catch
                {
                }
            }
        }
        private async void RequestVpn_OnOrOff_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(ViewModel.SelectedVpnFriendlyName) ||
                string.IsNullOrEmpty(ViewModel.VpnUsername) ||
                string.IsNullOrEmpty(ViewModel.VpnPassword))
            {
                taskbarIcon.ShowBalloonTip("Error", "Missing VPN configuration", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Error);
                return;
            }

            if (_requestInProgress)
            {
                return;
            }

            Client client        = new Client(ViewModel.Host, ViewModel.Username, ViewModel.Password);
            string mode          = ((MenuItem)sender).CommandParameter as string;
            bool   requestResult = false;
            string title         = "";
            string message       = "";
            string warning       = "";

            switch (mode.ToUpper())
            {
            case "ON":
                title         = "Connected";
                message       = "VPN network initialized";
                warning       = "VPN network initialized but unable to connect to {0} VPN on this pc";
                requestResult = client.RequestVpnOn();
                break;

            case "OFF":
                title         = "Disconnected";
                message       = "VPN network closed";
                warning       = "VPN network closed but unable to disconnect from {0} VPN on this pc";
                requestResult = client.RequestVpnOff();
                break;
            }

            if (requestResult)
            {
                _requestInProgress = true;
                taskbarIcon.ShowBalloonTip("Request sent", "Request has been sent to server", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
                if (await client.CheckRequestStatusContinuouslyAsync(mode))
                {
                    RasEntry entry = new RasEntry()
                    {
                        FriendlyName = ViewModel.SelectedVpnFriendlyName,
                        UserName     = ViewModel.VpnUsername,
                        Password     = ViewModel.VpnPassword
                    };
                    bool vpnResult = false;
                    switch (mode.ToUpper())
                    {
                    case "ON":
                        vpnResult = entry.Connect();
                        break;

                    case "OFF":
                        vpnResult = entry.Disconnect();
                        break;
                    }
                    if (vpnResult)
                    {
                        taskbarIcon.ShowBalloonTip(title, message, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
                    }
                    else
                    {
                        taskbarIcon.ShowBalloonTip("Warning", string.Format(warning, ViewModel.SelectedVpnFriendlyName), Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Warning);
                    }
                    _requestInProgress = false;
                }
                else
                {
                    _requestInProgress = false;
                    taskbarIcon.ShowBalloonTip("Error", client.LastError, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Error);
                }
            }
            else
            {
                _requestInProgress = false;
                taskbarIcon.ShowBalloonTip("Error", client.LastError, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Error);
            }
        }