public PickContactPicker()
 {
     InitializeComponent();
     var cons = new DeviceContacts();
     cons.SearchCompleted += this.OnSearchCompleted;
     cons.SearchAsync(string.Empty, FilterKind.None, string.Empty);
 }
Ejemplo n.º 2
0
        public Contacts()
        {
            saveContactTask = new SaveContactTask();
            saveContactTask.Completed += new EventHandler<SaveContactResult>(saveContactTask_Completed);

            contacts = new Microsoft.Phone.UserData.Contacts();
            contacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);
        }
Ejemplo n.º 3
0
        void ContactSaveTaskCompleted(object sender, SaveContactResult e)
        {
            SaveContactTask task = sender as SaveContactTask;

            if (e.TaskResult == TaskResult.OK)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    DeviceContacts deviceContacts   = new DeviceContacts();
                    deviceContacts.SearchCompleted += new EventHandler <ContactsSearchEventArgs>(postAdd_SearchCompleted);

                    string displayName = String.Format("{0}{2}{1}", task.FirstName, task.LastName, String.IsNullOrEmpty(task.FirstName) ? "" : " ");

                    deviceContacts.SearchAsync(displayName, FilterKind.DisplayName, task);
                });
            }
            else if (e.TaskResult == TaskResult.Cancel)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Operation cancelled."));
            }
        }
Ejemplo n.º 4
0
        // TODO: we need to be able to pass a search param in.
        public void search(string searchCriteria)
        {
            ContactSearchParams searchParams = JSON.JsonHelper.Deserialize <ContactSearchParams>(searchCriteria);

            DeviceContacts deviceContacts = new DeviceContacts();

            deviceContacts.SearchCompleted += new EventHandler <ContactsSearchEventArgs>(contacts_SearchCompleted);

            // default is to search all fields
            FilterKind filterKind = FilterKind.None;

            // if only one field is specified, we will try the 3 available DeviceContact search filters
            if (searchParams.fields.Count() == 1)
            {
                if (searchParams.fields.Contains("name"))
                {
                    filterKind = FilterKind.DisplayName;
                }
                else if (searchParams.fields.Contains("emails"))
                {
                    filterKind = FilterKind.EmailAddress;
                }
                else if (searchParams.fields.Contains("phoneNumbers"))
                {
                    filterKind = FilterKind.PhoneNumber;
                }
            }

            try
            {
                deviceContacts.SearchAsync(searchParams.options.filter, filterKind, searchParams);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("search contacts exception :: " + ex.Message);
            }
        }
Ejemplo n.º 5
0
        void ContactSaveTaskCompleted(object sender, SaveContactResult e)
        {
            SaveContactTask task = sender as SaveContactTask;

            if (e.TaskResult == TaskResult.OK)
            {

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    DeviceContacts deviceContacts = new DeviceContacts();
                    deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(postAdd_SearchCompleted);

                    string displayName = String.Format("{0}{2}{1}", task.FirstName, task.LastName, String.IsNullOrEmpty(task.FirstName) ? "" : " ");

                    deviceContacts.SearchAsync(displayName, FilterKind.DisplayName, task);
                });

            }
            else if (e.TaskResult == TaskResult.Cancel)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Operation cancelled."));
            }
        }
