private async void AddContact(Contact contact)
        {
            ContactStore contactstore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite);

            IReadOnlyList <ContactList> contactLists = await contactstore.FindContactListsAsync();

            ContactList lists2 = null;

            //if there is no contact list we create one
            if (contactLists.Count == 0)
            {
                try
                {
                    lists2 = await contactstore.CreateContactListAsync("MyList");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("1:\n" + ex.ToString());
                    Console.WriteLine(ex);
                }
            }
            //otherwise if there is one then we reuse it
            else
            {
                foreach (var c in contactLists)
                {
                    if (c.DisplayName == "MyList")
                    {
                        lists2 = c;
                        break;
                    }
                }
                if (lists2 == null)
                {
                    try
                    {
                        lists2 = await contactstore.CreateContactListAsync("MyList");
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show("2:\n" + ex.ToString());
                        AddContact2(contact);
                        return;
                    }
                }
            }

            if (lists2 != null)
            {
                await lists2.SaveContactAsync(contact);

                return;
            }
            else
            {
                MessageBox.Show("cannot find ContactList MyList!");
            }
        }
Example #2
0
        /// <summary>
        /// Check if contact exists
        /// </summary>
        /// <param name="user">User to check</param>
        /// <returns>True if the user does not exist</returns>
        private async Task <bool> CheckContact(User user)
        {
            // Intialize store if not done
            if (store == null)
            {
                store = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
            }

            if (store == null)
            {
                // Unavailable, call it quits
                return(true);
            }

            ContactList contactList;

            // Get contact lists for Discord
            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            if (contactLists.Count == 0)
            {
                contactList = await store.CreateContactListAsync("Discord");
            }
            else
            {
                contactList = contactLists[0];
            }

            // Get user
            var returnval = await contactList.GetContactFromRemoteIdAsync(user.Id);

            // If user is null, return true
            return(returnval != null);
        }
Example #3
0
        /// <summary>
        /// Load contact list
        /// </summary>
        /// <returns>Contact list</returns>
        private async Task <ContactList> GetContactList()
        {
            // If contact list is already determined, just return it
            if (contactList == null)
            {
                // Initialize contact store
                store = await Windows.ApplicationModel.Contacts.ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                if (store == null)
                {
                    // Unavailable, call it quits
                    return(null);
                }

                // Get contact list
                IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

                if (contactLists.Count == 0)
                {
                    contactList = await store.CreateContactListAsync("Discord");
                }
                else
                {
                    contactList = contactLists[0];
                }
            }

            // Return contact list
            return(contactList);
        }
        private async Task <ContactList> GetContactListAsync()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            // Find the contact list by name. (GetContactListAsync looks up a contact list by its ID.)
            IReadOnlyList <ContactList> lists = await store.FindContactListsAsync();

            ContactList sampleList = null;

            foreach (ContactList list in lists)
            {
                if (list.DisplayName == Constants.ContactListName)
                {
                    sampleList = list;
                    break;
                }
            }

            if (sampleList == null)
            {
                sampleList = await store.CreateContactListAsync(Constants.ContactListName);
            }

            return(sampleList);
        }
Example #5
0
        private async Task <ContactList> GetContactListAsync(UserDataAccount userDataAccount, ContactStore store)
        {
            try
            {
                var user        = _cacheService.GetUser(_cacheService.Options.MyId);
                var displayName = user?.GetFullName() ?? "Unigram";

                ContactList contactList = null;
                if (_cacheService.Options.TryGetValue("x_contact_list", out string id))
                {
                    contactList = await store.GetContactListAsync(id);
                }

                if (contactList == null)
                {
                    contactList = await store.CreateContactListAsync(displayName, userDataAccount.Id);

                    await _protoService.SendAsync(new Telegram.Td.Api.SetOption("x_contact_list", new Telegram.Td.Api.OptionValueString(contactList.Id)));
                }

                contactList.DisplayName         = displayName;
                contactList.OtherAppWriteAccess = ContactListOtherAppWriteAccess.None;
                await contactList.SaveAsync();

                return(contactList);
            }
            catch
            {
                return(null);
            }
        }
        private async void AddContact2(Contact contact)
        {
            ContactStore contactstore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            ContactList lists2 = null;

            try
            {
                lists2 = await contactstore.CreateContactListAsync("MyList");
            }
            catch (Exception ex)
            {
                MessageBox.Show("3:\n" + ex.ToString());
                Console.WriteLine(ex);
            }

            if (lists2 != null)
            {
                await lists2.SaveContactAsync(contact);

                return;
            }
            else
            {
                MessageBox.Show("4:\nAddContact2() list2 is null");
            }
        }
