Exemplo n.º 1
0
        private static void threadStartFun(string serverIP, int port, String username, String password,Form frm)
        {
            //TBD
            Program.ClientForm.addtoConsole("Starting signin thread");
            //TBD
            if(username == "" || password == "")
            {
                Program.ClientForm.addtoConsole("Error : <<Username: \"" +username + "\" and Password: \"" +password + "\" >>" );
                //Program.ClientForm.addtoConsole("Password:"******"Username and Password field cannot be empty", "DBLike Client Sign In");
                if (!Program.ClientForm.IsHandleCreated)
                {
                    Program.ClientForm.CreateHandle();
                }
                //enable service controller
                Program.ClientForm.signinfail();
                Program.ClientForm.addtoConsole("Exiting");
                Thread.CurrentThread.Abort();
            }

            MessageClasses.MsgSignIn msgobj = new MessageClasses.MsgSignIn();

            msgobj.setUsername(username);
            msgobj.setPassword(password);

            // Fill out the content in msgobj

            //call CreateMsg.createSignUpMsg(msgobj) get it in bytes form
            Message.CreateMsg msg = new Message.CreateMsg();
            String message = msg.createSignInMsg(msgobj);

            //create a socket connection. you may need to create in Conection Manager
            sender = conn.connect(serverIP, port);
            if (sender == null)
            {
                //System.Windows.Forms.MessageBox.Show("Could not connect to server.Please check if Server is Running.", "DBLike Client");
                if (!Program.ClientForm.IsHandleCreated)
                {
                    Program.ClientForm.CreateHandle();
                }
                //enable service controller
                Program.ClientForm.addtoConsole("Error : <<Unable to connect to server>> ");
                Program.ClientForm.signinfail();
                Program.ClientForm.addtoConsole("Exiting");
                Thread.CurrentThread.Abort();
            }
            //call  SocketCommunication.ReaderWriter.write(byte[] msg) to write msg on socket
            SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter();
            Program.ClientForm.addtoConsole("Writing to socket");
            rw.writetoSocket(sender, message);
            //call  SocketCommunication.ReaderWriter.read() to read response from server
            String response = rw.readfromSocket(sender);
            Program.ClientForm.addtoConsole("Reading from socket");
            //call parser and process it.....
            Message.MessageParser mp = new Message.MessageParser();
            msgobj = mp.signInParseMessage(response);
            if(!msgobj.getAck().Equals(""))
            {
                if(msgobj.getAck()=="ERRORS")
                {
                    Program.ClientForm.addtoConsole("Error : <<" + msgobj.getAddiMsg() + ">>");
                    System.Windows.Forms.MessageBox.Show("AUTHENTICATION FAILED", "User name or Password incorrect");
                    if (!Program.ClientForm.IsHandleCreated)
                    {
                        Program.ClientForm.CreateHandle();
                    }
                    //enable service controller
                    Program.ClientForm.signinfail();
                    Program.ClientForm.addtoConsole("Exiting");
                    Thread.CurrentThread.Abort();
                }
                else
                {
                    //System.Windows.Forms.MessageBox.Show(msgobj.getAck(),msgobj.getAddiMsg());\
                    //Program.ClientForm.addtoConsole("Username:"******"Hello, "+ username +"! You have successfully signed in");
                    LocalDbAccess.LocalDB file = new LocalDbAccess.LocalDB();
                    file = file.readfromfile();
                    if (file != null)
                    {
                        if (username != file.getUsername() || password != file.getPassword())
                        {

                            if (DialogResult.Yes == System.Windows.Forms.MessageBox.Show("This System is already configured for a dblike user." +
                                "Do you really want to reconfigure it for another user?", "DBLike Client", MessageBoxButtons.YesNo))
                            {

                                string path = null;
                                System.Windows.Forms.MessageBox.Show("Please select a path to download your folder from the server");
                                var t = new Thread((ThreadStart)(() =>
                                {
                                    FolderBrowserDialog folder = new FolderBrowserDialog();
                                    if (folder.ShowDialog() == DialogResult.OK)
                                    {
                                        path = folder.SelectedPath;
                                    }
                                }));
                                t.IsBackground = true;
                                t.SetApartmentState(ApartmentState.STA);
                                t.Start();
                                t.Join();
                                //write to file
                                file = new LocalDbAccess.LocalDB();
                                file.writetofile(username, password, path);

                                Program.ClientForm.addtoConsole("Wrote to Config file");
                            }
                            else
                            {
                                Program.ClientForm.signinfail();
                                Program.ClientForm.addtoConsole("Exiting");
                                Thread.CurrentThread.Abort();
                            }
                        }
                    }
                    else
                    {
                        //System.Windows.Forms.MessageBox.Show("Localdb doesnot exist.");

                        string path = null;
                        System.Windows.Forms.MessageBox.Show("Please select a path to download your folder from the server");
                        var t = new Thread((ThreadStart)(() =>
                        {
                            FolderBrowserDialog folder = new FolderBrowserDialog();
                            if (folder.ShowDialog() == DialogResult.OK)
                            {
                                path = folder.SelectedPath;
                            }
                        }));

                        t.IsBackground = true;
                        t.SetApartmentState(ApartmentState.STA);
                        t.Start();
                        t.Join();
                        //write to file
                        file = new LocalDbAccess.LocalDB();
                        file.writetofile(username, password, path);

                        Program.ClientForm.addtoConsole("Wrote to Confgi file");

                    }
                    //poll = new PollFiles();
                    if (!Program.ClientForm.IsHandleCreated)
                    {
                        Program.ClientForm.CreateHandle();
                    }
                    //enable service controller
                    Program.ClientForm.signinpass();

                    Program.ClientForm.addtoConsole("Successefully Signed in");
                    //poll.start();
                    //MessageBox.Show("Signing in done","Client");
                    Client.Program.poll.pull = true;
                    Client.Program.poll.start();
                    Program.ClientForm.addtoConsole("Polling started");
                    //Thread.Sleep(10000);

                    // initialize the file list for sign in scenario
                    Client.LocalFileSysAccess.FileListMaintain fileMaintain = new Client.LocalFileSysAccess.FileListMaintain();
                    fileMaintain.scanAllFilesAttributes();

                    //FileSysWatchDog.Run();
                    Program.folderWatcher.start();
                    Program.ClientForm.addtoConsole("File-watcher Installed");
                    //Program.ClientForm.ballon("File watcher installed");
                    Thread.CurrentThread.Abort();
                }
            }
        }
