Пример #1
0
        /// <summary>
        /// Retrieve list of contacts from the store
        /// </summary>
        /// <param name="parameters"></param>
        async public void GetContactsFromStore(string parameters)
        {
            store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

            ContactQueryOptions options = new ContactQueryOptions();

            options.DesiredFields.Add(KnownContactProperties.Email);
            options.DesiredFields.Add(KnownContactProperties.Address);
            options.DesiredFields.Add(KnownContactProperties.Telephone);

            ContactQueryResult result = store.CreateContactQuery(options);

            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            string jsContacts = "AppMobi.people = [";

            foreach (StoredContact con in contacts)
            {
                IDictionary <string, object> temps = await con.GetPropertiesAsync();

                string displayName = "";
                Windows.Phone.PersonalInformation.ContactAddress address;
                string familyName = "";
                string givenName  = "";
                string email      = "";
                string telephone  = "";

                if (temps.ContainsKey("DisplayName"))
                {
                    displayName = (string)temps["DisplayName"];
                }

                if (temps.ContainsKey("Address"))
                {
                    address = (Windows.Phone.PersonalInformation.ContactAddress)temps["Address"];
                }

                if (temps.ContainsKey("FamilyName"))
                {
                    familyName = (string)temps["FamilyName"];
                }

                if (temps.ContainsKey("GivenName"))
                {
                    givenName = (string)temps["GivenName"];
                }

                if (temps.ContainsKey("Email"))
                {
                    email = (string)temps["Email"];
                }

                if (temps.ContainsKey("Telephone"))
                {
                    telephone = (string)temps["Telephone"];
                }
            }

            jsContacts += "];";
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// 获取联系人
        /// </summary>
        private async void GetContacts()
        {
            //创建联系人存储
            conStore = await ContactStore.CreateOrOpenAsync();

            //联系人查询的结果
            conQueryResult = conStore.CreateContactQuery();
            //联系人集合
            conList = await conQueryResult.GetContactsAsync();

            //显示联系人的集合

            List <Item> list = new List <Item>();

            foreach (StoredContact storCon in conList)
            {
                var properties = await storCon.GetPropertiesAsync();

                list.Add(new Item
                {
                    Name = storCon.GivenName,
                    Id   = storCon.Id
                });
            }
            conListBox.ItemsSource = list;
        }
Пример #4
0
        async private Task UpdateContact(string remoteId, string givenName, string familyName, string phone)
        {
            logger.debug("updating contact id={0} {1} {2} {3}", remoteId, givenName, familyName, phone);
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            string        taggedRemoteId = remoteId;
            StoredContact contact        = await store.FindContactByRemoteIdAsync(taggedRemoteId);

            if (contact != null)
            {
                logger.debug("contact id={0} exists in custom store, updating", remoteId);
                contact.GivenName  = givenName;
                contact.FamilyName = familyName;

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

                props[KnownContactProperties.MobileTelephone] = phone;

                await contact.SaveAsync();
            }
            else
            {
                await AddContact(remoteId, givenName, familyName, phone);
            }
        }
Пример #5
0
        public async Task <string> GetUserIdsMd5InStore()
        {
            logger.debug("Loading saved user ids...");
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            ContactQueryResult            result   = store.CreateContactQuery();
            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            List <int> userIds = new List <int>();

            foreach (var storedContact in contacts)
            {
                userIds.Add(int.Parse(storedContact.RemoteId));
            }

            userIds.Sort();
            string sortedStr = userIds.Aggregate("", (current, userId) => current + (userId + ","));

            if (sortedStr != "")
            {
                sortedStr = sortedStr.Substring(0, sortedStr.Length - 1);
                logger.debug("sorted str is {0}", sortedStr);
                return(MD5.GetMd5String(sortedStr));
            }

            return("");
        }
Пример #6
0
        private async void  GetContact(string p)
        {
            //创建联系人存储
            conStore = await ContactStore.CreateOrOpenAsync();

            //联系人查询结果
            ContactQueryResult conQueryResult = conStore.CreateContactQuery();
            //查询联系人
            IReadOnlyList <StoredContact> conList = await conQueryResult.GetContactsAsync();

            List <Item> list = new List <Item>();

            foreach (StoredContact strCon in conList)
            {
                if (strCon.GivenName.Contains(p))
                {
                    list.Add(new Item
                    {
                        Name = strCon.GivenName,
                        Id   = strCon.Id,
                    });
                }
            }
            conListBox.ItemsSource = list;
        }
Пример #7
0
        private async Task DoDeleteAllContactsAsync()
        {
            this._deleting = true;
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                await(await ContactStore.CreateOrOpenAsync()).DeleteAsync();
                await SocialManager.DeprovisionAsync();

                SavedContacts arg_1E1_0 = await this.GetSavedList();

                arg_1E1_0.SyncedDate = DateTime.MinValue;
                arg_1E1_0.SavedUsers.Clear();
                await this.EnsurePersistSavedContactsAsync();

                stopwatch.Stop();
                stopwatch = null;
            }
            catch (Exception var_4_272)
            {
                Logger.Instance.Error("ContactsManager failed to delete all contacts", var_4_272);
            }
            finally
            {
                int num = 0;
                if (num < 0)
                {
                    this._deleting = false;
                }
            }
        }
