Пример #1
0
        private static async Task AddContact(RemoteContact remoteContact)
        {
            try
            {
                ContactStore store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

                var contact = new StoredContact(store);

                if (remoteContact.RemoteId == null)
                {
                    return;
                }

                var remoteIdHelper = new RemoteIdHelper();
                contact.RemoteId = await remoteIdHelper.GetTaggedRemoteId(store, remoteContact.RemoteId);

                IDictionary <string, object> props = await contact.GetPropertiesAsync();

                if (remoteContact.Email != null)
                {
                    props.Add(KnownContactProperties.Email, remoteContact.Email);
                }

                IDictionary <string, object> extprops = await contact.GetExtendedPropertiesAsync();

                if (remoteContact.CodeName != null)
                {
                    extprops.Add("Codename", remoteContact.CodeName);
                }

                if (remoteContact.DisplayName != null)
                {
                    contact.DisplayName = remoteContact.DisplayName + " " + remoteContact.GivenName;
                }

                var prop = await contact.GetPropertiesAsync();

                prop.Add(KnownContactProperties.MobileTelephone, "+1" + MdnGenerator(10));
                prop.Add(KnownContactProperties.JobTitle, JobTitleGenerator());
                prop.Add(KnownContactProperties.OfficeLocation, LocationGenerator());
                prop.Add(KnownContactProperties.Notes, JobTitleGenerator());

                Debug.WriteLine(contact.Store);

                await contact.SaveAsync();

                Debug.WriteLine(String.Format("Adding:\n{0}", remoteContact.ToString()));
            }

            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Пример #2
0
        public async void Emulate(string numberOfContacts)
        {
            try
            {
                for (var i = 0; i < int.Parse(numberOfContacts); i++)
                {
                    // Use this for the remote Id
                    // for each contact
                    var r        = new Random();
                    var remoteId = r.Next();

                    // Generate Random Names
                    var givenName   = Path.GetRandomFileName().Replace(".", "").Substring(0, 8);
                    var mail        = Path.GetRandomFileName().Replace(".", "").Substring(0, 10);
                    var familyName  = Path.GetRandomFileName().Replace(".", "").Substring(0, 4);
                    var displayName = Path.GetRandomFileName().Replace(".", "").Substring(0, 6);

                    var remoteContact = new RemoteContact
                    {
                        RemoteId    = remoteId.ToString(),
                        GivenName   = givenName,
                        FamilyName  = familyName,
                        DisplayName = displayName,
                        Email       = mail + "@gmail.com",
                        CodeName    = "R"
                    };

                    await AddContact(remoteContact);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                var messageDialog = new MessageDialog("Contacts Generation Complete");

                messageDialog.ShowAsync();
            }
        }