Пример #1
0
 public static void ContactReceived(ChannelContact contact)
 {
     new ContactMatcher(contact).Execute();
 }
Пример #2
0
        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;
        }
        public IEnumerable<ChannelContact> GetContacts()
        {
            var client = new ExchangeClient(Hostname, CredentialsProvider);

            foreach (var contactItem in client.GetContacts())
            {
                if (contactItem.EmailAddresses == null || contactItem.EmailAddresses.Length == 0)
                {
                    Logger.Warn("Contact {0} had no email address, ignoring", LogSource.Sync, contactItem.DisplayName);

                    continue;
                }

                var contact = new ChannelContact();

                contact.Profile.ChannelProfileKey = contactItem.ItemId.Id;
                contact.Profile.SourceAddress = new SourceAddress(contactItem.EmailAddresses[0].Value, contactItem.DisplayName);

                contact.Person.Lastname = contactItem.Surname;
                contact.Person.Firstname = contactItem.GivenName;

                if (contactItem.BirthdaySpecified)
                    contact.Person.DateOfBirth = contactItem.Birthday;

                contact.Profile.ScreenName = contactItem.Nickname;
                contact.Profile.Title = contactItem.JobTitle;
                contact.Profile.ScreenName = contactItem.DisplayName;
                contact.Profile.CompanyName = contactItem.CompanyName;

                if (contactItem.PhysicalAddresses.Length > 0)
                {
                    contact.Profile.Street = contactItem.PhysicalAddresses[0].Street;
                    contact.Profile.ZipCode = contactItem.PhysicalAddresses[0].PostalCode;
                    contact.Profile.City = contactItem.PhysicalAddresses[0].City;
                    contact.Profile.Country = contactItem.PhysicalAddresses[0].CountryOrRegion;
                }

                yield return contact;
            }
        }
        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;
        }
Пример #5
0
 public ContactMatcher(ChannelContact contact)
 {
     this.contact = contact;
     this.dataService = ClientState.Current.DataService;
 }
Пример #6
0
        public IEnumerable<ChannelContact> GetContacts()
        {
            foreach (var ycontact in GetYammerContacts())
            {
                var contact = new ChannelContact();
                contact.Person.Name = ycontact.FullName;

                contact.Profile.ChannelProfileKey = ycontact.Id;
                contact.Profile.ProfileType = ProfileType.Social;
                contact.Profile.ScreenName = ycontact.ScreenName;
                contact.Profile.Url = ycontact.Url;
                contact.Profile.Location = ycontact.Location;
                contact.Profile.Title = ycontact.Title;
                contact.Profile.SourceAddress = new SourceAddress(ycontact.ScreenName, ycontact.FullName);

                contact.Profile.ChannelAvatar = new ChannelAvatar();
                contact.Profile.ChannelAvatar.Url = ycontact.AvatarUrl;

                yield return contact;
            }
        }
Пример #7
0
        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);
        }
Пример #8
0
        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);
        }
Пример #9
0
 public ContactMatcher(ChannelContact contact)
 {
     this.contact = contact;
     this.mailbox = VirtualMailBox.Current;
 }
