Exemple #1
0
        private void threadStartFun(Socket soc, string req)
        {
            try
            {
                Program.ServerForm.addtoConsole("Service Poll Req Thread Started");
                Server.Message.MessageParser serverPollPar = new Server.Message.MessageParser();
                Server.MessageClasses.MsgPoll msgpollServer = serverPollPar.pollParseMsg(req);

                CloudBlobClient blobClient = new Server.ConnectionManager.BlobConn().BlobConnect();
                Blob blob = new Blob(blobClient, msgpollServer.userName);
                GenerateSAS sas = new GenerateSAS();
                string link = "";
                if (msgpollServer.password == "requestVC")
                {
                    link = sas.GetContainerSasUri(blob.container, "RWLD");
                }
                else
                {
                    link = sas.GetContainerSasUri(blob.container, "RWLD");
                }

                // Server send response to Client
                Server.Message.CreateMsg pollResp = new Server.Message.CreateMsg();
                msgpollServer.fileContainerUri = link;
                msgpollServer.fileBlobUri = "none";
                string respMsg = pollResp.pollRespMsg("OK", msgpollServer);

                //socket
                SocketCommunication.ReaderWriter rw = new SocketCommunication.ReaderWriter();
                // write to socket
                rw.writetoSocket(soc, respMsg);
                Program.ServerForm.addtoConsole("Wrote Response to socket");

            }
            catch (Exception e)
            {
                Program.ServerForm.addtoConsole("Exception: [Poll Req]"+ e.Message);
                //System.Windows.Forms.MessageBox.Show(e.ToString());
            }
            finally
            {
                Program.ServerForm.addtoConsole("Exiting");
                Thread.CurrentThread.Abort();
            }
        }
        public void interPollTest()
        {
            // 1. Client create and send poll msg to Server
                Client.Message.CreateMsg pollM = new Client.Message.CreateMsg();
                Client.MessageClasses.MsgPoll msgpoll = new Client.MessageClasses.MsgPoll();
                msgpoll.userName = "******";
                msgpoll.password = "******";
                string pollCtoS = pollM.pollMsg(msgpoll);
                Console.WriteLine("msg from client to server: " + pollCtoS);

                // 2. Server parse msg and create sas uri
                Server.Message.MessageParser serverPollPar = new Server.Message.MessageParser();
                Server.MessageClasses.MsgPoll msgpollServer = serverPollPar.pollParseMsg(pollCtoS);
                string resp = "";
                try
                {
                    CloudBlobClient blobClient = new Server.ConnectionManager.BlobConn().BlobConnect();
                    Blob blob = new Blob(blobClient, msgpollServer.userName);
                    GenerateSAS sas = new GenerateSAS();
                    string link = sas.GetContainerSasUri(blob.container, "RL");
                    // 3. Server send response to Client
                    Server.Message.CreateMsg pollResp = new Server.Message.CreateMsg();
                    msgpollServer.fileContainerUri = link;
                    msgpollServer.fileBlobUri = "none";
                    resp = pollResp.pollRespMsg("OK", msgpollServer);

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }

                //4. Client parse and poll
                Client.Message.MessageParser pollGetClient = new Client.Message.MessageParser();
                msgpoll = pollGetClient.pollParseMsg(resp);
                new Client.PollFunction.Poll(msgpoll.fileContainerUri);
        }