private void threadStartFun(Socket soc, string req) { Program.ServerForm.addtoConsole("Sign In thread Started"); Message.MessageParser parser = new Message.MessageParser(); MessageClasses.MsgSignIn.req reqobj = new MessageClasses.MsgSignIn.req(); reqobj = parser.signInParseReq(req); ConnectionManager.DataBaseConn con = new ConnectionManager.DataBaseConn(1); SqlConnection conn = con.DBConnect(); //check if user already exits UserAuth.SignInFunctions userauth = new UserAuth.SignInFunctions(); if(userauth.userAuthentication(reqobj.userName,reqobj.psw)==true) { Program.ServerForm.addtoConsole("User Exists"); MessageClasses.MsgSignIn.resp resp = new MessageClasses.MsgSignIn.resp(); resp.ack = "OK"; resp.addiMsg = "EXISTING"; Message.CreateMsg msg = new Message.CreateMsg(); string res = msg.signInResp(resp); SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter(); rw.writetoSocket(soc, res); Program.ServerForm.addtoConsole("Wrote Respose to scoket"); } else { Program.ServerForm.addtoConsole("User Does Not Exist"); MessageClasses.MsgSignIn.resp resp = new MessageClasses.MsgSignIn.resp(); resp.ack = "ERRORS"; resp.addiMsg = "NON-EXISTING"; Message.CreateMsg msg = new Message.CreateMsg(); string res = msg.signInResp(resp); SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter(); rw.writetoSocket(soc, res); Program.ServerForm.addtoConsole("Wrote Response to socket. Exiting"); } Thread.CurrentThread.Abort(); }
private void threadStartFun(Socket soc, string req) { Program.ServerForm.addtoConsole("Service SignUpReq Thread Started"); //parse msg received //System.Windows.Forms.MessageBox.Show("Signup service started:"+ req, "Server"); Message.MessageParser parser = new Message.MessageParser(); MessageClasses.MsgSignUp.req reqobj = new MessageClasses.MsgSignUp.req(); reqobj = parser.signUpParseReq(req); //create connection with sql ConnectionManager.DataBaseConn con = new ConnectionManager.DataBaseConn(1); SqlConnection conn = con.DBConnect(); //check if user already exits DatabaseAccess.Query q = new DatabaseAccess.Query(); if (true == q.checkIfUserExists(reqobj.userName, conn)) { con.DBClose(); //System.Windows.Forms.MessageBox.Show("Signup service if user exists", "Server"); MessageClasses.MsgSignUp.resp resp = new MessageClasses.MsgSignUp.resp(); resp.ack = "ERRORS"; resp.addiMsg = "AlreadyExist"; Message.CreateMsg msg = new Message.CreateMsg(); string res= msg.signUpResp(resp); SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter(); rw.writetoSocket(soc, res); Program.ServerForm.addtoConsole("Writing response to Socket"); Program.ServerForm.addtoConsole("Exiting"); Thread.CurrentThread.Abort(); } else { ConnectionManager.DataBaseConn con1 = new ConnectionManager.DataBaseConn(1); SqlConnection conn1 = con.DBConnect(); if (true == q.insertNewUser(reqobj.userName, reqobj.psw, conn1)) { Program.ServerForm.addtoConsole("New User Added"); conn1.Close(); //System.Windows.Forms.MessageBox.Show("Signup service insert user", "Server"); MessageClasses.MsgSignUp.resp resp = new MessageClasses.MsgSignUp.resp(); resp.ack = "OK"; resp.addiMsg = "Added"; Message.CreateMsg msg = new Message.CreateMsg(); string res = msg.signUpResp(resp); SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter(); rw.writetoSocket(soc, res); Program.ServerForm.addtoConsole("Wrote response to Socket"); //conn.Close(); } else { conn1.Close(); Program.ServerForm.addtoConsole("Sign Up Error while inserting to Database"); //System.Windows.Forms.MessageBox.Show("Signup service could insert", "Server"); MessageClasses.MsgSignUp.resp resp = new MessageClasses.MsgSignUp.resp(); resp.ack = "ERRORS"; resp.addiMsg = "ERRORWHILEINSERTING"; Message.CreateMsg msg = new Message.CreateMsg(); string res = msg.signUpResp(resp); SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter(); rw.writetoSocket(soc, res); Program.ServerForm.addtoConsole("Wrote Respose to Socket"); //conn.Close(); } //conn.Close(); Program.ServerForm.addtoConsole("Exiting"); Thread.CurrentThread.Abort(); } //TBD }
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(); } } }
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(); } } }