Ejemplo n.º 6
0
        public void search(string searchCriteria)
        {
            string[] args = JSON.JsonHelper.Deserialize<string[]>(searchCriteria);

            ContactSearchParams searchParams = new ContactSearchParams();
            try
            {
                searchParams.fields = JSON.JsonHelper.Deserialize<string[]>(args[0]);
                searchParams.options = JSON.JsonHelper.Deserialize<SearchOptions>(args[1]);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_ARGUMENT_ERROR));
                return;
            }

            if (searchParams.options == null)
            {
                searchParams.options = new SearchOptions();
                searchParams.options.filter = "";
                searchParams.options.multiple = true;
            }
            else if (searchParams.options.filter == null)
            {
                searchParams.options.filter = "";
            }

            DeviceContacts deviceContacts = new DeviceContacts();
            deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);

            // default is to search all fields
            FilterKind filterKind = FilterKind.None;
            // if only one field is specified, we will try the 3 available DeviceContact search filters
            if (searchParams.fields.Count() == 1)
            {
                if (searchParams.fields.Contains("name"))
                {
                    filterKind = FilterKind.DisplayName;
                }
                else if (searchParams.fields.Contains("emails"))
                {
                    filterKind = FilterKind.EmailAddress;
                }
                else if (searchParams.fields.Contains("phoneNumbers"))
                {
                    filterKind = FilterKind.PhoneNumber;
                }
            }

            try
            {

                deviceContacts.SearchAsync(searchParams.options.filter, filterKind, searchParams);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("search contacts exception :: " + ex.Message);
            }
        }
Ejemplo n.º 7
0
        void contactTask_Completed(object sender, SaveContactResult e)
        {
            SaveContactTask task = sender as SaveContactTask;

            if (e.TaskResult == TaskResult.OK)
            {
                DeviceContacts deviceContacts = new DeviceContacts();
                deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(postAdd_SearchCompleted);
                deviceContacts.SearchAsync(task.FirstName + " " + task.LastName, FilterKind.DisplayName, task);
            }
            else if (e.TaskResult == TaskResult.Cancel)
            {

            }
        }
Ejemplo n.º 8
0
        // TODO: we need to be able to pass a search param in.
        public void search(string searchCriteria)
        {
            ContactSearchParams searchParams = JSON.JsonHelper.Deserialize<ContactSearchParams>(searchCriteria);

            DeviceContacts deviceContacts = new DeviceContacts();
            deviceContacts.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(contacts_SearchCompleted);

            // default is to search all fields
            FilterKind filterKind = FilterKind.None;
            // if only one field is specified, we will try the 3 available DeviceContact search filters
            if (searchParams.fields.Count() == 1)
            {
                if (searchParams.fields.Contains("name"))
                {
                    filterKind = FilterKind.DisplayName;
                }
                else if (searchParams.fields.Contains("emails"))
                {
                    filterKind = FilterKind.EmailAddress;
                }
                else if (searchParams.fields.Contains("phoneNumbers"))
                {
                    filterKind = FilterKind.PhoneNumber;
                }
            }

            try
            {
                deviceContacts.SearchAsync(searchParams.options.filter, filterKind, searchParams);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("search contacts exception :: " + ex.Message);
            }
        }
