void next(ServerName result)
 {
     if (result != null)
         System.Diagnostics.Debug.WriteLine(result.servername);
     else
         System.Diagnostics.Debug.WriteLine("Unable to connect to server");
 }
        private void createMeetingCallback(ServerName output)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                if (output == null || output.servername == null)
                {
                    MessageBox.Show("Couldn't connect to server");

                    setControlEnabled(true);
                }
                else if (output.servername != server.serverName)
                {
                    MessageBox.Show("Server with this address has different name than the chosen server name");

                    setControlEnabled(true);
                }
                else
                {
                    string url = server.address + "/api/meeting/new";
                    NewMeetingInput newMeetingInput = new NewMeetingInput();
                    newMeetingInput.login = server.login;
                    newMeetingInput.sid = server.sid;
                    newMeetingInput.title = titleBox.Text;
                    newMeetingInput.topic = topicBox.Text;
                    newMeetingInput.abilityToSendFiles = (bool)tglSwitch.IsChecked ? "true" : "false";//Convert.ToString(tglSwitch.IsChecked);
                    new HttpPostRequest<NewMeetingInput, MeetingOutput>(url, createMeetingCallback, newMeetingInput);
                }
            });
        }
        private void joinMeetingCallback(ServerName result)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                if (result == null)
                {
                    MessageBox.Show("Couldn't connect to server");
                    _timer.Start();
                }
                else if (result.servername == null)
                {
                    MessageBox.Show("Incorrect server response, please contact with administrator or try again later.");
                    _timer.Start();
                }
                else
                {
                    server.name = result.servername;
                    var servers = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == result.servername select s);
                    if (servers.Count() > 0)
                    {

                        server = servers[0];
                        if (server.sid == null)
                        {
                            MessageBoxResult messageResult =
                                MessageBox.Show("You are not logged in on server. Would you like to log in?",
                                "", MessageBoxButton.OKCancel);

                            if (messageResult == MessageBoxResult.OK)
                            {
                                string url = server.address + "/api/account/login";
                                LoginInput input = new LoginInput(server.login, server.pass);
                                new HttpPostRequest<LoginInput, LoginOutput>(url, loginCallback, input);
                            }
                            else
                            {
                                _timer.Start();
                                text = "";
                            }
                        }
                        else
                        {
                            joinMeeting();
                        }
                    }
                    else
                    {
                        //TODO go to registration page instead telling a user to do it
                        MessageBox.Show("You are not logged in on server. Please register or log in to server.");
                        NavigationService.Navigate(new Uri("/Pages/AddServerPage.xaml?serverAddress=" + server.address + "&serverName=" + server.name, UriKind.Relative));
                    }
                }
            });
        }
        private void connectCallback(ServerName result)
        {
            this.Dispatcher.BeginInvoke(delegate()
                {
                    serverAddressBox.IsEnabled = true;
                    connectButton.IsEnabled = true;
                    connectProgressBar.Visibility = System.Windows.Visibility.Collapsed;
                    if (result == null)
                    {
                        connectedPanel.Visibility = System.Windows.Visibility.Collapsed;
                        MessageBox.Show("Couldn't connect to server");
                    }
                    else if (result.servername == null)
                    {
                        connectedPanel.Visibility = System.Windows.Visibility.Collapsed;
                        MessageBox.Show("Incorrect server response, please contact with administrator or try again later.");
                    }
                    else
                    {
                        serverNameBox.Text = result.servername;
                        var servers = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == serverNameBox.Text select s);
                        if (servers.Count() > 0)
                        {
                            Server server = servers[0];
                            if (server.address == serverAddressBox.Text)
                                MessageBox.Show("You already have account on this server. \n If you want to change to another one, please remove server from application. " +
                            "All data on the device will be lost. Data on the server will remain unchanged.");
                            else
                            {
                                server.address = serverAddressBox.Text;
                                MDEDB.SubmitChanges();
                                MessageBox.Show("You already have account on this server, under other address. Address in application had been automatically changed. \n If you want to change to another account, please remove server from application. " +
                            "All data on the device will be lost. Data on the server will remain unchanged.");
                            }
                            connectedPanel.Visibility = System.Windows.Visibility.Collapsed;
                        }
                        else
                        {
                            connectedPanel.Visibility = System.Windows.Visibility.Visible;
                        }
                    }

                });
        }
        private void loginCallback(ServerName output)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                if (output == null || output.servername == null)
                {
                    MessageBox.Show("Couldn't connect to server");
                }
                else if (output.servername != server.serverName)
                {
                    MessageBox.Show("Server with this address has different name than the chosen server name");

                }
                else
                {
                    string url = server.address + "/api/account/login";
                    LoginInput input = new LoginInput(server.login, server.pass);
                    new HttpPostRequest<LoginInput, LoginOutput>(url, loginCallback, input);
                }
            });
        }
        private void connectCallback(ServerName result)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                changeAddressBox.IsEnabled = true;
                ChangeAddress2.IsEnabled = true;
                connectProgressBar.Visibility = System.Windows.Visibility.Collapsed;
                if (result == null)
                {
                    MessageBox.Show("Couldn't connect to server");
                }
                else if (result.servername == null)
                {
                    MessageBox.Show("Incorrect server response, please contact with administrator or try again later.");
                }
                else
                {
                    if (result.servername != server.serverName)
                        MessageBox.Show("Server with this address is other than chosen one. Please add it as new serwer.");
                    else
                    {
                        MessageBox.Show("Server address changed.");
                        server.address = changeAddressBox.Text;
                        MDEDB.SubmitChanges();
                        Popup.IsOpen = false;
                        ContentPanel.Visibility = System.Windows.Visibility.Visible;
                    }

                }

            });
        }