/// <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(); } }
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); }
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(); } }
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)); } }