public ChannelProfileControl(Person person, Profile profile, ChannelConfiguration channel)
        {
            InitializeComponent();

            DataContext = this;

            Person = person;
            Profile = profile;
            Channel = channel;

            if (Channel.Charasteristics.SupportsStatusUpdates)
            {
                // Execute task to get latest status update for this user
                var task = new GetLastUserStatusTask(Channel,
                    ChannelsManager.GetChannelObject(Channel.ChannelId).StatusUpdatesChannel, Profile.SourceAddress);

                task.FinishedSuccess += GetLastUserStatusTask_Finished;
                task.FinishedFailure += GetLastUserStatusTask_FinishedFailure;
                task.ExecuteAsync();

                // Start loader animation
                ((Storyboard)FindResource("RunLoaderStoryboard")).Begin();
            }
        }
Beispiel #2
0
        public void Add(Profile profile)
        {
            Profiles.Add(profile);

            profile.Person = this;
        }
 public void AddToRecipient(Profile profile)
 {
     ToRecipients.AddRecipient(profile);
 }
Beispiel #4
0
        void LoadAddressBook()
        {
            using (new CodeTimer("VirtualMailBox/Load/AddressBook"))
            {
                const string query1 = "select PersonId, PersonKey, RedirectPersonId, SourceChannelId, Firstname, Lastname, DateOfBirth, Locale, Gender, Timezone, DateCreated from Persons";
                const string query2 = "select ProfileId, ProfileKey, PersonId, IsSoft, ChannelProfileKey, SourceChannelId, ProfileType, AvatarStreamName, ScreenName, Address, Url, SourceAddress, Location, GeoLocation, CompanyName, Title, Street, HouseNumber, ZipCode, City, State, Country, CountryCode, PhoneNr, MobileNr, FaxNr, DateCreated from Profiles";

                var temp = new List<Person>();

                using (var reader = ClientState.Current.DataService.ExecuteReader(query1))
                {
                    while (reader.Read())
                    {
                        var person = new Person(reader);

                        temp.Add(person);
                        keyedPersons.Add(person.PersonId.Value, person);
                    }
                }

                using (var reader = ClientState.Current.DataService.ExecuteReader(query2))
                {
                    while (reader.Read())
                    {
                        var profile = new Profile(reader);

                        profiles.Add(profile);

                        if (profile.Address != null)
                            if (!keyedProfiles.ContainsKey(profile.Address))
                                keyedProfiles.Add(profile.Address, profile);
                    }
                }

                #region Add profiles to persons

                foreach (var profile in profiles)
                {
                    if (keyedPersons.ContainsKey(profile.PersonId))
                        keyedPersons[profile.PersonId].Add(profile);
                }

                #endregion

                // Swap persons into addressbook
                persons.AddRange(temp);

                #region Add messages to persons and profiles

                foreach (var message in messages)
                {
                    var profile = LoadPerson(message, message.From);

                    // Set profile
                    if (profile != null)
                        message.Profile = profile;

                    foreach (var to in message.To)
                        LoadPerson(message, to);
                }

                #endregion
            }

            // Rebuild score for all persons
            persons.ForEach(p => p.RebuildScore());
        }
        void SaveProfile(Person person, SourceAddress address)
        {
            // Create new profile
            var profile = new Profile();

            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;

            ClientState.Current.DataService.Save(profile);

            Logger.Debug("Profile saved successfully in ProfileMatcher. Person = {0}, Profile.SourceAddress = {1}", LogSource.Sync, person.PersonId, profile.SourceAddress);
        }
        public void Execute()
        {
            // Validate the minimum required fields
            if (String.IsNullOrEmpty(contact.Person.Name.Trim()))
            {
                Logger.Warn("Contact for channelprofilekey [{0}] has an empty name and an invalid sourceaddress, ignoring entry", LogSource.Sync, contact.Profile.ChannelProfileKey);

                result = ContactMatchResult.Error;

                return;
            }

            if (String.IsNullOrEmpty(contact.Profile.ChannelProfileKey))
            {
                Logger.Debug("Profile for person [{0}] did not have a valid ChannelProfileKey, ignoring entry", LogSource.Sync, contact.Person.Name);

                result = ContactMatchResult.Error;

                return;
            }

            if (contact.Profile.SourceAddress == null)
            {
                Logger.Warn("Contact for channelprofilekey [{0}] has an invalid sourceaddress, ignoring entry", LogSource.Sync, contact.Profile.ChannelProfileKey);

                result = ContactMatchResult.Error;

                return;
            }

            // Some contacts (especially from gmail) don't have names but only email adrreses,
            // use the email address as name in that case
            if (String.IsNullOrEmpty(contact.Person.Name.Trim()))
            {
                contact.Person.Name = contact.Profile.SourceAddress.ToString();
                contact.IsSoft = true;
            }

            // Try to match the person to our addressbook based on unique channelprofilekey
            profile = dataService.SelectBy<Profile>(new { ChannelProfileKey = contact.Profile.ChannelProfileKey });

            if (profile != null)
            {
                // Find person belonging to profile
                EnsurePerson();

                result = ContactMatchResult.MatchedOnProfile;

                return;
            }

            // Profile not found on channel profile key, perform a match on person name
            FindPersonByName();

            // Person has been redirected
            if (person != null && person.RedirectPersonId.HasValue)
                person = dataService.SelectByKey<Person>(person.RedirectPersonId.Value);

            if (person != null)
            {
                var matchOnAddress = dataService.SelectBy<Profile>(new { Address = contact.Profile.SourceAddress.Address });

                if (matchOnAddress != null)
                {
                    Logger.Debug("Found soft profile [{0}] for person [{1}] on address match [{2}], removing from mailbox and recreating new one...", LogSource.Sync,
                        matchOnAddress.ProfileId, contact.Person.Name, contact.Profile.SourceAddress.Address);

                    // We have a soft profile on the same address that we are now receiving a hard profile for,
                    // remove the soft profile so that the matcher will create a new hard profile.
                    ClientState.Current.DataService.Delete(matchOnAddress);
                }

                // Doesn't have this profile yet, add it
                Logger.Debug("Found new profile [{0}] for person [{1}]", LogSource.Sync, contact.Profile.ChannelProfileKey, contact.Person.Name);

                // Append new profile
                SaveProfile(contact);

                result = ContactMatchResult.MatchedOnPerson;
            }
            else
            {
                profile = dataService.SelectBy<Profile>(
                    String.Format("select * from Profiles where Address like '{0}'", contact.Profile.SourceAddress.Address.AddSQLiteSlashes()));

                // Try to match to profile address
                if (profile != null)
                {
                    EnsurePerson();

                    result = ContactMatchResult.MatchedOnProfile;

                    return;
                }

                // Unable to match, create new person
                SavePerson(contact);

                // Create new profile
                SaveProfile(contact);
            }
        }
        void SaveProfile(ChannelContact channelContact)
        {
            profile = channelContact.Profile.DuckCopy<Profile>();
            profile.PersonId = person.PersonId.Value;
            profile.IsSoft = channelContact.IsSoft;

            // SourceAddress can be null with for instance phone contacts
            if (profile.SourceAddress != null)
            {
                if (String.IsNullOrEmpty(profile.ScreenName))
                    profile.ScreenName = profile.SourceAddress.DisplayName;

                if (String.IsNullOrEmpty(profile.Address))
                    profile.Address = profile.SourceAddress.Address;
            }

            try
            {
                if (channelContact.Profile.ChannelAvatar != null &&
                    (channelContact.Profile.ChannelAvatar.ContentStream != null || !String.IsNullOrEmpty(channelContact.Profile.ChannelAvatar.Url)))
                {
                    var streamname = Guid.NewGuid().GetHash(12) + "png";

                    if (channelContact.Profile.ChannelAvatar.ContentStream == null)
                    {
                        var helper = new WebContentStreamHelper(channelContact.Profile.ChannelAvatar.Url);

                        channelContact.Profile.ChannelAvatar.ContentStream = helper.GetContentStream();
                    }

                    using (channelContact.Profile.ChannelAvatar.ContentStream)
                        ClientState.Current.Storage.Write("a", streamname, channelContact.Profile.ChannelAvatar.ContentStream);

                    profile.AvatarStreamName = streamname;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("An error occured while trying to save avatar. ChannelProfileKey = {0} Exception = {1}", LogSource.Sync, channelContact.Profile.ChannelProfileKey, ex);
            }

            ClientState.Current.DataService.Save(profile);
            ClientState.Current.Search.Store(profile);

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

            using (Profiles.ReaderLock)
                found = Profiles.FirstOrDefault(p => p.Address.Equals(address.Address, StringComparison.InvariantCultureIgnoreCase));

            if (found == null)
            {
                found = new Profile {SourceAddress = address};
            }

            return found;
        }