Esempio n. 1
0
        public static List<ContactBinding> GetContactsFromWebServiceAsync()
        {
            List<ContactBinding> output = new List<ContactBinding>();

            // For this sample, we get the contacts from a local file
            XDocument xmldoc = XDocument.Load("RemoteContactStore.xml");

            if (xmldoc != null)
            {
                var contactElements = xmldoc.Descendants("Contact");

                foreach (var el in contactElements)
                {
                    ContactBinding contactBinding = new ContactBinding();
                    contactBinding.RemoteId = el.Element("RemoteId") != null ? el.Element("RemoteId").Value : null;


                    contactBinding.GivenName = el.Element("GivenName") != null ? el.Element("GivenName").Value : null;
                    contactBinding.FamilyName = el.Element("FamilyName") != null ? el.Element("FamilyName").Value : null;
                    contactBinding.Email = el.Element("Email") != null ? el.Element("Email").Value : null;
                    contactBinding.CodeName = el.Element("CodeName") != null ? el.Element("CodeName").Value : null;

                    output.Add(contactBinding);
                }
            }

            return output;
        }
Esempio n. 2
0
        public static List <ContactBinding> GetContactsFromWebServiceAsync()
        {
            List <ContactBinding> output = new List <ContactBinding>();

            // For this sample, we get the contacts from a local file
            XDocument xmldoc = XDocument.Load("RemoteContactStore.xml");

            if (xmldoc != null)
            {
                var contactElements = xmldoc.Descendants("Contact");

                foreach (var el in contactElements)
                {
                    ContactBinding contactBinding = new ContactBinding();
                    contactBinding.RemoteId = el.Element("RemoteId") != null?el.Element("RemoteId").Value : null;


                    contactBinding.GivenName = el.Element("GivenName") != null?el.Element("GivenName").Value : null;

                    contactBinding.FamilyName = el.Element("FamilyName") != null?el.Element("FamilyName").Value : null;

                    contactBinding.Email = el.Element("Email") != null?el.Element("Email").Value : null;

                    contactBinding.CodeName = el.Element("CodeName") != null?el.Element("CodeName").Value : null;

                    output.Add(contactBinding);
                }
            }

            return(output);
        }
        private async Task CreateContactBindingsAsync()
        {
            ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

            // Simulate call to web service
            List <ServerApi.ContactBinding> bindings = ServerApi.GetContactsFromWebServiceAsync();

            foreach (ServerApi.ContactBinding binding in bindings)
            {
                ContactBinding myBinding = bindingManager.CreateContactBinding(binding.RemoteId);

                // This information is not displayed on the Contact Page in the People Hub app, but
                // is used to automatically link the contact binding with existent phone contacts.
                // Add as much information as possible for the ContactBinding to increase the
                // chances to find a matching Contact on the phone.
                myBinding.FirstName     = binding.GivenName;
                myBinding.LastName      = binding.FamilyName;
                myBinding.EmailAddress1 = binding.Email;
                myBinding.Name          = binding.CodeName;

                // Don't crash if one binding fails, log the error and continue saving
                try
                {
                    await bindingManager.SaveContactBindingAsync(myBinding);
                }
                catch (Exception e)
                {
                    Logger.Log("MainPage", "Binding (" + binding.RemoteId + ") failed to save. " + e.Message);
                }
            }
        }
        /// <summary>
        /// Because the app writes contact bindings the agent will be invoked on a per need basis
        /// (e.g.: the user opens a contact an swipes to the "Connect" pivot). On invocation, the agent is
        /// requested to write the ConnectTile information.
        /// </summary>
        /// <param name="operation">The operation that we need to perform</param>
        private async Task ProcessOperationAsync(DownloadRichConnectDataOperation operation)
        {
            Logger.Log("Agent", "DownloadRichConnectDataOperation Ids=(" + string.Join(",", operation.Ids) + ")");

            try
            {
                await Helpers.ParallelForEach(operation.Ids, async (string remoteId) =>
                {
                    Logger.Log("Agent", "Start sync for id = " + remoteId);
                    ContactBinding binding      = await contactBindingManager.GetContactBindingByRemoteIdAsync(remoteId);
                    ServerApi.TileData tileData = await ServerApi.GetTileDataFromWebServiceAsync(remoteId);
                    binding.TileData            = new ConnectTileData();
                    binding.TileData.Title      = tileData.Title;
                    foreach (IRandomAccessStream stream in tileData.Images)
                    {
                        ConnectTileImage image = new ConnectTileImage();
                        await image.SetImageAsync(stream);
                        binding.TileData.Images.Add(image);
                    }
                    await contactBindingManager.SaveContactBindingAsync(binding);
                    Logger.Log("Agent", "Finish sync for id = " + remoteId);
                });
            }
            catch (Exception e)
            {
                Helpers.HandleException(e);
            }
            finally
            {
                Logger.Log("Agent", "DownloadRichConnectDataOperation Ids=(" + string.Join(",", operation.Ids) + ") - completed");
                operation.SafeNotifyCompletion();
            }
        }
