Ejemplo n.º 1
0
        public string login()
        {
            string cmd;

            Network.Client myClient = client;
            NetworkStream  ns       = myClient.CLIENT.GetStream();

            errorBox_Username.Visibility = System.Windows.Visibility.Hidden;
            errorBox_Password.Visibility = System.Windows.Visibility.Hidden;
            cmd = myClient.reciveComand(ns);

            if (cmd.Equals("+++OPEN"))
            {
                Connect.Dispatcher.Invoke(new Action(() =>
                {
                    username = usernameTxtBox.Text;
                    password = paswordTxtBox.Password;
                }), DispatcherPriority.ContextIdle);


                if (username.Equals(""))
                {
                    errorBox_Username.Visibility = System.Windows.Visibility.Visible;
                }


                if (password.Equals(""))
                {
                    errorBox_Password.Visibility = System.Windows.Visibility.Visible;
                }

                myClient.sendCommand("++LOGIN", ns);
                cmd = myClient.reciveComand(ns);
                if (cmd.Equals("+++++OK"))
                {
                    myClient.sendFileDimension(username.Length + password.Length + 1, ns);
                    cmd = myClient.reciveComand(ns);
                    if (cmd.Equals("+++++OK"))
                    {
                        string user = username + ":" + password;

                        myClient.sendData(user, ns);
                        string tmp = myClient.reciveComand(ns);

                        if (tmp.Equals("++CLOSE"))
                        {
                            myClient.close();
                            return(username);
                        }
                        else
                        {
                            errorBox.Visibility = System.Windows.Visibility.Visible;
                            myClient.close();
                            return(null);
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void RegisterButton_Click(object sender, RoutedEventArgs e)
        {
            string username = this.usernameTxtBox.Text;
            string password = this.passwordTxtBox.Password;

            errorBox_Username.Visibility = System.Windows.Visibility.Hidden;
            errorBox_Password.Visibility = System.Windows.Visibility.Hidden;

            /////////////////////////////////////////////////////////////////////
            if (username.Equals(""))
            {
                errorBox_Username.Visibility = System.Windows.Visibility.Visible;
                Errore = true;
            }


            if (password.Equals(""))
            {
                errorBox_Password.Visibility = System.Windows.Visibility.Visible;
                Errore = true;
            }


            if (Errore)
            {
                return;
            }
            ////////////////////////////////////////////////////////////////

            TcpClient tmp = new TcpClient();

            // ip e porta del server fissati
            tmp.Connect(classes.Function.checkIPAddress("172.29.146.235"), Int16.Parse("3000"));
            client = new Network.Client(tmp);
            string ccc = client.reciveComand(client.CLIENT.GetStream());

            if (ccc.Equals("+++OPEN"))
            {
                client.sendCommand("++++REG", client.CLIENT.GetStream());
                client.sendFileDimension(username.Length, client.CLIENT.GetStream());

                ccc = client.reciveComand(client.CLIENT.GetStream());
                if (ccc.Equals("+++++OK"))
                {
                    client.sendData(username, client.CLIENT.GetStream());
                }

                ccc = client.reciveComand(client.CLIENT.GetStream());
                if (ccc.Equals("+++++OK"))
                {
                    client.sendFileDimension(password.Length, client.CLIENT.GetStream());
                }

                ccc = client.reciveComand(client.CLIENT.GetStream());
                if (ccc.Equals("+++++OK"))
                {
                    client.sendData(password, client.CLIENT.GetStream());
                }
            }


            errorBox.Content    = "Registration succeed";
            errorBox.Visibility = System.Windows.Visibility.Visible;
            errorBox.Foreground = Brushes.Green;

            System.Threading.Thread.Sleep(1000);
            this.Hide();
            this.parent.Activate();
            this.parent.Show();
        }
Ejemplo n.º 3
0
        public FolderBackup(string cnt)
        {
            this.auth     = cnt;
            lstFilesFound = new List <string>();
            files         = new Dictionary <string, Utils.FileInfomation>();
            info          = new List <Utils.FileInfomation>();
            backupList    = new List <Utils.CheckBackup>();

            InitializeComponent();

            if (!Directory.Exists(backupFolder))
            {
                Directory.CreateDirectory(backupFolder);
            }

            try
            {
                // ip e porta del server fissati

                TcpClient tmp = new TcpClient();
                //TcpClient control = new TcpClient();
                _isRunning = true;
                // ip e porta del server fissati
                tmp.Connect(classes.Function.checkIPAddress("192.168.137.111"), Int16.Parse("3000"));
                //tmp.Connect(classes.Function.checkIPAddress("127.0.0.1"), Int16.Parse("3000"));
                client = new Network.Client(tmp);

                string ccc = client.reciveComand(client.CLIENT.GetStream());
                if (ccc.Equals("+++OPEN"))
                {
                    Thread th = new Thread(CheckCon);
                    th.Start(client.CLIENT);
                    clientSend("+++AUTH");
                    string cmd = client.reciveComand(client.CLIENT.GetStream());
                    Console.WriteLine(cmd);
                    if (cmd.Equals("+++++OK"))
                    {
                        client.sendFileDimension(this.auth.Length, client.CLIENT.GetStream());
                        cmd = client.reciveComand(client.CLIENT.GetStream());
                        if (cmd.Equals("+++++OK"))
                        {
                            Console.WriteLine(cmd);
                            client.sendData(this.auth, client.CLIENT.GetStream());
                        }
                    }

                    clientSend(String.Format("+++LIST"));

                    dir.Dispatcher.Invoke(new Action(() =>
                    {
                        dir.Text += "Client connected to server!\n";
                    }), DispatcherPriority.ContextIdle);

                    clientRecive();
                }
            }
            catch (SocketException e1)
            {
                MessageBox.Show("Server non ragiungibile!");
                this.client = null;
                return;
            }
            catch (FormatException e2)
            {
                MessageBox.Show("Porta errata!");
                this.client = null;
                return;
            }
            catch (InvalidOperationException e3)
            {
                MessageBox.Show("Indirizzo IP errato!");
                this.client = null;
                return;
            }
            catch (Exception e)
            {
                MessageBox.Show("Connessione col server persa!");
                return;
            }
        }