Пример #10
0
        public IEnumerable<ChannelContact> GetContacts()
        {
            var service = new TwitterService(ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);
            var result = service.ListFriends();

            foreach (var user in result)
            {
                var contact = new ChannelContact { IsSoft = true };

                contact.Profile.ChannelProfileKey = user.Id.ToString();
                contact.Person.Name = user.Name;
                contact.Profile.ScreenName = user.ScreenName;
                contact.Profile.SourceAddress = new SourceAddress(user.Id.ToString(), user.Name);
                contact.Profile.ProfileType = ProfileType.Social;
                contact.Profile.Url = user.Url;
                contact.Profile.Title = user.Description;
                contact.Profile.Location = user.Location;
                contact.Profile.ChannelAvatar = new ChannelAvatar();
                contact.Profile.ChannelAvatar.Url = user.ProfileImageUrl;

                yield return contact;
            }
        }
        //TODO: right implementation
        protected ChannelContact ParseContact(XElement element)
        {
            ChannelContact contact = new ChannelContact();

            contact.Person.Name = element.Element("Profiles").Element("Personal").Element("DisplayName").Value;
            contact.Profile.ChannelProfileKey = element.Element("ID").Value;

            // Todo could be different kind of addressses; home, work etc
            contact.Profile.SourceAddress = new SourceAddress(
                element.Element("Emails").Element("Email").Element("Address").Value,
                element.Element("Profiles").Element("Personal").Element("DisplayName").Value);

            return contact;
        }
        /// <summary>
        /// See: http://developer.linkedin.com/docs/DOC-1004
        /// </summary>
        /// <returns></returns>
        public IEnumerable<ChannelContact> GetContacts()
        {
            var result = LinkedInWebRequest.PerformRequest(new Uri("http://api.linkedin.com/v1/people/~/connections"),
                ChannelHelper.ConsumerKey, ChannelHelper.ConsumerSecret, ChannelHelper.Token, ChannelHelper.TokenSecret);

            if (result.Element("connections").Elements().Count() == 0)
                yield break;

            foreach (var response in result.Elements("connections").Elements("person"))
            {
                ChannelContact contact = new ChannelContact();
                contact.Profile.ChannelProfileKey = response.Element("id").Value;
                contact.Person.Firstname = response.Element("first-name").Value;
                contact.Person.Lastname = response.Element("last-name").Value;

                contact.Profile.Title = response.Element("headline").Value;
                contact.Profile.Url = response.Element("site-standard-profile-request").Element("url").Value;

                if (response.Element("picture-url") != null)
                {
                    contact.Profile.ChannelAvatar = new ChannelAvatar();
                    contact.Profile.ChannelAvatar.Url = response.Element("picture-url").Value;
                }

                contact.Profile.SourceAddress = new SourceAddress(response.Element("id").Value, contact.Person.Name);
                contact.Profile.ProfileType = ProfileType.Social;

                yield return contact;
            }
        }
        public IEnumerable<ChannelContact> GetContacts()
        {
            var cred = CredentialsProvider.GetCredentials();
            var rs = new RequestSettings("Tabdeelee-Inbox2-1", cred.Claim, cred.Evidence) { AutoPaging = true };
            var cr = new ContactsRequest(rs);

            var feed = cr.GetContacts();

            foreach (Contact entry in feed.Entries)
            {
                ChannelContact contact = new ChannelContact();

                contact.Person.Name = entry.Title;
                contact.Profile.ChannelProfileKey = entry.Id;

                if (entry.Phonenumbers.Count > 0)
                {
                    var phone = entry.Phonenumbers.First();
                    contact.Profile.PhoneNr = phone.Value;
                }

                if (entry.PrimaryEmail != null)
                    contact.Profile.SourceAddress = new SourceAddress(entry.PrimaryEmail.Address, contact.Person.Name);

                try
                {
                    // Check for 404 with custom httpclient on photourl since regular HttpWebClient keeps throwing exceptions
                    //var token = cr.Service.QueryAuthenticationToken();
                    //var code = HttpStatusClient.GetStatusCode(entry.PhotoUri.ToString(),
                    //    new Dictionary<string, string> { { "Authorization", "GoogleLogin auth=" + token }});

                    //if (code.HasValue && code == 200)
                    //{
                        IGDataRequest request = cr.Service.RequestFactory.CreateRequest(GDataRequestType.Query, entry.PhotoUri);
                        request.Execute();

                        using (var avatarstream = request.GetResponseStream())
                        {
                            if (avatarstream != null)
                            {
                                ChannelAvatar avatar = new ChannelAvatar();

                                // Copy avatarstream to a new memorystream because the source
                                // stream does not support seek operations.
                                MemoryStream ms = new MemoryStream();
                                avatarstream.CopyTo(ms);

                                avatar.Url = entry.PhotoUri.ToString();
                                avatar.ContentStream = ms;

                                contact.Profile.ChannelAvatar = avatar;
                            }
                        }
                    //}
                }
                catch (CaptchaRequiredException)
                {
                    // Since GMail will keep on raising CaptchaRequiredException, break out here
                    // todo let the user know in some way or another?
                    yield break;
                }
                catch (Exception)
                {

                }

                yield return contact;
            }
        }