Example #7
0
        private async Task <ContactList> GetContactListAsync(ContactStore store)
        {
            ContactList contactList;
            var         contactsList = await store.FindContactListsAsync();

            if (contactsList.Count == 0)
            {
                contactList = await store.CreateContactListAsync("Unigram");

                contactList.OtherAppWriteAccess = ContactListOtherAppWriteAccess.None;
                await contactList.SaveAsync();
            }
            else
            {
                contactList = contactsList[0];

                if (contactList.OtherAppWriteAccess != ContactListOtherAppWriteAccess.None)
                {
                    contactList.OtherAppWriteAccess = ContactListOtherAppWriteAccess.None;
                    await contactList.SaveAsync();
                }
            }

            return(contactList);
        }
Example #8
0
        async Task <ObservableCollection <Contact> > GetContactsAsync()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            //find contact list
            ContactList contactlist = await store.CreateContactListAsync(Windows.ApplicationModel.Package.Current.DisplayName); //problem if it already exists

            ContactReader contactreader = contactlist.GetContactReader();
            ContactBatch  contactbatch  = await contactreader.ReadBatchAsync();

            return(new ObservableCollection <Contact>(contactbatch.Contacts)); // store.FindContactsAsync()
        }
        private async Task <ContactList> GetContactListAsync()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            ContactList sampleList = contactLists.FirstOrDefault(list => list.DisplayName.Equals(Constants.ContactListName));

            if (sampleList == null)
            {
                sampleList = await store.CreateContactListAsync(Constants.ContactListName);
            }

            return(sampleList);
        }
Example #10
0
        private async Task <ContactList> GetContactListAsync(ContactStore store)
        {
            ContactList contactList;
            var         contactsList = await store.FindContactListsAsync();

            if (contactsList.Count == 0)
            {
                contactList = await store.CreateContactListAsync("Unigram");
            }
            else
            {
                contactList = contactsList[0];
            }

            return(contactList);
        }
Example #11
0
        private async Task <bool> saveContactToAddressBook(JObject c)
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            string defaultListName = "myPrivateList";
            /* Search for lists in contact list */
            var lists = await store.FindContactListsAsync();

            ContactList list = lists.FirstOrDefault((x) => x.DisplayName == "myPrivateList");

            if (list == null)
            {
                list = await store.CreateContactListAsync(defaultListName);

                list.OtherAppReadAccess  = ContactListOtherAppReadAccess.Full;
                list.OtherAppWriteAccess = ContactListOtherAppWriteAccess.SystemOnly;
                await list.SaveAsync();
            }

            if (c["name"] != null)
            {
                Contact contact = new Contact();
                contact.Name = c.Value <string>("name");
                if (c["email"] != null)
                {
                    contact.Emails.Add(new ContactEmail()
                    {
                        Kind = ContactEmailKind.Work, Address = c.Value <string>("email")
                    });
                }
                if (c["phone"] != null)
                {
                    contact.Phones.Add(new ContactPhone()
                    {
                        Kind = ContactPhoneKind.Mobile, Number = c.Value <string>("phone")
                    });
                }
                await list.SaveContactAsync(contact);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #12
0
        async private void AddContact()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            var lists = await store.FindContactListsAsync();

            ContactList list = lists.FirstOrDefault((x) => x.DisplayName == "myPrivateList");

            if (list == null)
            {
                list = await store.CreateContactListAsync("myPrivateList");

                list.OtherAppReadAccess  = ContactListOtherAppReadAccess.Full;
                list.OtherAppWriteAccess = ContactListOtherAppWriteAccess.SystemOnly;
                await list.SaveAsync();
            }

            Contact contact = new Contact();

            contact.Name = "Ocio fast food";
            contact.Websites.Add(new ContactWebsite()
            {
                Description = "Sito web", RawValue = "https://www.facebook.com/ocioivrea/", Uri = new Uri("https://www.facebook.com/ocioivrea/")
            });
            contact.Addresses.Add(new ContactAddress()
            {
                StreetAddress = "Corso Nigra 67", Description = "Indirizzo", Country = "Italia", Kind = ContactAddressKind.Work, Locality = "Ivrea", PostalCode = "10015", Region = "TO"
            });

            var appInstalledFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
            var assets             = await appInstalledFolder.GetFolderAsync("Assets");

            var imageFile = await assets.GetFileAsync("StoreLogo.backup.png");

            contact.SourceDisplayPicture = imageFile;

            contact.Phones.Add(new ContactPhone()
            {
                Kind = ContactPhoneKind.Work, Number = PHONE_NUMBER
            });
            await list.SaveContactAsync(contact);

            var dialog = new MessageDialog("Contatto inserito. Grazie!");
            await dialog.ShowAsync();
        }
