Example #1
0
        public Domain.Message MapClientMessageToDomain(Model.Message message)
        {
            var messageDto = new Domain.Message()
            {
                SentDate = message.SentDate,
                Likes = message.Likes,
                Text = message.Text,
                Author = new BsonDocument
                    {
                        {"Id", new ObjectId(message.SenderId)},
                        {"Username", message.Username},
                        {"Avatar", new ObjectId(message.AvatarId)}
                    }
            };

            if (message.Id != null)
                messageDto.Id = new ObjectId(message.Id);

            return messageDto;
        }
 // Inserts a single message into the collection. If the messages is
 // already present in the collection an exception will be thrown.
 public void InsertMessage(Message message)
 {
     messageCollection.Insert(message);
 }
Example #3
0
        /// <summary>
        /// Gets the current callback channel and adds it to the collection of all channels.
        /// </summary>
        /// <returns></returns>
        public ChannelWrapper RegisterClient(Message message)
        {
            var manager = new NewsfeedManager();

            string username;
            if (manager.TryGetCurrentUsername(message, out username))
            {
                ChannelWrapper wrapper;

                //If the user is logged and resfresh the page, a new channel will be opened and the old should be removed
                if (this.clients.TryGetValue(username, out wrapper))
                {
                    this.clients.Remove(username);
                }

                var client = OperationContext.Current.GetCallbackChannel<INewsfeedServiceCallback>();

                wrapper = new ChannelWrapper(username, client);
                wrapper.Closed += Connection_Closed;
                wrapper.Faulted += Connection_Closed;

                var usersRepository = new Domain.UserRepository();
                wrapper.User = usersRepository.Get(username);

                this.clients.Add(username, wrapper);

                return wrapper;
            }

            return null;
        }