Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            appStatus.isServerOnline = AppStatus.CheckForServerConnection();
            appStatus.isOnline       = AppStatus.CheckForInternetConnection();


            mainGrid.Visibility      = Visibility.Hidden;
            filesListGrid.Visibility = Visibility.Hidden;
            newFileGrid.Visibility   = Visibility.Hidden;

            if (appStatus.isServerOnline == true && appStatus.isOnline == true)
            {
                loginBtn.Visibility   = Visibility.Visible;
                passBox.IsEnabled     = true;
                loginBox.IsEnabled    = true;
                workOffBtn.Visibility = Visibility.Hidden;
            }
            else
            {
                loginBtn.Visibility   = Visibility.Hidden;
                passBox.IsEnabled     = false;
                loginBox.IsEnabled    = false;
                workOffBtn.Visibility = Visibility.Visible;
            }

            LoginGrid.Visibility   = Visibility.Visible;
            welcomeGrid.Visibility = Visibility.Hidden;
        }
Esempio n. 2
0
        private void loginBtn_Click(object sender, RoutedEventArgs e)
        {
            appStatus.isServerOnline = AppStatus.CheckForServerConnection();
            appStatus.isOnline       = AppStatus.CheckForInternetConnection();
            filesListGrid.Visibility = Visibility.Hidden;

            login    = loginBox.Text;
            password = passBox.Password.ToString();
            if (login.Count() > 0 && password.Count() > 0)
            {
                user = new User(login, password, "desktop");
                user.Get2();
                //user.GetUsersList();

                if (user.user_exists == true && user.logged_in)
                {
                    appStatus.isUserLogged   = true;
                    AppStatus.userID         = user.user_id;
                    MenuGrid.Visibility      = Visibility.Hidden;
                    loginMenuGrid.Visibility = Visibility.Visible;
                    LoginGrid.Visibility     = Visibility.Hidden;
                    welcomeGrid.Visibility   = Visibility.Visible;
                    welcomeLabel.Content     = $"Logged in as \n{user.user_login}";
                    chatBtn.Visibility       = Visibility.Visible;

                    Documents documents = new Documents();
                    documents.Get2(true);
                    listOfFiles.ItemsSource = new DirectoryInfo(path).GetFiles();

                    loginBttn.Visibility = Visibility.Hidden;
                    logoutBtn.Visibility = Visibility.Visible;

                    loggedUser      = user.user_id;
                    lockedFilesList = user.list_of_locked_files;
                    //Console.WriteLine("Locked file: {0}, {1}", lockedFilesList[0].file_id, lockedFilesList[0].file_name);

                    socket = IO.Socket(adresIP.adres);

                    newSocket.isSocketConnected(socket, user.user_id);
                    newSocket.socketIoManager(socket, login);
                    newSocket.chatGetMsg(socket, login);

                    toggleSwitch.IsChecked = false;
                    toggleSwitch.IsEnabled = true;
                }
                else
                {
                    appStatus.isUserLogged = false;
                    MessageBox.Show("Wrong Credentials");
                }

                loginBox.Clear();
                passBox.Clear();
            }
        }
