ChannelContact ParseContact(XElement source) { ChannelContact contact = new ChannelContact(); contact.Person.Firstname = source.Element("firstname").Value; contact.Person.Lastname = source.Element("lastname").Value; contact.Person.Gender = source.Element("gender").Value; contact.Profile.ScreenName = contact.Person.Name; contact.Profile.ChannelProfileKey = source.Element("userid").Value; contact.Profile.ProfileType = ProfileType.Social; contact.Profile.Url = source.Element("url").Value; contact.Profile.SourceAddress = new SourceAddress(source.Element("userid").Value, contact.Person.Name); if (source.Element("cityname") != null) { contact.Profile.City = source.Element("cityname").Value; } if (source.Element("countryname") != null) { contact.Profile.Country = source.Element("countryname").Value; } if (source.Element("countryname") != null) { contact.Profile.Country = source.Element("countryname").Value; } if (source.Element("birthday") != null && !(String.IsNullOrEmpty(source.Element("birthday").Element("year").Value)) && !(String.IsNullOrEmpty(source.Element("birthday").Element("month").Value)) && !(String.IsNullOrEmpty(source.Element("birthday").Element("day").Value))) { contact.Person.DateOfBirth = new DateTime( Int32.Parse(source.Element("birthday").Element("year").Value), Int32.Parse(source.Element("birthday").Element("month").Value), Int32.Parse(source.Element("birthday").Element("day").Value) ); } if (source.Element("profilepicture") != null) { string url = source.Element("profilepicture").Element("icon_extralarge").Element("src").Value; ChannelAvatar avatar = new ChannelAvatar(); avatar.Url = url; avatar.ContentStream = WebContentStreamHelper.GetContentStream(avatar.Url); contact.Profile.ChannelAvatar = avatar; } return(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); } mailbox.Profiles.Add(profile); Thread.CurrentThread.ExecuteOnUIThread(() => person.Add(profile)); 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); }
ChannelContact ParseFbContact(FbContact fbContact) { ChannelContact contact = new ChannelContact(); contact.Person.Firstname = fbContact.Firstname; contact.Person.Lastname = fbContact.Lastname; contact.Profile.ChannelProfileKey = fbContact.UserId; contact.Profile.ProfileType = ProfileType.Social; contact.Profile.SourceAddress = new SourceAddress(fbContact.UserId, contact.Person.Name); if (!String.IsNullOrEmpty(fbContact.AvatarSquareUrl.Trim())) { ChannelAvatar avatar = new ChannelAvatar(); avatar.Url = fbContact.AvatarSquareUrl; avatar.ContentStream = WebContentStreamHelper.GetContentStream(avatar.Url); contact.Profile.ChannelAvatar = avatar; } return(contact); }