Example #13
0
        /// <summary>
        /// Get the ContactList for this app
        /// </summary>
        private async Task <ContactList> _GetContactListAsync()
        {
            // Get the contact store and the contact lists that are already present
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            // Find the contact list that belongs to this app
            ContactList contactList = contactLists.
                                      FirstOrDefault(p => p.DisplayName == cContactListName);

            // Create the contact list if it is not present
            if (contactList == null)
            {
                contactList = await store.CreateContactListAsync(cContactListName);
            }

            return(contactList);
        }
    private async Task <ContactList> GetAsync()
    {
        ContactList  result = null;
        ContactStore store  = await Store();

        if (store != null)
        {
            IReadOnlyList <ContactList> list = await store.FindContactListsAsync();

            if (list.Count == 0)
            {
                result = await store.CreateContactListAsync(contacts_list);
            }
            else
            {
                result = list.FirstOrDefault(s => s.DisplayName == contacts_list);
            }
        }
        return(result);
    }
Example #15
0
        private static async Task <ContactList> GetContactList()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            if (null == store)
            {
                return(null);
            }
            ContactList contactList;
            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            if (0 == contactLists.Count)
            {
                contactList = await store.CreateContactListAsync("AsusRouterList");
            }
            else
            {
                contactList = contactLists[0];
            }
            return(contactList);
        }
Example #16
0
        private async Task InitializeContactListAsync()
        {
            if (ContactStore == null)
            {
                throw new Exception("Unable to get contacts store");
            }

            var contactLists = await ContactStore.FindContactListsAsync();

            ContactList = (from c in contactLists where c.DisplayName == Constants.CONTACT_LIST_NAME select c).SingleOrDefault();

            if (ContactList == null)
            {
                ContactList = await ContactStore.CreateContactListAsync(Constants.CONTACT_LIST_NAME);

                ContactList.OtherAppReadAccess = ContactListOtherAppReadAccess.Limited;
                await ContactList.SaveAsync();
            }

            ContactList.ContactChanged += _contactList_ContactChanged;
            ContactList.ChangeTracker.Enable();
        }
        private async Task <ContactList> _GetContactList()
        {
            ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            if (null == store)
            {
                rootPage.NotifyUser("Unable to get a contacts store.", NotifyType.ErrorMessage);
                return(null);
            }

            ContactList contactList;
            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            if (0 == contactLists.Count)
            {
                contactList = await store.CreateContactListAsync("TestContactList");
            }
            else
            {
                contactList = contactLists[0];
            }

            return(contactList);
        }