Ejemplo n.º 9
0
        public void search(string searchCriteria)
        {
            string[] args = JSON.JsonHelper.Deserialize <string[]>(searchCriteria);

            ContactSearchParams searchParams = new ContactSearchParams();

            try
            {
                searchParams.fields  = JSON.JsonHelper.Deserialize <string[]>(args[0]);
                searchParams.options = JSON.JsonHelper.Deserialize <SearchOptions>(args[1]);
            }
            catch (Exception)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_ARGUMENT_ERROR));
                return;
            }

            if (searchParams.options == null)
            {
                searchParams.options          = new SearchOptions();
                searchParams.options.filter   = "";
                searchParams.options.multiple = true;
            }
            else if (searchParams.options.filter == null)
            {
                searchParams.options.filter = "";
            }

            DeviceContacts deviceContacts = new DeviceContacts();

            deviceContacts.SearchCompleted += new EventHandler <ContactsSearchEventArgs>(contacts_SearchCompleted);

            // default is to search all fields
            FilterKind filterKind = FilterKind.None;

            // if only one field is specified, we will try the 3 available DeviceContact search filters
            if (searchParams.fields.Count() == 1)
            {
                if (searchParams.fields.Contains("name"))
                {
                    filterKind = FilterKind.DisplayName;
                }
                else if (searchParams.fields.Contains("emails"))
                {
                    filterKind = FilterKind.EmailAddress;
                }
                else if (searchParams.fields.Contains("phoneNumbers"))
                {
                    filterKind = FilterKind.PhoneNumber;
                }
            }

            try
            {
                deviceContacts.SearchAsync(searchParams.options.filter, filterKind, searchParams);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("search contacts exception :: " + ex.Message);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Searches if a there is a contact for whom the email is stored.
        /// </summary>
        /// <param name="email">email to use to filter the contacts.</param>
        private void FindContactByEmail(String email, String original)
        {
            Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
            contacts.SearchCompleted += contact_EmailSearchCompleted;

            contacts.SearchAsync(email, FilterKind.EmailAddress, original);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Searches if a there is a contact for whom the phone number is stored.
        /// </summary>
        /// <param name="number">phone number to use to filter the contacts.</param>
        private void FindContactByNumber(String number, String original)
        {
            Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
            contacts.SearchCompleted += contact_PhoneSearchCompleted;

            contacts.SearchAsync(number, FilterKind.PhoneNumber, original);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Public constructor.
        /// </summary>
        public ContactManager()
        {
            Microsoft.Phone.UserData.Contacts contacts = new Microsoft.Phone.UserData.Contacts();
            contacts.SearchCompleted += contacts_SearchCompleted;

            contacts.SearchAsync(String.Empty, FilterKind.None, "Phone Contacts");
        }
Ejemplo n.º 13
0
 private void BtnWriteBusinessCard_Click(object sender, RoutedEventArgs e)
 {
     SetStatusOutput(AppResources.LoadingFirstContact);
     var cons = new Microsoft.Phone.UserData.Contacts();
     cons.SearchCompleted += Contacts_SearchCompleted;
     cons.SearchAsync(String.Empty, FilterKind.None, "Contacts Import from Address Book");
 }
        void checkForDataChange()
        {
            try
            {
                bool update = false;

                if (appSettings.useBing)
                {
                    System.Diagnostics.Debug.WriteLine(DateTime.Now.Subtract(lastbing).Hours);

                    if (DateTime.Now.Subtract(lastbing).Hours > 6)
                    {
                        lastbing = DateTime.Now;
                        updateBingWallpaper();
                        bingUpdateStatePending = true;
                    }
                }


                if (bingUpdateStatePending)
                {
                    return;
                }

                if (appSettings.chkSMS)
                {
                    int count = 0;
                    instance.getUnreadSMSCount(out count);

                    if (count != lastSMSCount)
                    {
                        string data = instance.getLatestSMS();
                        lastSMSBody = data.Substring(data.IndexOf(":") + 1);
                        string number = data.Substring(0, data.IndexOf(":"));

                        Microsoft.Phone.UserData.Contacts cc = new Microsoft.Phone.UserData.Contacts();
                        cc.SearchCompleted += new EventHandler <Microsoft.Phone.UserData.ContactsSearchEventArgs>((object o, Microsoft.Phone.UserData.ContactsSearchEventArgs e) =>
                        {
                            if (e.Results.Count() > 0)
                            {
                                lastSMSFrom = e.Results.First().DisplayName;
                            }
                            else
                            {
                                lastSMSFrom = number;
                            }
                            updateWidgets();
                        });
                        cc.SearchAsync(number, Microsoft.Phone.UserData.FilterKind.PhoneNumber, null);

                        lastSMSCount = count;
                    }
                }

                if (appSettings.chkWeather)
                {
                    if (weatherdata == 1)
                    {
                        weatherdata = 0;

                        string query = "http://weather.yahooapis.com/forecastrss?w=" + appSettings.woeid + "&nocache=" + DateTime.Now.Millisecond.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Hour.ToString();

                        System.Diagnostics.Debug.WriteLine(query);

                        WebClient cl = new System.Net.WebClient();
                        cl.DownloadStringAsync(new Uri(query));
                        cl.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(cl_DownloadStringCompleted);

                        return;
                    }
                }


                if (counter > 400)
                {
                    updateWidgets();
                    counter = 1;
                    if (weatherdata == 0)
                    {
                        weatherdata = 1;
                    }
                }

                if (lastSMSCount == 0 && counter == 0 && appSettings.chkWeather == false) // first time thing
                {
                    updateWidgets();
                }

                counter++;
            }
            catch (Exception ex)
            {
                msgbox("Actual Exception in checkForDataChange(): " + ex.Message);
            }
        }
Ejemplo n.º 15
0
        private void DoSearch()
        {
            //ContactResultsLabel.Text = "results are loading...";
            ContactResultsData.DataContext = null;

            Microsoft.Phone.UserData.Contacts cons = new Microsoft.Phone.UserData.Contacts();

            cons.SearchCompleted += new EventHandler<ContactsSearchEventArgs>(Contacts_SearchCompleted);

            cons.SearchAsync(contactFilterString.Text, contactFilterKind, "Contacts Test #1");
        }
Ejemplo n.º 16
0
        // Searches in Contacts for display name and then the phonenumber/email
        void SearchContactInUserDataAsync(
            string filter,
            EventHandler <MowblyContactsSearchEventArgs> OnSearchCompleted,
            bool shouldIncludeW3ContactsInResults = false,
            FilterKind filterKind    = FilterKind.DisplayName,
            double limit             = 1,
            List <string> properties = null)
        {
            Microsoft.Phone.UserData.Contacts oContacts = new Microsoft.Phone.UserData.Contacts();

            EventHandler <ContactsSearchEventArgs> OnContactsSearchCompleted = null;

            OnContactsSearchCompleted = (object sender, ContactsSearchEventArgs e) =>
            {
                // If results are empty, try searching with other contact fields
                if (e.Results.Count() == 0)
                {
                    switch (e.FilterKind)
                    {
                    case FilterKind.PhoneNumber:
                        // Phonenumber failed. Search by Display name
                        oContacts.SearchAsync(e.Filter, FilterKind.DisplayName, e.State);
                        break;

                    case FilterKind.DisplayName:
                        // Display name failed. Search by email
                        oContacts.SearchAsync(e.Filter, FilterKind.EmailAddress, e.State);
                        break;

                    default:
                        // No results
                        // Unsubscribe
                        oContacts.SearchCompleted -= OnContactsSearchCompleted;

                        // Notify event handler - Error
                        OnSearchCompleted(this,
                                          new MowblyContactsSearchEventArgs(
                                              Mowbly.GetString(Constants.STRING_CONTACT_NOT_FOUND)));
                        break;
                    }
                }
                else
                {
                    // Unsubscribe
                    oContacts.SearchCompleted -= OnContactsSearchCompleted;

                    MowblyContactsSearchEventArgs eventArgs;

                    // Create W3Contacts - if requested
                    if (shouldIncludeW3ContactsInResults)
                    {
                        int numResults = 0;
                        List <W3Contact> w3Contacts = new List <W3Contact>();
                        foreach (Contact contact in e.Results)
                        {
                            w3Contacts.Add(new W3Contact(contact, properties));
                            numResults++;
                            if (limit == numResults)
                            {
                                break;
                            }
                        }

                        // Create EventArgs - with W3Contact list
                        eventArgs = new MowblyContactsSearchEventArgs(e.Results, w3Contacts);
                    }
                    else
                    {
                        // Create EventArgs - without W3Contact list
                        eventArgs = new MowblyContactsSearchEventArgs(e.Results);
                    }
                    // Notify event handler - Result
                    OnSearchCompleted(this, eventArgs);
                }
            };
            oContacts.SearchCompleted += new EventHandler <ContactsSearchEventArgs>(OnContactsSearchCompleted);
            // Start search
            oContacts.SearchAsync(filter, filterKind, null);
        }