예제 #1
0
        /// <summary>
        /// Creates a new conversation.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        Conversation CreateNewConversation(Message message)
        {
            Conversation conversation = DispatcherActivator <Conversation> .Create();

            string conversationId = message.ConversationIdentifier;

            if (String.IsNullOrEmpty(message.ConversationIdentifier))
            {
                // Create new conversation id
                conversationId = Guid.NewGuid().ToConversationId();
            }

            conversation.ConversationIdentifier = conversationId;
            conversation.Context = message.Context.ToClearSubject();

            ClientState.Current.DataService.Save(conversation);

            Logger.Debug("Conversation {0} was created successfully", LogSource.MessageMatcher, conversation);
            Logger.Debug("Message {0} now has ConversationIdentifier {1}", LogSource.MessageMatcher, message, conversationId);

            UpdateMessage(message, conversation);

            Debug.Assert(!String.IsNullOrEmpty(message.ConversationIdentifier), "Message can not have an empty ConversationIdentifier!");

            mailbox.Conversations.Add(conversation);

            return(conversation);
        }
예제 #2
0
        long SavePerson(SourceAddress address)
        {
            // Create new person
            Person person = DispatcherActivator <Person> .Create();

            person.Name = address.DisplayName;
            // See comment in SaveProfile method
            person.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;;
            person.DateCreated = DateTime.Now;

            mailbox.Persons.Add(person);

            Thread.CurrentThread.ExecuteOnUIThread(() => person.Messages.Add(message));

            person.RebuildScore();

            ClientState.Current.DataService.Save(person);

            Logger.Debug("Person saved successfully in ProfileMatcher. Person = {0}", LogSource.Sync, person.PersonId);

            SaveProfile(person, address);

            return(person.PersonId.Value);
        }
예제 #3
0
        void SaveProfile(Person person, SourceAddress address)
        {
            // Create new profile
            Profile profile = DispatcherActivator <Profile> .Create();

            profile.PersonId = person.PersonId.Value;

            // SourceChannelId is 0 if its a valid email (because soft email addresses are not
            // nescessarily tied to any channel), otherwise its the SourceChannelId of the message
            // (usually Facebook/Twitter/etc)
            profile.SourceChannelId =
                SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId;

            profile.ScreenName    = address.DisplayName;
            profile.Address       = address.Address;
            profile.SourceAddress = address;
            profile.ProfileType   = ProfileType.Default;
            profile.IsSoft        = true;
            profile.DateCreated   = DateTime.Now;

            mailbox.Profiles.Add(profile);

            Thread.CurrentThread.ExecuteOnUIThread(delegate
            {
                person.Profiles.Add(profile);

                // Set profile
                message.Profile = profile;

                profile.Messages.Add(message);
            });

            ClientState.Current.DataService.Save(profile);

            Logger.Debug("Profile saved successfully in ProfileMatcher. Person = {0}, Profile.SourceAddress = {1}", LogSource.Sync, person.PersonId, profile.SourceAddress);
        }