Esempio n. 3
0
        private void saveBtn_Click(object sender, RoutedEventArgs e)
        {
            appStatus.isServerOnline = AppStatus.CheckForServerConnection();
            appStatus.isOnline       = AppStatus.CheckForInternetConnection();

            if (appStatus.isUserLogged == true)
            {
                loginBttn.Visibility = Visibility.Hidden;
                logoutBtn.Visibility = Visibility.Visible;
                chatBtn.Visibility   = Visibility.Visible;
            }
            else
            {
                loginBttn.Visibility = Visibility.Visible;
                logoutBtn.Visibility = Visibility.Hidden;
                chatBtn.Visibility   = Visibility.Hidden;
            }

            if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == true)
            {
                Documents documents = new Documents();
                documents.Get2(true);
            }

            String title               = TitleBox.Text;
            String content             = contentBox.Text;
            string filenameNoExtension = title;
            string filename            = String.Format("{0}.txt", title);
            string allPath             = System.IO.Path.Combine(path, filename);

            if (!File.Exists(allPath))
            {
                if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == true)
                {
                    Document document = new Document(filenameNoExtension, content, DateTime.Now, DateTime.Now, 1, user.user_id);
                    if (document.checkIfNoDuplicated())
                    {
                        document.PostDocument(document);
                        newSocket.socketIoEmit(TitleBox.Text, 2, login, socket, user.user_id, 0);
                        MessageBox.Show("File has been saved");
                    }
                    else
                    {
                        MessageBox.Show("File name exsist!");
                    }
                }
                else if (appStatus.isServerOnline == true && appStatus.isOnline == true &&
                         appStatus.isUserLogged == false)
                {
                    using (StreamWriter str = File.CreateText(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();
                        MessageBox.Show("Login to sync document!");
                        Button_Click(sender, e);
                    }
                }
                else if ((appStatus.isServerOnline == false || appStatus.isOnline == false) &&
                         appStatus.isUserLogged == true)
                {
                    appStatus.isUserLogged = false;
                    using (StreamWriter str = File.CreateText(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();
                        MessageBox.Show("You`ve lost connection! Document will be saved locally");
                        //Button_Click(sender, e);
                    }
                    if (appStatus.isUserLogged == true)
                    {
                        loginBttn.Visibility = Visibility.Hidden;
                        logoutBtn.Visibility = Visibility.Visible;
                        chatBtn.Visibility   = Visibility.Visible;
                    }
                    else
                    {
                        loginBttn.Visibility = Visibility.Visible;
                        logoutBtn.Visibility = Visibility.Hidden;
                        chatBtn.Visibility   = Visibility.Hidden;
                    }
                }
                else
                {
                    using (StreamWriter str = File.CreateText(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();
                        MessageBox.Show("File has been saved");
                    }
                }
            }
            else if (File.Exists(allPath))
            {
                if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == true)
                {
                    Document exsistingDoc = Documents.currentDocuments
                                            .Where(a => a.file_name == Path.GetFileNameWithoutExtension(allPath))
                                            .FirstOrDefault();
                    exsistingDoc.file_content = content;
                    //temporary hardcode ;c
                    exsistingDoc.user_id = user.user_id;
                    var localWriteTime =
                        File.GetLastWriteTime(Path.Combine(Documents.path, exsistingDoc.file_name + ".txt"));
                    if (localWriteTime < exsistingDoc.file_update_date)
                    {
                        using (StreamWriter str =
                                   File.CreateText(Path.Combine(Documents.path, exsistingDoc.file_name + "_local.txt")))
                        {
                            str.WriteLine(content);
                            str.Flush();
                            MessageBox.Show($"{exsistingDoc.file_name}_local file has been created locally");
                        }
                    }
                    else
                    {
                        exsistingDoc.is_online_file = true;
                        exsistingDoc.CallUpdateDoc();
                        newSocket.socketIoEmit(TitleBox.Text, 3, login, socket, user.user_id, idPickedDoc);
                        MessageBox.Show("File has been updated!");
                    }
                }
                else if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == false)
                {
                    using (var str = new StreamWriter(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();
                        MessageBox.Show("Login to sync document!");
                        Button_Click(sender, e);
                    }
                }
                else if ((appStatus.isServerOnline == false || appStatus.isOnline == false) &&
                         appStatus.isUserLogged == true)
                {
                    appStatus.isUserLogged = false;
                    using (var str = new StreamWriter(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();
                        MessageBox.Show("You`ve lost connection! Document will be saved locally");
                        Button_Click(sender, e);
                    }
                    if (appStatus.isUserLogged == true)
                    {
                        loginBttn.Visibility = Visibility.Hidden;
                        logoutBtn.Visibility = Visibility.Visible;
                        chatBtn.Visibility   = Visibility.Visible;
                    }
                    else
                    {
                        loginBttn.Visibility = Visibility.Visible;
                        logoutBtn.Visibility = Visibility.Hidden;
                        chatBtn.Visibility   = Visibility.Hidden;
                    }
                }
                else
                {
                    using (var str = new StreamWriter(allPath))
                    {
                        str.WriteLine(content);
                        str.Flush();

                        MessageBox.Show("File has been overwritten");
                    }
                }
            }

            try
            {
                if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == true)
                {
                    Documents documents = new Documents();
                    documents.Get2(true);
                }
            }
            catch (Exception es)
            {
                Console.WriteLine(es);
            }

            listOfFiles.ItemsSource = null;
            listOfFiles.ItemsSource = new DirectoryInfo(path).GetFiles();

            if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged == true)
            {
                TitleBox.IsReadOnly    = true;
                contentBox.IsReadOnly  = true;
                toggleSwitch.IsChecked = false;
                toggleSwitch.IsEnabled = true;
                saveBtn.IsEnabled      = false;
            }
            else
            {
                TitleBox.IsReadOnly    = false;
                contentBox.IsReadOnly  = false;
                toggleSwitch.IsChecked = true;
                toggleSwitch.IsEnabled = false;
                saveBtn.IsEnabled      = true;
            }
        }