Пример #8
0
        private async Task DoDeleteAllContactsAsync()
        {
            this._deleting = true;
            try
            {
                Stopwatch sw = Stopwatch.StartNew();
                await(await ContactStore.CreateOrOpenAsync()).DeleteAsync();
                await SocialManager.DeprovisionAsync();

                SavedContacts savedList = await this.GetSavedList();

                DateTime dateTime = DateTime.MinValue;
                savedList.SyncedDate = dateTime;
                savedList.SavedUsers.Clear();
                await this.EnsurePersistSavedContactsAsync();

                sw.Stop();
                sw = (Stopwatch)null;
            }
            catch (Exception ex)
            {
                Logger.Instance.Error("ContactsManager failed to delete all contacts", ex);
            }
            finally
            {
                this._deleting = false;
            }
        }
Пример #9
0
        //async public void AddContactFromStore(string parameters)
        //{
        //    string[] tempParams = HttpUtility.UrlDecode(parameters).Split('~');

        //    string remoteId = tempParams[0];
        //    string givenName = tempParams[1];
        //    string familyName = tempParams[2];
        //    string street = tempParams[3];
        //    string city = tempParams[4];
        //    string state = tempParams[5];
        //    string zip = tempParams[6];
        //    string country = tempParams[7];
        //    string phone = tempParams[8];
        //    string email = tempParams[9];

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

        //    StoredContact contact = new StoredContact(store);

        //    RemoteIdHelper remoteIDHelper = new RemoteIdHelper();
        //    await remoteIDHelper.SetRemoteIdGuid(store);
        //    contact.RemoteId = await remoteIDHelper.GetTaggedRemoteId(store, remoteId);

        //    contact.GivenName = givenName;
        //    contact.FamilyName = familyName;

        //    string address = street + Environment.NewLine + city + ", " + state + " " + zip + Environment.NewLine + country;

        //    IDictionary<string, object> props = await contact.GetPropertiesAsync();
        //    props.Add(KnownContactProperties.Email, email);
        //    //props.Add(KnownContactProperties.Address, address);
        //    props.Add(KnownContactProperties.Telephone, phone);

        //    //IDictionary<string, object> extprops = await contact.GetExtendedPropertiesAsync();
        //    //extprops.Add("Codename", codeName);

        //    await contact.SaveAsync();
        //}

        #region Private methods
        async private void EditContact(string parameters)
        {
            string js = "";

            // WP8 does not allow the editing of the contact.  Just return NOT AVAILABLE IN WINDOES PHONE 8 message
            js = "javascript: var e = document.createEvent('Events');" +
                 "e.initEvent('intel.xdk.contacts.edit',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);

            getAllContacts();

            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("javascript:" + js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                return;
            }

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

                StoredContact contact = await store.FindContactByRemoteIdAsync(contactId);

                if (contact != null)
                {
                }
                else
                {
                    js = string.Format("javascript: var e = document.createEvent('Events');" +
                                       "e.initEvent('intel.xdk.contacts.edit',true,true);e.success=false;" +
                                       "e.error='contact not found';e.contactid='{0}';document.dispatchEvent(e);", contactId);
                    //InjectJS("javascript:" + js);
                    InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                    return;
                }
            }
            catch (Exception e)
            {
                js = string.Format("javascript: var e = document.createEvent('Events');" +
                                   "e.initEvent('intel.xdk.contacts.edit',true,true);e.success=false;" +
                                   "e.error='{0}';e.contactid='{1}';document.dispatchEvent(e);", e.Message, contactId);
                //InjectJS("javascript:" + js);
                InvokeCustomScript(new ScriptCallback("eval", new string[] { js }), true);
                return;
            }
        }
