Ejemplo n.º 1
0
        public void StartSearch(ContactSearchArguments search)
        {
            lock (this.syncObject)
            {
                this.searches.Add(search);

                if (this.searches.Count == 1)
                {
                    this.RunSearch(search);
                }
            }
        }
Ejemplo n.º 2
0
        private void LoadContactPhoto()
        {
            if (this.UserType == UserType.Group)
            {
                this.contactPhoto = new BitmapImage(new Uri("/Images/group.png", UriKind.RelativeOrAbsolute));
                return;
            }

            if (string.IsNullOrEmpty(this.PhoneNumber))
            {
                this.contactPhoto = new BitmapImage(new Uri("/Images/default.profile.png", UriKind.RelativeOrAbsolute));
                return;
            }

            var isoFile = IsolatedStorageFile.GetUserStoreForApplication();

            if (isoFile.FileExists(string.Format("UserPhoto/{0}", this.Id.ToString())))
            {
                this.contactPhoto = this.GetImageFromIsolatedStorage();
                return;
            }

            if (isoFile.FileExists(string.Format("UserPhoto/{0}Default", this.Id.ToString())))
            {
                this.contactPhoto = new BitmapImage(new Uri("/Images/default.profile.png", UriKind.RelativeOrAbsolute));
                return;
            }

            var contactSearchArguments = new ContactSearchArguments(this.PhoneNumber, SearchKind.Picture, FilterKind.PhoneNumber, null);

            contactSearchArguments.SearchCompleted += (s, args) =>
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (args.Results != null)
                    {
                        this.contactPhoto = (BitmapImage)args.Results;
                        this.SavePhoto(this.contactPhoto);
                    }

                    if (this.contactPhoto == null)
                    {
                        this.contactPhoto = new BitmapImage(new Uri("/Images/default.profile.png", UriKind.RelativeOrAbsolute));
                        this.contactPhoto.CreateOptions = BitmapCreateOptions.None;
                        isoFile.CreateFile(string.Format("UserPhoto/{0}Default", this.Id.ToString()));
                    }

                    this.NotifyPropertyChanged("ContactPhoto");
                });
            };

            ContactSearchController.Instance.StartSearch(contactSearchArguments);
        }
Ejemplo n.º 3
0
        public void StartSearch(ContactSearchArguments search)
        {
            lock (this.syncObject)
            {
                this.searches.Add(search);

                if (this.searches.Count == 1)
                {
                    this.RunSearch(search);
                }
            }
        }
Ejemplo n.º 4
0
        public void StartSearch(ContactSearchArguments search)
        {
            YapperContactsSearchEventArgs args = new YapperContactsSearchEventArgs();
            args.Filter = search.Filter;
            args.FilterKind = search.FilterKind;
            args.State = search.State;

            if (search.SearchKind == SearchKind.AllPhoneNumbers)
            {
                args.Results = this.PhoneNumbers;
                search.SearchCompleted(this, args);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initiates a search for the list of contacts registered with Yapper
        /// </summary>
        public void SyncUsers()
        {
            this.IsUsersSyncComplete = false;
            var contactSearchArgument = new ContactSearchArguments(null, SearchKind.AllPhoneNumbers, FilterKind.None, null);

            contactSearchArgument.SearchCompleted += (s, args) =>
                {
                    List<string> userPhoneNumbers = (List<string>)args.Results;
                    try
                    {
                        this.serviceProxy.GetRegisteredPhoneNumbers(userPhoneNumbers, this.RegisteredPhoneNumbersDownloaded);
                        this.DownloadGroups();
                    }
                    catch (Exception)
                    {
                        this.IsUsersSyncComplete = true;
                    }
                };

            // get all contacts
            this.contactSearchController.StartSearch(contactSearchArgument);
        }
Ejemplo n.º 6
0
        private void RunSearch(ContactSearchArguments search)
        {
            var contacts = new Contacts();

            contacts.SearchCompleted += (s, args) =>
            {
                lock (this.syncObject)
                {
                    YapperContactsSearchEventArgs eventArgs = new YapperContactsSearchEventArgs();
                    eventArgs.Filter     = args.Filter;
                    eventArgs.FilterKind = args.FilterKind;
                    eventArgs.State      = args.State;

                    switch (search.SearchKind)
                    {
                    case SearchKind.AllPhoneNumbers:
                    {
                        List <string> userPhoneNumbers = new List <string>();
                        foreach (var contact in args.Results)
                        {
                            foreach (var phoneNumber in contact.PhoneNumbers)
                            {
                                userPhoneNumbers.Add(phoneNumber.PhoneNumber);
                            }
                        }

                        eventArgs.Results = userPhoneNumbers;
                    }
                    break;

                    case SearchKind.Picture:
                    {
                        if (args.Results != null)
                        {
                            foreach (var phoneContact in args.Results)
                            {
                                if (phoneContact.GetPicture() != null)
                                {
                                    BitmapImage image = new BitmapImage();
                                    image.SetSource(phoneContact.GetPicture());
                                    eventArgs.Results = image;
                                    break;
                                }

                                break;
                            }
                        }
                    }
                    break;

                    default:
                        break;
                    }

                    search.SearchCompleted(s, eventArgs);
                    this.searches.Remove(search);
                    if (this.searches.Count != 0)
                    {
                        this.RunSearch(this.searches[0]);
                    }
                }
            };

            contacts.SearchAsync(search.Filter, search.FilterKind, search.State);
        }
Ejemplo n.º 7
0
        private void RunSearch(ContactSearchArguments search)
        {
            var contacts = new Contacts();

            contacts.SearchCompleted += (s, args) =>
                {
                    lock (this.syncObject)
                    {
                        YapperContactsSearchEventArgs eventArgs = new YapperContactsSearchEventArgs();
                        eventArgs.Filter = args.Filter;
                        eventArgs.FilterKind = args.FilterKind;
                        eventArgs.State = args.State;

                        switch (search.SearchKind)
                        {
                            case SearchKind.AllPhoneNumbers:
                                {
                                    List<string> userPhoneNumbers = new List<string>();
                                    foreach (var contact in args.Results)
                                    {
                                        foreach (var phoneNumber in contact.PhoneNumbers)
                                        {
                                            userPhoneNumbers.Add(phoneNumber.PhoneNumber);
                                        }
                                    }

                                    eventArgs.Results = userPhoneNumbers;
                                }
                                break;
                            case SearchKind.Picture:
                                {
                                    if (args.Results != null)
                                    {
                                        foreach (var phoneContact in args.Results)
                                        {
                                            if (phoneContact.GetPicture() != null)
                                            {
                                                BitmapImage image = new BitmapImage();
                                                image.SetSource(phoneContact.GetPicture());
                                                eventArgs.Results = image;
                                                break;
                                            }

                                            break;
                                        }
                                    }
                                }
                                break;
                            default:
                                break;
                        }

                        search.SearchCompleted(s, eventArgs);
                        this.searches.Remove(search);
                        if (this.searches.Count != 0)
                        {
                            this.RunSearch(this.searches[0]);
                        }
                    }
                };

            contacts.SearchAsync(search.Filter, search.FilterKind, search.State);
        }