Esempio n. 4
0
        private void Row_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            appStatus.isServerOnline = AppStatus.CheckForServerConnection();
            appStatus.isOnline       = AppStatus.CheckForInternetConnection();

            try
            {
                String title = listOfFiles.SelectedItems[0].ToString();
                string text  = System.IO.File.ReadAllText(System.IO.Path.Combine(path, title));


                foreach (Document doc in Documents.currentDocuments)
                {
                    if (doc.file_name.Equals(title.Substring(0, title.Length - 4)))
                    {
                        idPickedDoc = doc.file_id;
                        //Console.WriteLine("Id wybranego dokumnetu: {0}", idPickedDoc);
                    }
                }
                TitleBox.Text   = title.Substring(0, title.Length - 4);
                contentBox.Text = text;
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee);
            }

            filesListGrid.Visibility = Visibility.Hidden;
            newFileGrid.Visibility   = Visibility.Visible;

            string lockedOnList = null;

            if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged)
            {
                try
                {
                    foreach (sUser s in lockedFilesList)
                    {
                        if (s.file_name.Equals(TitleBox.Text) && s.file_id.Equals(idPickedDoc) && !s.file_name.Equals(newSocket.unlockedFile))
                        {
                            toggleSwitch.IsChecked = false;
                            toggleSwitch.IsEnabled = false;
                            TitleBox.IsReadOnly    = true;
                            contentBox.IsReadOnly  = true;
                            saveBtn.IsEnabled      = false;
                            Console.WriteLine("Warunek 1");
                            lockedOnList = s.file_name;
                        }
                        else if (!s.file_name.Equals(TitleBox.Text))
                        {
                            toggleSwitch.IsChecked = false;
                            toggleSwitch.IsEnabled = true;
                            TitleBox.IsReadOnly    = true;
                            contentBox.IsReadOnly  = true;
                            saveBtn.IsEnabled      = false;
                            Console.WriteLine("Warunek 2");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                if (TitleBox.Text.Equals(newSocket.lockedFile) /* && !TitleBox.Text.Equals(newSocket.unlockedFile)*/)
                {
                    toggleSwitch.IsChecked = false;
                    toggleSwitch.IsEnabled = false;
                    Console.WriteLine("Warunek 3");
                }
                else if (lockedFilesList == null)
                {
                    toggleSwitch.IsEnabled = true;
                    Console.WriteLine("Warunek 4");
                }

                else if (!TitleBox.Text.Equals(newSocket.lockedFile) && !TitleBox.Text.Equals(lockedOnList))
                {
                    toggleSwitch.IsChecked = false;
                    toggleSwitch.IsEnabled = true;
                    Console.WriteLine("Warunek 3a");
                }

                if (TitleBox.Text.Equals(newSocket.unlockedFile) /*&& !TitleBox.Text.Equals(newSocket.lockedFile)*/)
                {
                    toggleSwitch.IsEnabled = true;
                    Console.WriteLine("Warunek 5");
                }
            }
            else               //offline
            {
                String title = listOfFiles.SelectedItems[0].ToString();
                string text  = System.IO.File.ReadAllText(System.IO.Path.Combine(path, title));

                TitleBox.Text   = title.Substring(0, title.Length - 4);
                contentBox.Text = text;

                toggleSwitch.IsChecked = true;
                toggleSwitch.IsEnabled = false;
                saveBtn.IsEnabled      = true;
                Console.WriteLine("Warunek 6");
            }

            //if (appStatus.isServerOnline == true && appStatus.isOnline == true && appStatus.isUserLogged)
            //{
            //	if (toggleSwitch.IsChecked == true && !newSocket.lockedFile.Equals(TitleBox.Text))
            //	{
            //		TitleBox.IsReadOnly = false;
            //		contentBox.IsReadOnly = false;
            //		saveBtn.IsEnabled = true;
            //		toggleSwitch.IsEnabled = true;
            //		Console.WriteLine("Warunek 7");
            //	}
            //	else if (toggleSwitch.IsChecked == false && newSocket.lockedFile != null && TitleBox.Text.Equals(newSocket.lockedFile))
            //	{
            //		TitleBox.IsReadOnly = true;
            //		contentBox.IsReadOnly = true;
            //		saveBtn.IsEnabled = false;
            //		toggleSwitch.IsEnabled = false;
            //		Console.WriteLine("Warunek 8");
            //	}

            //	if(!TitleBox.Text.Equals(newSocket.lockedFile) )
            //	{
            //		TitleBox.IsReadOnly = true;
            //		contentBox.IsReadOnly = true;
            //		saveBtn.IsEnabled = false;
            //		toggleSwitch.IsEnabled = true;
            //		Console.WriteLine("Warunek 9");
            //	}
            //}

            if (appStatus.isServerOnline == false || appStatus.isOnline == false)             //offline
            {
                TitleBox.IsReadOnly    = false;
                contentBox.IsReadOnly  = false;
                toggleSwitch.IsChecked = true;
                toggleSwitch.IsEnabled = false;
                saveBtn.IsEnabled      = true;
            }
        }