Esempio n. 5
0
        async void EntityList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (EntityList.SelectedItem != null)
            {
                ContactBinding entity = EntityList.SelectedItem as ContactBinding;
                await contactBindingManager.CreateContactBindingTileAsync(bindingId, entity);

                System.Diagnostics.Debug.WriteLine(string.Format("Bound [{0}] to entity with name [{1}]", bindingId, entity.Name));

                NavigationService.Navigate(new Uri(string.Format("/MainPage.xaml?action=Show_Contact&contact_ids={0}", entity.RemoteId), UriKind.Relative));
            }
        }
Esempio n. 6
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);
                }
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
0
        private async Task ProcessOperationAsync(DownloadRichConnectDataOperation operation)
        {
            try
            {
                await ParallelForEach(operation.Ids, async (string remoteId) =>
                {
                    if (remoteId.Contains(","))
                    {
                        remoteId = remoteId.Split(',')[0];
                    }


                    ContactBinding binding = await contactBindingManager.GetContactBindingByRemoteIdAsync(remoteId);
                    TraktProfile tileData  = await new UserController().GetUserProfile(remoteId);

                    binding.TileData       = new ConnectTileData();
                    binding.TileData.Title = tileData.Username;

                    ConnectTileImage tileImage  = new ConnectTileImage();
                    HttpWebRequest request      = (HttpWebRequest)WebRequest.Create(new Uri(tileData.Avatar));
                    HttpWebResponse webResponse = await request.GetResponseAsync() as HttpWebResponse;
                    MemoryStream memoryStream   = new MemoryStream();
                    webResponse.GetResponseStream().CopyTo(memoryStream);
                    IRandomAccessStream stream = await ConvertToRandomAccessStream(memoryStream);
                    await tileImage.SetImageAsync(stream);

                    binding.TileData.Images.Add(tileImage);

                    await contactBindingManager.SaveContactBindingAsync(binding);
                });
            }
            catch (Exception e)
            {
            }
            finally
            {
                NotifyComplete();
            }
        }
Esempio n. 9
0
        private async void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            ListItemViewModel model = (ListItemViewModel)((Grid)sender).DataContext;

            String id;

            NavigationContext.QueryString.TryGetValue("id", out id);

            if (!String.IsNullOrEmpty(id))
            {
                ContactBindingManager bindingManager = await ContactBindings.GetAppContactBindingManagerAsync();

                ContactBinding entity = await bindingManager.GetContactBindingByRemoteIdAsync(model.Name);;

                await bindingManager.CreateContactBindingTileAsync(id, entity);

                NavigationService.Navigate(new Uri("/Friend.xaml?friendid=" + model.Name + "&assigned=true" + "&isKnown=true", UriKind.Relative));
            }
            else
            {
                Animation.NavigateToFadeOut(this, LayoutRoot, new Uri("/Friend.xaml?friendid=" + model.Name + "&isKnown=true", UriKind.Relative));
            }
        }