Пример #10
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);
        }
Пример #11
0
        public async static void ClearContactData()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            ContactStore store = await ContactStore.CreateOrOpenAsync();

            await store.DeleteAsync();

            await bindingManager.DeleteAllContactBindingsAsync();
        }
Пример #12
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);
            }
        }
Пример #13
0
        private static async void CleanContacts()
        {
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            ContactQueryResult            result   = store.CreateContactQuery();
            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            foreach (var contact in contacts)
            {
                await store.DeleteContactAsync(contact.Id);
            }
        }
        public static void ImportContactsAsync(IFileManager fileManager, ContactsOperationToken token, IList <TLUserBase> contacts, Action <Telegram.Api.WindowsPhone.Tuple <int, int> > progressCallback, System.Action cancelCallback)
        {
#if WP8
            Execute.BeginOnThreadPool(async() =>
            {
                //var contacts = _cacheService.GetContacts();
                var totalCount = contacts.Count;
                if (totalCount == 0)
                {
                    return;
                }


                var store           = await ContactStore.CreateOrOpenAsync();
                var importedCount   = 0;
                var delayedContacts = new TLVector <TLInt>();
                foreach (var contact in contacts)
                {
                    if (token.IsCanceled)
                    {
                        cancelCallback.SafeInvoke();
                        return;
                    }

                    try
                    {
                        var delayedContact = await UpdateContactInternalAsync(contact, fileManager, store, true);
                        if (delayedContact != null)
                        {
                            delayedContacts.Add(delayedContact.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        // continue import after failed contact
                    }
                    //Thread.Sleep(100);
                    importedCount++;
                    progressCallback.SafeInvoke(new Telegram.Api.WindowsPhone.Tuple <int, int>(importedCount, totalCount));
                    //var duration = importedCount == totalCount ? 0.5 : 2.0;
                    //_mtProtoService.SetMessageOnTime(duration, string.Format("Sync contacts ({0} of {1})...", importedCount, totalCount));
                }

                var result = new TLVector <TLInt>();
                foreach (var delayedContact in delayedContacts)
                {
                    result.Add(delayedContact);
                }
                SaveDelayedContactsAsync(result);
            });
#endif
        }
Пример #15
0
        public static async Task <IReadOnlyList <StoredContact> > GetContactsFromPhoneAsync(CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            token.ThrowIfCancellationRequested();
            ContactQueryResult result = store.CreateContactQuery();

            token.ThrowIfCancellationRequested();
            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            token.ThrowIfCancellationRequested();
            return(contacts);
        }
Пример #16
0
        public async void CreateContactBindingsAsync()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            // Simulate call to web service
            TraktProfile[] profiles = await userDao.getUserFriends();

            ContactStore store = await ContactStore.CreateOrOpenAsync();

            foreach (TraktProfile profile in profiles)
            {
                ContactBinding myBinding = bindingManager.CreateContactBinding(profile.Username);

                if (!String.IsNullOrEmpty(profile.Name))
                {
                    if (profile.Name.Contains(" "))
                    {
                        Regex    regex     = new Regex(@"\s");
                        String[] nameSplit = regex.Split(profile.Name);

                        myBinding.FirstName = nameSplit[0];
                        myBinding.LastName  = nameSplit[1];
                    }
                    else
                    {
                        myBinding.LastName = profile.Name;
                    }
                }

                try
                {
                    if (!String.IsNullOrEmpty(profile.Name) && profile.Name.Contains(" "))
                    {
                        Regex    regex     = new Regex(@"\s");
                        String[] nameSplit = regex.Split(profile.Name);

                        AddContact(profile.Username, nameSplit[0], nameSplit[1], profile.Username, profile.Avatar, profile.Url);
                    }
                    else
                    {
                        AddContact(profile.Username, "", "", profile.Username, profile.Avatar, profile.Url);
                    }
                    await bindingManager.SaveContactBindingAsync(myBinding);
                }
                catch (Exception e)
                {
                    Console.Write(e.InnerException);
                }
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            store = await ContactStore.CreateOrOpenAsync(   // initally created with default parameters
                ContactStoreSystemAccessMode.ReadWrite,
                ContactStoreApplicationAccessMode.ReadOnly);

            if (NavigationContext.QueryString.ContainsKey("givenName") &&
                NavigationContext.QueryString.ContainsKey("familyName"))
            {
                string givenName  = NavigationContext.QueryString["givenName"];
                string familyName = NavigationContext.QueryString["familyName"];
                FindAndLoadContact(givenName, familyName);
            }
        }
Пример #18
0
        /// <summary>
        /// Creates a contact store and add contacts.
        /// </summary>
        public static async void CreateContactStore()
        {
            ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                ContactStoreSystemAccessMode.ReadWrite,
                ContactStoreApplicationAccessMode.ReadOnly);

            foreach (SampleContact sampleContact in SampleContact.CreateSampleContacts())
            {
                StoredContact contact = new StoredContact(contactStore);
                IDictionary <string, object> props = await contact.GetPropertiesAsync();

                if (!string.IsNullOrEmpty(sampleContact.FirstName))
                {
                    props.Add(KnownContactProperties.GivenName, sampleContact.FirstName);
                }

                if (!string.IsNullOrEmpty(sampleContact.LastName))
                {
                    props.Add(KnownContactProperties.FamilyName, sampleContact.LastName);
                }

                if (!string.IsNullOrEmpty(sampleContact.HomeEmail))
                {
                    props.Add(KnownContactProperties.Email, sampleContact.HomeEmail);
                }

                if (!string.IsNullOrEmpty(sampleContact.WorkEmail))
                {
                    props.Add(KnownContactProperties.WorkEmail, sampleContact.WorkEmail);
                }

                if (!string.IsNullOrEmpty(sampleContact.HomePhone))
                {
                    props.Add(KnownContactProperties.Telephone, sampleContact.HomePhone);
                }

                if (!string.IsNullOrEmpty(sampleContact.WorkPhone))
                {
                    props.Add(KnownContactProperties.CompanyTelephone, sampleContact.WorkPhone);
                }

                if (!string.IsNullOrEmpty(sampleContact.MobilePhone))
                {
                    props.Add(KnownContactProperties.MobileTelephone, sampleContact.MobilePhone);
                }

                await contact.SaveAsync();
            }
        }
Пример #19
0
        public static async void Save(string givenName, string familyName, string mobile)
        {
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            StoredContact contact = new StoredContact(store);

            contact.GivenName  = givenName;
            contact.FamilyName = familyName;

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

            props.Add(KnownContactProperties.MobileTelephone, mobile);

            await contact.SaveAsync();
        }
Пример #20
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);
        }
