Пример #1
0
        private void threadStartFun()
        {
            try
            {
                Console.WriteLine("in Vc thread");
                // Client create poll msg
                LocalDB readLocalDB = new LocalDB();
                readLocalDB = readLocalDB.readfromfile();
                Client.MessageClasses.MsgPoll msgpoll = new Client.MessageClasses.MsgPoll();
                Client.Message.CreateMsg pollM = new Client.Message.CreateMsg();
                msgpoll.userName = readLocalDB.getUsername();
                msgpoll.password = "******";
                string msg = pollM.pollMsg(msgpoll);

                //send the msg using socket
                ConnectionManager.Connection conn = new ConnectionManager.Connection();
                Socket soc = conn.connect(conf.serverAddr, conf.port);

                SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter();
                rw.writetoSocket(soc, msg);

                //receive the msg
                string resp = rw.readfromSocket(soc);

                //parse msg and poll
                Client.Message.MessageParser parseResp = new Client.Message.MessageParser();
                msgpoll = parseResp.pollParseMsg(resp);
                if (msgpoll.indicator == "OK")
                {
                    Configuration.userInfo.containerURI = msgpoll.fileContainerUri;
                    // write container somewhere (msgpoll.fileContainerUri);
                }

            }
            catch (Exception e)
            {
                Program.ClientForm.addtoConsole(e.ToString());
                System.Windows.Forms.MessageBox.Show(e.ToString());
                //System.IO.File.WriteAllText("errors.txt", e.ToString());
            }
            finally
            {
                Thread.CurrentThread.Abort();
            }
        }
Пример #2
0
        public void poll()
        {
            Configuration.flag.polling = true;
            Program.ClientForm.addtoConsole("Poll initiated");

            //MessageBox.Show("Polling started", "Client");
            try
            {
                // Client create poll msg
                LocalDB readLocalDB = new LocalDB();
                readLocalDB = readLocalDB.readfromfile();

                Client.MessageClasses.MsgPoll msgpoll = new Client.MessageClasses.MsgPoll();
                Client.Message.CreateMsg pollM = new Client.Message.CreateMsg();
                msgpoll.userName = readLocalDB.getUsername();
                msgpoll.password = readLocalDB.getPassword();
                string msg = pollM.pollMsg(msgpoll);

                //send the msg using socket
                ConnectionManager.Connection conn = new ConnectionManager.Connection();
                Socket soc = conn.connect(conf.serverAddr, conf.port);

                SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter();
                rw.writetoSocket(soc, msg);
                Program.ClientForm.addtoConsole("Writing Socket");
                //receive the msg
                string resp = rw.readfromSocket(soc);
                Program.ClientForm.addtoConsole("Reading Socket");
                //parse msg and poll
                Client.Message.MessageParser parseResp = new Client.Message.MessageParser();
                msgpoll = parseResp.pollParseMsg(resp);
                if (msgpoll.indicator == "OK")
                {
                    new Client.PollFunction.Poll(msgpoll.fileContainerUri);
                    Configuration.userInfo.containerURI = msgpoll.fileContainerUri;
                }
                Configuration.flag.polling = false;
            }
            catch(Exception ex)
            {
                Program.ClientForm.addtoConsole("Poll thread Exception:" + ex.Message);
                //System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }