Пример #1
0
        void ProcessDbMessage(DbMessage record)
        {
            // Does the message exist yet?
            var message = this.GetMessageById(record.MessageId, nullIfMissing: true);

            bool messageIsNew = message == null;

            var eventCollector = new YamsterModelEventCollector();

            if (messageIsNew)
            {
                message = new YamsterMessage(record.MessageId, this);
                this.messagesById.Add(record.MessageId, message);
                eventCollector.NotifyAfterAdd(message);
                message.SetDbMessage(record, eventCollector);

                // For now we assume that messages cannot move between threads
                var           threadId = message.ThreadId;
                YamsterThread thread   = GetThreadById(threadId, nullIfMissing: true);
                if (thread == null)
                {
                    thread = new YamsterThread(threadId, message.Group, this);
                    threadsById.Add(threadId, thread);
                    eventCollector.NotifyAfterAdd(thread);
                    message.Group.AddThread(thread, eventCollector);

                    thread.AddMessage(message, eventCollector);

                    FixupUnresolvedObjectsForThread(thread, message, eventCollector);
                }
                else
                {
                    thread.AddMessage(message, eventCollector);
                }
            }
            else
            {
                message.SetDbMessage(record, eventCollector);
            }

            // Was there an unresolved message that we can process now?
            DbMessageState unresolvedMessageState;

            if (this.unresolvedMessageStatesById.TryGetValue(record.MessageId, out unresolvedMessageState))
            {
                this.unresolvedMessageStatesById.Remove(record.MessageId);
                ProcessDbMessageState(unresolvedMessageState, eventCollector);
            }

            if (messageIsNew)
            {
                CheckForListenedMessage(message, eventCollector);
            }

            eventCollector.FireEvents();
        }
Пример #2
0
        internal YamsterUser FetchUserById(long userId, YamsterModelEventCollector eventCollector)
        {
            YamsterUser user = this.GetUserById(userId, nullIfMissing: true);

            if (user == null)
            {
                user = new YamsterUser(userId, this);
                this.usersById.Add(userId, user);
                eventCollector.NotifyAfterAdd(user);
            }
            return(user);
        }
Пример #3
0
        internal YamsterGroup FetchGroupById(long groupId, YamsterModelEventCollector eventCollector)
        {
            YamsterGroup group = this.GetGroupById(groupId, nullIfMissing: true);

            if (group == null)
            {
                group = new YamsterGroup(groupId, this);
                this.groupsById.Add(groupId, group);
                eventCollector.NotifyAfterAdd(group);
            }
            return(group);
        }