protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            var serversInDB = from Server s in MDEDB.Servers
                              select s;

            string serverName = NavigationContext.QueryString["serverName"];
            System.Diagnostics.Debug.WriteLine(serverName);
            if(serverName!="")server = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == serverName select s)[0];

            if (server.sid == null)
            {
                Login.Visibility = System.Windows.Visibility.Visible;
                ChangeAddress.Visibility = System.Windows.Visibility.Visible;
                Logout.Visibility = System.Windows.Visibility.Collapsed;
                Edit.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                Login.Visibility = System.Windows.Visibility.Collapsed;
                ChangeAddress.Visibility = System.Windows.Visibility.Collapsed;
                Logout.Visibility = System.Windows.Visibility.Visible;
                Edit.Visibility = System.Windows.Visibility.Visible;
            }

            base.OnNavigatedTo(e);
        }
        public JoinMeetingPage()
        {
            InitializeComponent();

            MDEDB = new MDEDataContext();
            server = new Server();
            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(100);
            _timer.Tick += (o, arg) => ScanPreviewBuffer();
        }
        private void joinMeeting()
        {
            JoinMeetingInput input = new JoinMeetingInput();
            server = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == server.name select s)[0];
            input.login = server.login;
            input.sid = server.sid;
            input.meetingid = text.Split(';')[2];
            input.accessCode = text.Split(';')[3];

            string url = text.Split(';')[1] + "/api/meeting/adduser";
            new HttpPostRequest<JoinMeetingInput, MeetingOutput>(url, joinMeetingCallback, input);
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            // Define the query to gather all of the to-do items.
            var serversInDB = from Server s in MDEDB.Servers
                              select s;

            string serverName = NavigationContext.QueryString["serverName"];
            server = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == serverName select s)[0];
            nameBox.Text = server.name;
            mailBox.Text = server.email;
            // Call the base method.
            base.OnNavigatedTo(e);
        }
        private void registerCallback(RegistrationOutput output)
        {
            this.Dispatcher.BeginInvoke(delegate()
                {
                    if (output == null)
                    {
                        MessageBox.Show("Error communicating with server. Check your internet connection and try again.");
                        passwordBox.Password = repPasswordBox.Password = "";
                        setControlEnabled(true);
                    }
                    else if (output.status == "ok")
                    {

                        MessageBox.Show("Registerred on server.");
                        var servers = from Server s in MDEDB.Servers where s.serverName == serverNameBox.Text select s;
                        Server server;
                        if (servers.Count() > 0)
                        {
                            MessageBox.Show("Wow, you shouldn't be here, how have you done that?!");
                        }
                        else
                        {
                            server=new Server();
                            server.address = serverUrl;
                            server.serverName = serverNameBox.Text;
                            server.login = loginBox.Text;
                            server.name = nameBox.Text;
                            server.email = mailBox.Text;
                            server.pass = passwordBox.Password;
                            MDEDB.Servers.InsertOnSubmit(server);
                            MDEDB.SubmitChanges();
                            login();
                        }

                    }
                    else
                    {
                        MessageBox.Show("Unable to register on server:\n" + output.reason);
                        passwordBox.Password = repPasswordBox.Password = "";
                        setControlEnabled(true);
                    }
                });
        }
        private void loginCallback(LoginOutput output)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {
                setControlEnabled(true);
                if (output.status == "ok")
                {
                    var servers = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == serverNameBox.Text select s);
                    Server server;
                    if (servers.Count() > 0)
                    {
                        //We are here right after registration. We should only add sid.
                        server = servers[0];
                        server.sid = output.sid;
                        MDEDB.SubmitChanges();
                        NavigationService.GoBack();
                    }
                    else
                    {
                        server = new Server();
                        MDEDB.Servers.InsertOnSubmit(server);
                        server.serverName = serverNameBox.Text;
                        server.address = serverAddressBox.Text;
                        server.login = loginBox.Text;
                        server.pass = passwordBox.Password;
                        server.sid = output.sid;

                        MDEDB.SubmitChanges();

                        string url = serverUrl + "/api/account/getdata/" + loginBox.Text + "/" + output.sid;
                        new HttpGetRequest<PersonalDataOutput>(url, personalDataCallback);

                        MessageBox.Show("Logged in on server.");
                        NavigationService.GoBack();
                    }
                }
                else
                {
                    MessageBox.Show("Unable to login on server:\n" + output.reason);
                }
            });
        }
 public Meeting getEntity(Server server)
 {
     Meeting meeting = new Meeting();
     meeting.server = server;
     meeting.serverMeetingID = meetingid;
     meeting.title = title;
     meeting.topic = topic;
     meeting.adminName = hostname;
     meeting.startTime = starttime;
     meeting.endTime = endtime;
     meeting.numerOfMembers = members;
     meeting.permissions = permissions == "memberUpload" ? 1 : (permissions == "member" ? 0 : 2);
     meeting.code = accessCode;
     return meeting;
 }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            MDEDB = new MDEDataContext();
            string serverName = NavigationContext.QueryString["serverName"];

            server = new ObservableCollection<Server>(from Server s in MDEDB.Servers where s.serverName == serverName select s)[0];

            serverNameTextBox.Text = serverName;

            meetings = new ObservableCollection<Meeting>(server.meetings);
            refresh();
            _timer.Start();

            base.OnNavigatedTo(e);
        }
        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));
                    }
                }
            });
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            #region Actualising navigation stack
            bool remove = false;

            if (NavigationContext.QueryString.ContainsKey("removePrevious"))
            {
                remove = ((string)NavigationContext.QueryString["removePrevious"]).Equals(bool.TrueString);
                NavigationContext.QueryString.Remove("removePrevious");
            }

            if (remove)
            {
                NavigationService.RemoveBackEntry();
            }
            #endregion

            MDEDB = new MDEDataContext();
            int meetingID = int.Parse( NavigationContext.QueryString["meetingID"] );

            meeting = new ObservableCollection<Meeting>(from Meeting m in MDEDB.Meetings where m.ID == meetingID select m)[0];
            server = meeting.server;
            files = new ObservableCollection<File>(meeting.files);

            PivotRoot.Title = server.serverName;

            #region Details
            titleBlock.Text = meeting.title;
            topicBlock.Text = meeting.topic;
            organisatorBlock.Text = meeting.adminName;
            if (meeting.endTime == null)
            {
                timeBlock.Text = meeting.startTime;
                stateBlock.Text = "Trwa (liczba użytkowników: " + meeting.numerOfMembers + " )";
            }
            else
            {
                timeBlock.Text = meeting.startTime + " - " + meeting.endTime;
                stateBlock.Text = "Zakończone (l. użytkowników: " + meeting.numerOfMembers + " )";
            }
            //permision = 0 - member
            //1 - member upload
            //2 - admin
            if (meeting.permissions == 2)
            {
                permissionBlock.Text = "Admin";
                settingsButton.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                settingsButton.Visibility = System.Windows.Visibility.Collapsed;
                if(meeting.permissions == 1)
                    permissionBlock.Text = "Member with upload permission";
                else
                    permissionBlock.Text = "Member without upload permission";
            }
            #endregion

            refresh();
            _timer.Start();

            base.OnNavigatedTo(e);
        }