Ejemplo n.º 1
0
        /* The CheckResourceVote MessageHandler
         * It handles messages of RANK_CHECK_RESOURCE_VOTE_REQUEST type.
         */
        private static void CheckResourceVote(RMessage message, TcpClient connection)
        {
            Console.WriteLine("CheckResourceVote");
            UserData         usr          = (UserData)(((List <Object>)message.Data)[0]);
            ResourceData     res          = (ResourceData)(((List <Object>)message.Data)[1]);
            ResourceVoteData resVote      = ResourceVoteConnector.CheckResourceVote(usr, res);
            List <Object>    replyContent = new List <Object>();

            replyContent.Add(usr);
            replyContent.Add(res);
            replyContent.Add(resVote);
            RMessage replyMessage = new RMessage(MessageType.RANK_CHECK_RESOURCE_VOTE_REPLY, replyContent);

            ServerCore.GetWorkerByConnection(connection).SendMessage(replyMessage);
        }
Ejemplo n.º 2
0
        /* The ResourceVote MessageHandler
         * It handles messages of VOTE_RESOURCE_REQUEST type.
         */
        private static void ResourceVote(RMessage message, TcpClient connection)
        {
            Console.WriteLine("VoteResource");
            ResourceVoteData resVote = (ResourceVoteData)message.Data;

            ResourceVoteData oldResVote = ResourceVoteConnector.UpdateVote(resVote);

            ResourceConnector.VoteResource(oldResVote, resVote);
            UserConnector.UpdateUserRank(ServerCore.GetIdByConnection(connection), Ranking.USER_VOTED_RESOURCE_VALUE);

            ResourceData editedResource = ResourceConnector.GetResource(resVote.Id_Resource);

            RMessage            replyMessage = new RMessage(MessageType.EDIT_RESOURCE_REPLY, editedResource);
            List <ClientWorker> clientList   = ServerCore.GetAllWorkers();

            foreach (ClientWorker client in clientList)
            {
                client.SendMessage(replyMessage);
            }
        }