Пример #21
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();
        }
        public static void DeleteContactAsync(IStateService stateService, TLInt userId)
        {
#if WP8
            Telegram.Api.Helpers.Execute.BeginOnThreadPool(() =>
                                                           stateService.GetNotifySettingsAsync(
                                                               async settings =>
            {
                if (settings.PeopleHub)
                {
                    var store        = await ContactStore.CreateOrOpenAsync();
                    var phoneContact = await store.FindContactByRemoteIdAsync(userId.ToString());
                    await store.DeleteContactAsync(phoneContact.Id);
                }
            }));
#endif
        }
Пример #23
0
        public async Task AddContact(string remoteId, string givenName, string familyName, string phone)
        {
            logger.debug("adding contact id={0} {1} {2} {3}", remoteId, givenName, familyName, phone);
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            StoredContact contact = new StoredContact(store);

            contact.RemoteId   = remoteId;
            contact.GivenName  = givenName;
            contact.FamilyName = familyName;
            // TODO: picture sync

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

            props.Add(KnownContactProperties.MobileTelephone, phone);

            await contact.SaveAsync();
        }
        private async void GetFriends()
        {
            ContactStore store = await ContactStore.CreateOrOpenAsync();

            ContactQueryResult result = store.CreateContactQuery();



            IReadOnlyList <StoredContact> contacts = await result.GetContactsAsync();

            friendList.Clear();

            foreach (var storedContact in contacts)
            {
                UserModel user = TelegramSession.Instance.GetUser(int.Parse(storedContact.RemoteId));
                friendList.Add(user);
            }
        }
