예제 #1
0
파일: Worker.cs 프로젝트: Pallua1/Qs2017
        /// <summary>
        /// Spawns a worker helper which communicates with the message store to add a dislike
        /// to a user message given in the message passed as parameter.
        /// </summary>
        /// <param name="m">non-null message of type Dislike</param>
        protected void processDislike(Message m)
        {
            Dislike like = (Dislike)m;

            if (!ongoingCommunications.ContainsKey(like.CommunicationId))
            {
                throw new UnknownClientException("Unknown communication ID");
            }
            SimulatedActor      client  = ongoingCommunications[like.CommunicationId];
            MessageStoreMessage message = new AddDislike(like.ClientName, like.MessageId, like.CommunicationId);
            WorkerHelper        helper  = new WorkerHelper(messageStore, client, message, system);

            system.Spawn(helper);
        }
예제 #2
0
 /// <summary>
 /// The message processing logic for the store.
 /// <para>If the message passed as parameter is of type <c>RetrieveFromStore</c>,
 /// all messages of a given author are looked up and sent back to the client of the
 /// store.
 /// </para>
 /// <para>If the message passed as parameter is of type <c>AddLike</c>, a
 /// like is added to the given message if the message exists and has not
 /// already been liked by the given person.
 /// If the message passed as parameter is of type <c>UpdateMessageStore</c>,
 /// a message is stored if the message is new and if the same message has not already
 /// been stored by the same author.
 /// In case of success a OperationAck message is sent to the client, otherwise
 /// an OperationFailed message is sent.
 /// </para>
 /// </summary>
 /// <param name="m">message sent to the store</param>
 public override void Receive(Message m)
 {
     if (m is RetrieveFromStore)
     {
         RetrieveFromStore  retrieve     = (RetrieveFromStore)m;
         List <UserMessage> foundMessage = FindByAuthor(retrieve.Author);
         retrieve.StoreClient.Tell(new FoundMessages(foundMessage, retrieve.CommunicationId));
     }
     else if (m is AddLike)
     {
         AddLike addLikeMessage = (AddLike)m;
         if (addLike(addLikeMessage.ClientName, addLikeMessage.MessageId))
         {
             addLikeMessage.StoreClient.Tell(new OperationAck(addLikeMessage.CommunicationId));
         }
         else
         {
             addLikeMessage.StoreClient.Tell(new OperationFailed(addLikeMessage.CommunicationId));
         }
     }
     else if (m is AddDislike)
     {
         AddDislike addDislikeMessage = (AddDislike)m;
         if (addDislike(addDislikeMessage.ClientName, addDislikeMessage.MessageId))
         {
             addDislikeMessage.StoreClient.Tell(new OperationAck(addDislikeMessage.CommunicationId));
         }
         else
         {
             addDislikeMessage.StoreClient.Tell(new OperationFailed(addDislikeMessage.CommunicationId));
         }
     }
     else if (m is UpdateMessageStore)
     {
         UpdateMessageStore updateMessage = (UpdateMessageStore)m;
         if (update(updateMessage.Message))
         {
             updateMessage.StoreClient.Tell(new OperationAck(updateMessage.CommunicationId));
         }
         else
         {
             updateMessage.StoreClient.Tell(new OperationFailed(updateMessage.CommunicationId));
         }
     }
 }