Example #18
0
        private async void DoneContactClick(object sender, RoutedEventArgs e)
        {
            var contact = new Windows.ApplicationModel.Contacts.Contact();

            contact.FirstName = name;

            ContactEmail email = new ContactEmail();

            email.Address = mail;
            email.Kind    = ContactEmailKind.Other;
            contact.Emails.Add(email);

            ContactPhone phone = new ContactPhone();

            phone.Number = number;
            phone.Kind   = ContactPhoneKind.Mobile;
            contact.Phones.Add(phone);

            ContactStore store = await
                                 ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

            ContactList contactList;

            IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

            if (0 == contactLists.Count)
            {
                contactList = await store.CreateContactListAsync("TestContactList");
            }
            else
            {
                contactList = contactLists[0];
            }

            await contactList.SaveContactAsync(contact);
        }
Example #19
0
        public static async void SyncContacts()
        {
            ContactList contactList;

            //CleanUp
            {
                ContactStore store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);

                IReadOnlyList <ContactList> contactLists = await store.FindContactListsAsync();

                if (contactLists.Count > 0)
                {
                    await contactLists[0].DeleteAsync();
                }

                contactList = await store.CreateContactListAsync("Lite Messenger");
            }

            ContactAnnotationList annotationList;

            {
                ContactAnnotationStore annotationStore = await
                                                         ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);


                IReadOnlyList <ContactAnnotationList> annotationLists = await annotationStore.FindAnnotationListsAsync();

                if (annotationLists.Count > 0)
                {
                    await annotationLists[0].DeleteAsync();
                }

                annotationList = await annotationStore.CreateAnnotationListAsync();
            }


            String appId = "4a6ce7f5-f418-4ba8-8836-c06d77ab735d_g91sr9nghxvmm!App";

            foreach (var chatHeader in Names)
            {
                //if (chatHeader.IsGroup)
                //    continue;
                Contact contact = new Contact
                {
                    FirstName = chatHeader.Name,
                    RemoteId  = chatHeader.Href
                };
                await contactList.SaveContactAsync(contact);

                ContactAnnotation annotation = new ContactAnnotation
                {
                    ContactId           = contact.Id,
                    RemoteId            = chatHeader.Href,
                    SupportedOperations = ContactAnnotationOperations.Message
                };


                if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5))
                {
                    annotation.ProviderProperties.Add("ContactPanelAppID", appId);
                    annotation.SupportedOperations = ContactAnnotationOperations.Message | ContactAnnotationOperations.ContactProfile;
                }
                await annotationList.TrySaveAnnotationAsync(annotation);
            }
        }
        private async void AddContact(string firstName, string lastName)
        {
            /// https://docs.microsoft.com/en-us/windows/uwp/contacts-and-calendar/integrating-with-contacts
            /// https://stackoverflow.com/questions/34647386/windows-phone-10-is-possible-to-edit-add-new-contact-programmatically-in-wind

            ContactStore contactstore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadWrite);

            IReadOnlyList <ContactList> contactLists = await contactstore.FindContactListsAsync();


            ContactList lists2 = await contactstore.GetContactListAsync("24,d,d");

            if (lists2 != null)
            {
                var contact1 = new Contact();
                contact1.FirstName = firstName;
                contact1.LastName  = lastName;
                await lists2.SaveContactAsync(contact1);

                return;
            }


            ContactList contactList = null;

            //if there is no contact list we create one
            if (contactLists.Count == 0)
            {
                try
                {
                    contactList = await contactstore.CreateContactListAsync("MyList");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            //otherwise if there is one then we reuse it
            else
            {
                foreach (var c in contactLists)
                {
                    if (c.DisplayName == "MyList")
                    {
                        contactList = c;
                        break;
                    }
                }
            }

            var contact = new Contact();

            contact.FirstName = "Bob";
            contact.LastName  = "Doe";
            ContactEmail email = new ContactEmail();

            email.Address = "*****@*****.**";
            email.Kind    = ContactEmailKind.Other;
            contact.Emails.Add(email);
            await contactList.SaveContactAsync(contact);
        }