Пример #25
0
        private async Task <bool> ProcessConnectData(DownloadRichConnectDataOperation downloadRichConnectDataOperation)
        {
            ContactBindingManager store = await ContactBindings.GetAppContactBindingManagerAsync();

            ContactStore contactStore = await ContactStore.CreateOrOpenAsync();

            foreach (string id in (IEnumerable <string>)downloadRichConnectDataOperation.Ids)
            {
                string remoteId = id;
                try
                {
                    string         title          = (await contactStore.FindContactByRemoteIdAsync(remoteId)).DisplayName;
                    ContactBinding contactBinding = await store.GetContactBindingByRemoteIdAsync(remoteId);

                    ConnectTileData connectTileData = new ConnectTileData();
                    connectTileData.Title = title;
                    BackendResult <PhotosListWithCount, ResultCode> profilePhotos = await PhotosService.Current.GetProfilePhotos(RemoteIdHelper.GetItemIdByRemoteId(remoteId), 0, 3);

                    if (profilePhotos.ResultCode == ResultCode.Succeeded)
                    {
                        for (int index = 0; index < Math.Min(3, profilePhotos.ResultData.response.Count); ++index)
                        {
                            Photo            photo            = profilePhotos.ResultData.response[index];
                            ConnectTileImage connectTileImage = new ConnectTileImage();
                            connectTileImage.ImageUrl = photo.src_big;
                            ((ICollection <ConnectTileImage>)connectTileData.Images).Add(connectTileImage);
                        }
                    }
                    contactBinding.TileData = connectTileData;
                    await store.SaveContactBindingAsync(contactBinding);

                    title           = null;
                    contactBinding  = null;
                    connectTileData = null;
                }
                catch (Exception ex)
                {
                    Logger.Instance.Error("ProcessConnectData failed", ex);
                }
                remoteId = null;
            }
            return(true);
        }
Пример #26
0
        private async void bt_add_Click(object sender, RoutedEventArgs e)
        {
            //创建一个系统通信可以读写和其他程序制度的联系人存储
            ContactStore conStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly);

            //新增联系人
            ContactInformation conInfo = new ContactInformation();
            //获取ContacInformation类的属性map表
            var properties = await conInfo.GetPropertiesAsync();

            //添加电话属性
            properties.Add(KnownContactProperties.FamilyName, "test");
            properties.Add(KnownContactProperties.Telephone, "123456789");

            //创建联系人对象
            StoredContact storedContact = new StoredContact(conStore, conInfo);
            //获取安装包的一张图片文件用作联系人的头像
            StorageFile imagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets/1.jpeg");


            ///设置头像,将图片数据转化成Stream对象,在转化成IInputStream对象。
            //打开文件的可读数据流
            Stream stream = await imagefile.OpenStreamForReadAsync();

            //用Stream对象转化成为IIputStream对象
            IInputStream inputStream = stream.AsInputStream();
            //用IInputStream 对象设置为联系人头像
            await storedContact.SetDisplayPictureAsync(inputStream);

            //保存联系人
            await storedContact.SaveAsync();

            ///获取头像,接收到的图片数据为IRandomAccessStream类型,如果要展示出来,需要创建一个BitmapImage对象,
            IRandomAccessStream raStream = await storedContact.GetDisplayPictureAsync();

            BitmapImage bi = new BitmapImage();

            bi.SetSource(raStream);
            image.Source = bi;
        }
