public SoftProfilesControl(Person person) { Person = person; Profiles = new AdvancedObservableCollection<Profile>(); InitializeComponent(); DataContext = this; }
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(); } }
static void UserProfileControl_SourceAddresChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) { // Find and attach person var address = (SourceAddress) args.NewValue; if (address != null) { var person = VirtualMailBox.VirtualMailBox.Current.FindPerson(address); if (person == null) { // Person not found, create a fake one person = new Person(address); person.Profiles.Add(new Profile { SourceAddress = address, ScreenName = address.DisplayName, Address = address.Address }); } // Attach person to control ((UserProfileControl)d).Person = person; } }
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); }
long SavePerson(SourceAddress address) { // Create new person var person = new Person(); // See comment in SaveProfile method person.SourceChannelId = SourceAddress.IsValidEmail(address.Address) ? 0 : message.SourceChannelId; ; person.Name = address.DisplayName; person.DateCreated = DateTime.Now; 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; }
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 SavePerson(ChannelContact channelContact) { person = channelContact.Person.DuckCopy<Person>(); person.PersonId = person.PersonId; person.Firstname = person.Firstname.Capitalize(); person.Lastname = person.Lastname.Capitalize(); ClientState.Current.DataService.Save(person); Logger.Debug("Person saved successfully in ContactMatcher. Person = {0}", LogSource.Sync, person.PersonId); }
void FindPersonByName() { const string query = "select * from Persons where (Firstname || ' ' || Lastname) like '{0}' or replace(Firstname || Lastname, ' ', '') like '%{1}%'"; person = dataService.SelectBy<Person>(String.Format(query, contact.Person.Name.AddSQLiteSlashes(), contact.Person.Name.Replace(" ", ""))); }
void EnsurePerson() { person = dataService.SelectByKey<Person>(profile.PersonId); if (person == null) { FindPersonByName(); // Person not found on id or name, create a new person entry if (person == null) SavePerson(contact); } }
void FindPersonByName() { person = mailbox.Persons.FirstOrDefault(p => p.Name.Equals(contact.Person.Name, StringComparison.InvariantCultureIgnoreCase) || p.Name.Replace(" ", "").IndexOf(contact.Person.Name, StringComparison.InvariantCultureIgnoreCase) > -1); }
void EnsurePerson() { using (mailbox.Persons.ReaderLock) person = mailbox.Persons.FirstOrDefault(p => p.PersonId == profile.PersonId); if (person == null) { FindPersonByName(); // Person not found on id or name, create a new person entry if (person == null) SavePerson(contact); } }
public void JoinWith(Person person) { // Remove profile from old person if (Person != null) { Person.Profiles.Remove(this); Person.Messages.RemoveAll(m => Messages.Contains(m)); Person.Documents.RemoveAll(d => Documents.Contains(d)); if (Person.Profiles.Count == 0) { // If no profiles left, update person to indicate redirection Person.RedirectPersonId = Person.PersonId; AsyncUpdateQueue.Enqueue(Person); } } // Add profile to new person Person = person; Person.Profiles.Add(this); Person.Messages.AddRange(Messages); Person.Documents.AddRange(Documents); // Update person reference PersonId = Person.PersonId.Value; // Save profile to database AsyncUpdateQueue.Enqueue(this); }