Exemplo n.º 2
0
        private static void threadStartFun(string serverIP, int port,String username, String password,string sysncpath )
        {
            Program.ClientForm.addtoConsole("Sign Up initiated");
            //TBD
            //System.Windows.Forms.MessageBox.Show("start", "SignUp Thread started");
            MessageClasses.MsgSignUp msgobj = new MessageClasses.MsgSignUp();
            msgobj.userName = username;
            msgobj.psw = password;
            // Fill out the content in msgobj

            //call CreateMsg.createSignUpMsg(msgobj) get it in bytes form
            Message.CreateMsg msg=new Message.CreateMsg();
            String message = msg.createSignUpMsg(msgobj);

            //create a socket connection. you may need to create in Conection Manager
            sender = conn.connect(serverIP, port);
            if(sender == null)
            {
                Program.ClientForm.addtoConsole("Error : <<Could not connect to server. May be Server is not Running>>");
                //System.Windows.Forms.MessageBox.Show("Could not connect to server.Please check if Server is Running.", "DBLike Client");
                Program.ClientForm.addtoConsole("Exiting");
                Program.ClientForm.signupfail();
                Thread.CurrentThread.Abort();
            }
            //call  SocketCommunication.ReaderWriter.write(byte[] msg) to write msg on socket
            SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter();
            //System.Windows.Forms.MessageBox.Show("going to write socket:"+message, "SignUp Thread started");
            Program.ClientForm.addtoConsole("Writing to socket: " + message);
            rw.writetoSocket(sender, message);

            //call  SocketCommunication.ReaderWriter.read() to read response from server
            //System.Windows.Forms.MessageBox.Show("going to read socket: " , "SignUp Thread started");
            String response=rw.readfromSocket(sender);
            Program.ClientForm.addtoConsole("Read from socket :" + response);
            //System.Windows.Forms.MessageBox.Show("read:"+ response, "SignUp Thread started");
            //call parser and process it.....
            Message.MessageParser mp = new Message.MessageParser();

            //msgobj = mp.signInParseMessage(response);
            msgobj = mp.signUpParseMessage(response);

            // This functionality should be added here

            //call parser and process it.....
            if (!msgobj.ack.Equals(""))
            {
                Message.MessageParser msgparser = new Message.MessageParser();
                if (msgobj.ack.Equals("ERRORS"))
                {
                    Program.ClientForm.addtoConsole("Error :" +"<<"+ msgobj.addiMsg +">>");
                    //System.Windows.Forms.MessageBox.Show("Some error occured!Please try again.", "Error Occured");
                    Program.ClientForm.addtoConsole("Exiting");
                    Program.ClientForm.signupfail();
                    Thread.CurrentThread.Abort();
                }
                else
                {
                    Program.ClientForm.ballon("Congratulations " + username + "! Your account is successfully created");
                    if (File.Exists(@"C:\dblikeConfig\dblike.txt"))
                    {
                        if (DialogResult.No == System.Windows.Forms.MessageBox.Show("This System is already configured for a dblike user." +
                            "Do you want to reconfigure it for yourself?", "DBLike Client", MessageBoxButtons.YesNo))
                        {
                            Program.ClientForm.addtoConsole("Exiting");
                            Program.ClientForm.signupfail();
                            Thread.CurrentThread.Abort();
                        }
                    }
                    /*
                    if (!Program.ClientForm.IsHandleCreated)
                    {
                        Program.ClientForm.CreateHandle();
                    }
                    Program.ClientForm.Appendconsole("Successefully Signed in");
                     */
                    LocalDbAccess.LocalDB file = new LocalDbAccess.LocalDB();
                    if (false == file.writetofile(username, password, sysncpath))
                    {
                        Program.ClientForm.addtoConsole("Error : <<Unable to access config file. Please try Sign In>>");
                        //System.Windows.Forms.MessageBox.Show("Unable to access dblike file. Please try Sign In.", "Error Occured");
                        Program.ClientForm.addtoConsole("Exiting");
                        Program.ClientForm.signupfail();
                        Thread.CurrentThread.Abort();
                    }
                    else
                    {

                        //Upload all the content
                        bool result = file.writetofile(username, password, sysncpath);
                        if (result == false)
                        {
                            Program.ClientForm.addtoConsole("Error : <<Unable to access config file. Please try Sign In>>");
                            //System.Windows.Forms.MessageBox.Show("Unable to write on the file. Please try Sign In.", "Unable to write on file");
                            Program.ClientForm.addtoConsole("Exiting");
                            Program.ClientForm.signupfail();
                            Thread.CurrentThread.Abort();
                            //return;
                        }
                        Program.ClientForm.addtoConsole("Initiating content upload");
                        uploadeverything(sysncpath);
                        //System.Windows.Forms.MessageBox.Show("Uploaded!!!", "Client");
                        //System.Windows.Forms.MessageBox.Show("Started!!!", "Client");

                        // initialize the file list for sign up scenario
                        Client.LocalFileSysAccess.FileListMaintain fileMaintain = new Client.LocalFileSysAccess.FileListMaintain();
                        fileMaintain.scanAllFilesAttributes();

                        Program.folderWatcher.start();
                        Program.ClientForm.addtoConsole("File watcher Installed");

                        Client.Program.poll.start();
                        Program.ClientForm.addtoConsole("Poll thread started");

                        if (!Program.ClientForm.IsHandleCreated)
                        {
                            Program.ClientForm.CreateHandle();
                        }
                        //enable service controller
                        Program.ClientForm.signUppassed();

                        /*
                        Threads.FileSysWatchDog watchdog = new FileSysWatchDog();
                        if (watchdog.start() == false)
                        {
                            //disable stop service button
                            //enable start service button
                        }
                         */
                    }
                    Program.ClientForm.addtoConsole("Exiting Sign Up thread");
                    Thread.CurrentThread.Abort();
                }
            }
        }