예제 #1
0
        /// <summary>
        /// Saves the contact to native store
        /// </summary>
        /// <returns>Unique contact id of the stored contact</returns>
        public async Task <string> SaveToNativeContactStore()
        {
            ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                ContactStoreSystemAccessMode.ReadWrite,
                ContactStoreApplicationAccessMode.ReadOnly);

            StoredContact contact = null;

            // Update contact if already exists
            if (!String.IsNullOrEmpty(Id))
            {
                contact = await contactStore.FindContactByIdAsync(Id);
            }
            if (contact == null)
            {
                contact = new StoredContact(contactStore);
            }

            // Set properties on stored contact
            await ToStoredContact(contact);

            // Save the contact
            await contact.SaveAsync();

            return(contact.Id);
        }
예제 #2
0
        /// <summary>
        /// Delete Contact
        /// </summary>
        /// <param name="id"></param>
        async private void DeleteContact(string id)
        {
            store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

            StoredContact contact = await store.FindContactByIdAsync(id);


            await store.DeleteContactAsync(id);
        }
예제 #3
0
        /// <summary>
        /// Remove Contact
        /// </summary>
        /// <param name="parameters"></param>
        async public void removeContact(string parameters)
        {
            // WP8 does not allow the editing of the contact.  Just return NOT AVAILABLE IN WINDOES PHONE 8 message
            string js = "javascript: var e = document.createEvent('Events');" +
                        "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=false;" +
                        "e.error='NOT AVAILABLE IN WINDOES PHONE 8';document.dispatchEvent(e);";

            //InjectJS("javascript:" + js);
            InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
            return;


            string[] args = WPCordovaClassLib.Cordova.JSON.JsonHelper.Deserialize <string[]>(parameters);

            string contactId = HttpUtility.UrlDecode(args[0]);

            if (busy == true)
            {
                js = "javascript: var e = document.createEvent('Events');" +
                     "e.initEvent('intel.xdk.contacts.busy',true,true);e.success=false;" +
                     "e.message='busy';document.dispatchEvent(e);";
                //InjectJS(js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                return;
            }

            try{
                ContactStore store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

                StoredContact contact = await store.FindContactByIdAsync(contactId);

                await store.DeleteContactAsync(contactId);

                getAllContacts();

                js = string.Format("var e = document.createEvent('Events');" +
                                   "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=true;" +
                                   "e.contactid='{0}';document.dispatchEvent(e);", contactId);
                //InjectJS("javascript: "+js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);

                busy = false;
            }
            catch (Exception e)
            {
                js = string.Format("var e = document.createEvent('Events');" +
                                   "e.initEvent('intel.xdk.contacts.remove',true,true);e.success=false;" +
                                   "e.error='contact not found';e.contactid='{0}';document.dispatchEvent(e);", contactId);
                //InjectJS("javascript: "+errjs);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);

                busy = false;
                return;
            }
        }
예제 #4
0
        /// <summary>
        /// Gets the list of changes in the local contact store since the specified revision number
        /// and generates an XML document that could be used to convey the changes to the app's web service
        /// </summary>
        /// <param name="revision">The revision number of the local store indicating which changes
        /// should be retrieved.</param>
        /// <returns></returns>
        public async Task GetChanges(ulong revision = 0)
        {
            Debug.WriteLine(String.Format("Getting changes since revision: {0}", revision));

            // Create a new XML document and add a root node.
            var doc = new XDocument();

            doc.Add(new XElement("LocalContacts"));

            // Call GetChangesAsync to get all changes since the specified revision.
            var changeList = await contactStore.GetChangesAsync(revision);

            foreach (var change in changeList)
            {
                // Each change record returned contains the change type, remote and local ids, and revision number
                Debug.WriteLine(String.Format("Change Type: {0}\nLocal ID: {1}\nRemote ID: {2}\nRevision Number: {3}",
                                              change.ChangeType.ToString(),
                                              change.Id,
                                              await remoteIdHelper.GetUntaggedRemoteId(contactStore, change.RemoteId),
                                              change.RevisionNumber));

                // Get the contact associated with the change record using the Id property.
                var contact = await contactStore.FindContactByIdAsync(change.Id);

                if (contact != null)
                {
                    // Create an xml element to represent the local contact

                    var changeElement = new XElement("Contact");
                    changeElement.Add(new XElement("RemoteId", await remoteIdHelper.GetUntaggedRemoteId(contactStore, contact.RemoteId)));
                    changeElement.Add(new XElement("GivenName", await remoteIdHelper.GetUntaggedRemoteId(contactStore, contact.GivenName)));
                    changeElement.Add(new XElement("FamilyName", await remoteIdHelper.GetUntaggedRemoteId(contactStore, contact.FamilyName)));
                    var props = await contact.GetPropertiesAsync();

                    foreach (var prop in props)
                    {
                        if (prop.Key != null)
                        {
                            Debug.WriteLine("Propt name " + prop.Key + " " + (string)prop.Value);
                            changeElement.Add(new XElement(prop.Key, (string)prop.Value));
                        }
                    }
                    Debug.WriteLine("Propt names done");
                    // Append the contact element to the document
                    doc.Root.Add(changeElement);
                }
            }
            xmlContactsFiledata = doc.ToString();
        }
예제 #5
0
        private async void GetContact(string id)
        {

            //通过联系人的Id获取联系人的信息
         
            //创建联系人存储
            conStore = await ContactStore.CreateOrOpenAsync();
            //查找联系人
            storCon = await conStore.FindContactByIdAsync(id);
            //获取联系人信息
            properties = await storCon.GetPropertiesAsync();
            name.Text = storCon.GivenName;
            telphone.Text = properties[KnownContactProperties.Telephone ].ToString();
           
        }
예제 #6
0
        async Task <Tuple <string, string> > GetSearchParamAndType(string id)
        {
            Tuple <string, string> result       = null;
            ContactStore           contactStore = await ContactStore.CreateOrOpenAsync(
                ContactStoreSystemAccessMode.ReadOnly,
                ContactStoreApplicationAccessMode.ReadOnly);

            StoredContact contact = await contactStore.FindContactByIdAsync(id);

            if (contact != null)
            {
                result = await SearchContactInUserDataAsync(contact.DisplayName);
            }

            return(result);
        }
예제 #7
0
        private async void GetContact(string id)
        {
            //通过联系人的Id获取联系人的信息

            //创建联系人存储
            conStore = await ContactStore.CreateOrOpenAsync();

            //查找联系人
            storCon = await conStore.FindContactByIdAsync(id);

            //获取联系人信息
            properties = await storCon.GetPropertiesAsync();

            name.Text     = storCon.GivenName;
            telphone.Text = properties[KnownContactProperties.Telephone].ToString();
        }
예제 #8
0
 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     if (NavigationContext.QueryString.Keys.Contains("id"))
     {
         id = NavigationContext.QueryString["id"];
     }
     contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);
     storedContact = await contactStore.FindContactByIdAsync(id);
     if (storedContact != null)
     {
         var properties = await storedContact.GetPropertiesAsync();
         if (properties.Keys.Contains(KnownContactProperties.FamilyName))
         {
             name.Text = properties[KnownContactProperties.FamilyName].ToString();
         }
         if (properties.Keys.Contains(KnownContactProperties.Telephone))
         {
             tel.Text = properties[KnownContactProperties.Telephone].ToString();
         }
     }
     base.OnNavigatedTo(e);
 }