Пример #27
0
        /// <summary>
        /// 获取联系人列表
        /// </summary>
        private async void GetContacts()
        {
            conStore = await ContactStore.CreateOrOpenAsync();

            ContactQueryResult conQueryResult = conStore.CreateContactQuery();
            //查询联系人
            IReadOnlyList <StoredContact> conList = await conQueryResult.GetContactsAsync();

            List <Item> list = new List <Item>();

            foreach (StoredContact storCon in conList)
            {
                var properties = await storCon.GetPropertiesAsync();

                list.Add(new Item
                {
                    Name = storCon.GivenName,
                    Id   = storCon.Id,
                });
            }
            conListBox.ItemsSource = list;
        }
        public static void DeleteContactsAsync(System.Action callback)
        {
#if WP8
            Telegram.Api.Helpers.Execute.BeginOnThreadPool(
                async() =>
            {
                var store = await ContactStore.CreateOrOpenAsync();
                try
                {
                    await store.DeleteAsync();
                    FileUtils.Delete(_delayedContactsSyncRoot, Constants.DelayedContactsFileName);
                }
                catch (Exception ex)
                {
                    Telegram.Api.Helpers.Execute.ShowDebugMessage("store.DeleteAsync ex " + ex);
                }
                finally
                {
                    callback.SafeInvoke();
                }
            });
#endif
        }
        public static void CreateContactAsync(IFileManager fileManager, IStateService stateService, TLUserBase contact)
        {
#if WP8
            Telegram.Api.Helpers.Execute.BeginOnThreadPool(() =>
                                                           stateService.GetNotifySettingsAsync(
                                                               async settings =>
            {
                if (settings.PeopleHub)
                {
                    var store          = await ContactStore.CreateOrOpenAsync();
                    var delayedContact = await UpdateContactInternalAsync(contact, fileManager, store, true);
                    if (delayedContact != null)
                    {
                        GetDelayedContactsAsync(contacts =>
                        {
                            contacts.Add(delayedContact.Id);
                            SaveDelayedContactsAsync(contacts);
                        });
                    }
                }
            }));
#endif
        }
Пример #30
0
        private async void Save_Click(object sender, RoutedEventArgs e)
        {
            string message = "";

            if (name.Text != "" && telphone.Text != "")
            {
                try
                {
                    //创建一个联系人的信息对象
                    ContactInformation conInfo = new ContactInformation();
                    //获取联系人的属性字典
                    var properties = await conInfo.GetPropertiesAsync();

                    //添加联系人的属性
                    properties.Add(KnownContactProperties.GivenName, name.Text);
                    properties.Add(KnownContactProperties.Telephone, telphone.Text);
                    //创建或者打开联系人存储
                    ContactStore conStore = await ContactStore.CreateOrOpenAsync();

                    StoredContact storedContact = new StoredContact(conStore, conInfo);
                    //保存联系人
                    await storedContact.SaveAsync();

                    message = "保存成功";
                }
                catch (Exception ex)
                {
                    message = "保存失败,错误信息:" + ex.Message;
                }
            }
            else
            {
                message = "名字或电话不能为空";
            }
            await new MessageDialog(message).ShowAsync();
            (Window.Current.Content as Frame).Navigate(typeof(ContactsList));
        }