Пример #1
0
        private void TryAccessServer(Dictionary <string, object> connectionSettings, Action onSuccess)
        {
            imgInfo.Visibility = System.Windows.Visibility.Visible;

            this.IsEnabled = false;

            if (DialogActionType == ActionType.Add)
            {
                if (_config.Servers.Any(x => x.Name == Result.Server.Name))
                {
                    lbInfo.Content = "Server Connection already exists with same Name " + Result.Server.Name;
                }
            }

            Result.Server.Name                = tbName.RetrieveValue <string>();
            Result.Server.ServiceBus          = cbServiceBus.SelectedValue as string;
            Result.Server.ServiceBusQueueType = cbTransport.SelectedValue as string;

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (s, e) => {
                try {
                    Result.AllQueueNames = _discoverySvc.GetAllAvailableQueueNames(e.Argument as Dictionary <string, object>);

                    e.Result = true;
                } catch {
                    e.Result = false;
                }
            };

            worker.RunWorkerCompleted += (s, e) => {
                if (!((bool)e.Result)) // failed
                {
                    lbInfo.Content = "Could not access server";
                }
                else
                {
                    onSuccess();
                }

                imgInfo.Visibility = System.Windows.Visibility.Hidden;

                this.IsEnabled = true;
            };

            worker.RunWorkerAsync(connectionSettings);
        }