Пример #1
0
        /// <summary>
        /// Send to client list of PollSessions
        /// </summary>
        /// <param name="client">NetworkStream client</param>
        public void SendPollSessionsList(NetworkStream client)
        {
            string sendString;
            PollPacket sendPacket = new PollPacket();

            try
            {
                sendPacket.pollSessionList.items = PollDAL.GetPollSessions();
                sendString = PollSerializator.SerializePacket(sendPacket);
                data = Encoding.ASCII.GetBytes(sendString);
                client.Write(data, 0, sendString.Length);
                log.Info("List of PollSessions successfully sent to client");
            }
            catch (Exception exception)
            {
                log.Error(exception.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Receive PollPacket from client and response for a query
        /// </summary>
        /// <param name="client">NetworkStream client</param>
        public void RunClientSession(NetworkStream client)
        {
            while (true)
            {
                // Receive PollPacket from client
                string receivedString = ReceiveFromClient(client);
                if (receivedString == String.Empty)
                {
                    return;
                }

                receivedPacket = PollSerializator.DeserializePacket(receivedString);
                if (receivedPacket == null)
                {
                    log.Error("Invalid data received");
                    return;
                }

                // Select option
                switch (receivedPacket.request.type)
                {
                    case Request.GET_LIST:
                        SendPollSessionsList(client);
                        break;
                    case Request.GET_POLLSESSION:
                        SendPollSession(client);
                        break;
                    case Request.CREATE_POLLSESSION:
                        CreatePollSession(client);
                        break;
                    case Request.SAVE_RESULT:
                        SavePollSessionResult(client);
                        break;
                    case Request.REMOVE_POLLSESSION:
                        RemovePollSession(client);
                        break;
                    default:
                        log.Error("Invalid option sent by client");
                        break;
                }
            }
        }