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);
            }
        }
Example #2
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);
        }
Example #3
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);
        }