private async void Delete_Click(object sender, RoutedEventArgs e) { if (_list.SelectedItem is DriveItem driveItem) { try { MessageDialog confirmDialog = new MessageDialog(DeleteConfirmMessage); confirmDialog.Commands.Add(new UICommand(DeleteConfirmOkMessage, cmd => { }, commandId: 0)); confirmDialog.Commands.Add(new UICommand(DeleteConfirmCancelMessage, cmd => { }, commandId: 1)); confirmDialog.DefaultCommandIndex = 0; confirmDialog.CancelCommandIndex = 1; IUICommand result = await confirmDialog.ShowAsync(); if ((int)result.Id == 0) { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { await graphClient.Drives[_driveId].Items[driveItem.Id].Request().DeleteAsync(); string driveItemId = _driveItemPath.Peek()?.Id; await LoadFilesAsync(driveItemId); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } } }
private async void Share_Click(object sender, RoutedEventArgs e) { if (_list.SelectedItem is DriveItem driveItem) { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { Permission link = await graphClient.Drives[_driveId].Items[driveItem.Id].CreateLink("view", "organization").Request().PostAsync(); MessageDialog dialog = new MessageDialog(link.Link.WebUrl, ShareLinkCopiedMessage); DataPackage package = new DataPackage(); package.SetText(link.Link.WebUrl); Clipboard.SetContent(package); await dialog.ShowAsync(); } } catch (Exception exception) { MessageDialog dialog = new MessageDialog(exception.Message); await dialog.ShowAsync(); } } }
private async void Add_Click(object sender, RoutedEventArgs e) { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null && !string.IsNullOrWhiteSpace(_input?.Text)) { PlannerTask task = new PlannerTask { Title = _input.Text }; if (TaskType != TaskTypeAllTasksId && TaskType != TaskTypeClosedTasksId) { task.BucketId = TaskType; } task.PlanId = PlanId; _input.Text = string.Empty; CanAddTask = false; PlannerTask taskCreated = await graphClient.Planner.Tasks.Request().AddAsync(task); PlannerPlan plan = Plans.FirstOrDefault(s => s.Id == InternalPlanId); PlannerTaskViewModel taskViewModel = new PlannerTaskViewModel(taskCreated); Dictionary <string, string> buckets = Buckets.ToDictionary(s => s.Id, s => s.Name); if (plan != null) { taskViewModel.GroupId = plan.Owner; } if (!string.IsNullOrEmpty(taskViewModel.BucketId) && buckets.ContainsKey(taskViewModel.BucketId)) { taskViewModel.BucketName = buckets[taskViewModel.BucketId]; } if (taskCreated.PlanId == InternalPlanId) { taskViewModel.PropertyChanged += TaskViewModel_PropertyChanged; _allTasks.Add(taskViewModel); Tasks.Insert(0, taskViewModel); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } CanAddTask = true; }
private async Task LoadAllTasksAsync() { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { IPlannerPlanTasksCollectionPage tasks = await graphClient.Planner.Plans[PlanId].Tasks.Request().GetAsync(); Dictionary <string, string> buckets = Buckets.ToDictionary(s => s.Id, s => s.Name); List <PlannerTaskViewModel> taskList = new List <PlannerTaskViewModel>(); PlannerPlan plan = Plans.FirstOrDefault(s => s.Id == InternalPlanId); while (true) { foreach (PlannerTask task in tasks) { PlannerTaskViewModel taskViewModel = new PlannerTaskViewModel(task); if (plan != null) { taskViewModel.GroupId = plan.Owner; } taskViewModel.PropertyChanged += TaskViewModel_PropertyChanged; await GetAssignmentsAsync(taskViewModel, graphClient); if (!string.IsNullOrEmpty(taskViewModel.BucketId) && buckets.ContainsKey(taskViewModel.BucketId)) { taskViewModel.BucketName = buckets[taskViewModel.BucketId]; } taskList.Add(taskViewModel); } if (tasks.NextPageRequest == null) { break; } tasks = await tasks.NextPageRequest.GetAsync(); } _allTasks.Clear(); _allTasks.AddRange(taskList); LoadTasks(); } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async Task InitPlanAsync() { try { ClearTasks(); GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { IPlannerPlanBucketsCollectionPage buckets = await graphClient.Planner.Plans[PlanId].Buckets.Request().GetAsync(); List <PlannerBucket> bucketList = new List <PlannerBucket>(); while (true) { foreach (PlannerBucket bucket in buckets) { bucketList.Add(bucket); } if (buckets.NextPageRequest == null) { break; } buckets = await buckets.NextPageRequest.GetAsync(); } TaskFilterSource.Clear(); Buckets.Clear(); TaskFilterSource.Add(new PlannerBucket { Id = TaskTypeAllTasksId, Name = AllTasksLabel }); foreach (PlannerBucket bucket in bucketList) { Buckets.Add(bucket); TaskFilterSource.Add(bucket); } TaskFilterSource.Add(new PlannerBucket { Id = TaskTypeClosedTasksId, Name = ClosedTasksLabel }); TaskType = TaskTypeAllTasksId; await LoadAllTasksAsync(); } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async Task InitDriveAsync(string driveUrl) { try { string realDriveURL; if (driveUrl.StartsWith("https://graph.microsoft.com/", StringComparison.CurrentCultureIgnoreCase)) { realDriveURL = driveUrl; } else { realDriveURL = await GetDriveUrlFromSharePointUrlAsync(driveUrl); } GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, realDriveURL); await graphClient.AuthenticationProvider.AuthenticateRequestAsync(message); HttpResponseMessage result = await graphClient.HttpProvider.SendAsync(message); if (result.StatusCode == HttpStatusCode.OK) { string json = await result.Content.ReadAsStringAsync(); Drive drive = JsonConvert.DeserializeObject <Drive>(json); if (drive != null) { _driveId = drive.Id; _driveName = drive.Name; _driveItemPath.Clear(); DriveItem rootDriveItem = await graphClient.Drives[_driveId].Root.Request().GetAsync(); _driveItemPath.Push(rootDriveItem); UpdateCurrentPath(); await LoadFilesAsync(rootDriveItem.Id); BackButtonVisibility = Visibility.Collapsed; } } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async void Upload_Click(object sender, RoutedEventArgs e) { try { ErrorMessage = string.Empty; FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add("*"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { string driveItemId = _driveItemPath.Peek()?.Id; using (Stream inputStream = await file.OpenStreamForReadAsync()) { if (inputStream.Length < 1024 * 1024 * 4) { FileUploading++; StatusMessage = string.Format(UploadingFilesMessageTemplate, FileUploading); VisualStateManager.GoToState(this, UploadStatusUploading, false); try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { await graphClient.Drives[_driveId].Items[driveItemId].ItemWithPath(file.Name).Content.Request().PutAsync <DriveItem>(inputStream, _cancelUpload.Token); VisualStateManager.GoToState(this, UploadStatusNotUploading, false); FileUploading--; } } catch (Exception ex) { FileUploading--; ErrorMessage = ex.Message; VisualStateManager.GoToState(this, UploadStatusError, false); } await LoadFilesAsync(driveItemId); } } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private static async void DriveUrlPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (MicrosoftGraphService.Instance.IsAuthenticated) { SharePointFileList control = d as SharePointFileList; GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null && !string.IsNullOrWhiteSpace(control.DriveUrl)) { if (Uri.IsWellFormedUriString(control.DriveUrl, UriKind.Absolute)) { await control.InitDriveAsync(control.DriveUrl); } } } }
/// <summary> /// Retrieves an appropriate Drive URL from a SharePoint document library root URL /// </summary> /// <param name="rawDocLibUrl">Raw URL for SharePoint document library</param> /// <returns>Drive URL</returns> public async Task <string> GetDriveUrlFromSharePointUrlAsync(string rawDocLibUrl) { try { if (string.IsNullOrEmpty(rawDocLibUrl)) { return(rawDocLibUrl); } rawDocLibUrl = WebUtility.UrlDecode(rawDocLibUrl); Match match = Regex.Match(rawDocLibUrl, @"(https?://([^/]+)((/[^/?]+)*?)(/[^/?]+))(/(Forms/\w+.aspx)?)?(\?.*)?$", RegexOptions.IgnoreCase); string docLibUrl = match.Groups[1].Value; string hostName = match.Groups[2].Value; string siteRelativePath = match.Groups[3].Value; if (string.IsNullOrEmpty(siteRelativePath)) { siteRelativePath = "/"; } GraphServiceClient graphServiceClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphServiceClient != null) { Site site = await graphServiceClient.Sites.GetByPath(siteRelativePath, hostName).Request().GetAsync(); ISiteDrivesCollectionPage drives = await graphServiceClient.Sites[site.Id].Drives.Request().GetAsync(); Drive drive = drives.SingleOrDefault(o => WebUtility.UrlDecode(o.WebUrl).Equals(docLibUrl, StringComparison.CurrentCultureIgnoreCase)); if (drive == null) { throw new Exception("Drive not found"); } return(graphServiceClient.Drives[drive.Id].RequestUrl); } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } return(rawDocLibUrl); }
private async Task LoadPlansAsync() { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { IPlannerUserPlansCollectionPage plans = await graphClient.Me.Planner.Plans.Request().GetAsync(); Plans.Clear(); while (true) { foreach (PlannerPlan plan in plans) { Plans.Add(plan); } if (plans.NextPageRequest == null) { break; } plans = await plans.NextPageRequest.GetAsync(); } if (!string.Equals(InternalPlanId, PlanId)) { InternalPlanId = PlanId; } if (Plans.Count > 0 && string.IsNullOrWhiteSpace(PlanId)) { PlanId = Plans[0].Id; } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async Task GetAssignmentsAsync(PlannerTaskViewModel taskViewModel, GraphServiceClient graphClient = null) { try { if (graphClient == null) { graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); } string assignments = string.Empty; foreach (string userId in taskViewModel.AssignmentIds) { if (!string.IsNullOrEmpty(userId)) { if (!_userCache.ContainsKey(userId)) { User user = await graphClient.Users[userId].Request().GetAsync(); if (user != null) { _userCache.Add(user.Id, user.DisplayName); assignments += AssigneeSeperator + user.DisplayName; } } else { assignments += AssigneeSeperator + _userCache[userId]; } } } if (assignments.Length > AssigneeSeperator.Length) { assignments = assignments.Substring(2); } taskViewModel.AssignmentNames = assignments; } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async void Download_Click(object sender, RoutedEventArgs e) { if (_list.SelectedItem is DriveItem driveItem) { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { FileSavePicker picker = new FileSavePicker(); picker.FileTypeChoices.Add(AllFilesMessage, new List <string>() { driveItem.Name.Substring(driveItem.Name.LastIndexOf(".")) }); picker.SuggestedFileName = driveItem.Name; picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { using (Stream inputStream = await graphClient.Drives[_driveId].Items[driveItem.Id].Content.Request().GetAsync()) { using (Stream outputStream = await file.OpenStreamForWriteAsync()) { await inputStream.CopyToAsync(outputStream); } } } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } } }
private async Task DeleteTaskAsync(PlannerTaskViewModel task) { MessageDialog confirmDialog = new MessageDialog(DeleteConfirmDialogMessage); confirmDialog.Commands.Add(new UICommand { Id = DeleteConfirmDialogYes, Label = DeleteConfirmDialogYesLabel }); confirmDialog.Commands.Add(new UICommand { Id = DeleteConfirmDialogNo, Label = DeleteConfirmDialogNoLabel }); confirmDialog.DefaultCommandIndex = 0; confirmDialog.CancelCommandIndex = 1; IUICommand result = await confirmDialog.ShowAsync(); if (result.Id.ToString() == DeleteConfirmDialogYes) { try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { PlannerTask taskToUpdate = await graphClient.Planner.Tasks[task.Id].Request().GetAsync(); await graphClient.Planner.Tasks[task.Id].Request().Header(HttpHeaderIfMatch, taskToUpdate.GetEtag()).DeleteAsync(); task.PropertyChanged -= TaskViewModel_PropertyChanged; Tasks.Remove(task); _allTasks.Remove(task); } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } } }
private async void TaskViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { PlannerTaskViewModel plannerTaskViewModel = sender as PlannerTaskViewModel; if (Tasks.Contains(plannerTaskViewModel)) { Dictionary <string, object> task = new Dictionary <string, object>(); bool skipUpdate = false; switch (e.PropertyName) { case nameof(plannerTaskViewModel.AssignmentIds): await GetAssignmentsAsync(plannerTaskViewModel); PlannerAssignments assignments = new PlannerAssignments(); foreach (string assignee in plannerTaskViewModel.AssignmentIds) { assignments.AddAssignee(assignee); } task.Add(TaskAssignmentsJsonName, assignments); break; case nameof(plannerTaskViewModel.Title): task.Add(TaskTitleJsonName, plannerTaskViewModel.Title); break; case nameof(plannerTaskViewModel.BucketId): string bucketName = string.Empty; foreach (PlannerBucket bucket in Buckets) { if (bucket.Id == plannerTaskViewModel.BucketId) { bucketName = bucket.Name; break; } } plannerTaskViewModel.BucketName = bucketName; task.Add(TaskBucketIdJsonName, plannerTaskViewModel.BucketId); if (string.IsNullOrEmpty(plannerTaskViewModel.BucketId)) { skipUpdate = true; } break; case nameof(plannerTaskViewModel.DueDateTime): task.Add(TaskDueDateTimeJsonName, plannerTaskViewModel.DueDateTime); if (_list.ContainerFromItem(plannerTaskViewModel) is ListViewItem taskContainer) { var flyout = taskContainer.ContentTemplateRoot.FindDescendants <Button>().FirstOrDefault(s => s.Flyout != null)?.Flyout; if (flyout != null) { flyout.Hide(); } } break; default: skipUpdate = true; break; } if (!skipUpdate) { plannerTaskViewModel.IsUpdating = true; try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { PlannerTask taskToUpdate = await graphClient.Planner.Tasks[plannerTaskViewModel.Id].Request().GetAsync(); if (task.ContainsKey(TaskAssignmentsJsonName)) { PlannerAssignments assignments = task[TaskAssignmentsJsonName] as PlannerAssignments; string[] oldAssignees = taskToUpdate.Assignments.Assignees.ToArray(); string[] newAssignees = assignments.Assignees.ToArray(); foreach (string userId in oldAssignees) { if (!newAssignees.Contains(userId)) { assignments.AddAssignee(userId); assignments[userId] = null; } } } plannerTaskViewModel.ETag = taskToUpdate.GetEtag(); using (HttpRequestMessage request = graphClient.Planner.Tasks[plannerTaskViewModel.Id].Request().GetHttpRequestMessage()) { request.Method = new HttpMethod(HttpMethodPatch); string json = JsonConvert.SerializeObject(task); request.Content = new StringContent(json, System.Text.Encoding.UTF8, MediaTypeJson); request.Headers.Add(HttpHeaderIfMatch, plannerTaskViewModel.ETag); await graphClient.AuthenticationProvider.AuthenticateRequestAsync(request); HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(request); response.Dispose(); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } plannerTaskViewModel.IsUpdating = false; } } }
private async Task LoadFilesAsync(string driveItemId, int pageIndex = 0) { IsDetailPaneVisible = false; HideDetailsPane(); if (!string.IsNullOrEmpty(_driveId)) { try { _cancelLoadFile.Cancel(false); _cancelLoadFile.Dispose(); _cancelLoadFile = new CancellationTokenSource(); _list.Items.Clear(); VisualStateManager.GoToState(this, NavStatesFolderReadonly, false); QueryOption queryOption = new QueryOption("$top", PageSize.ToString()); GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { Task <IDriveItemChildrenCollectionPage> taskFiles = graphClient.Drives[_driveId].Items[driveItemId].Children.Request(new List <Option> { queryOption }).GetAsync(_cancelLoadFile.Token); IDriveItemChildrenCollectionPage files = await taskFiles; if (!taskFiles.IsCanceled) { _list.Items.Clear(); foreach (DriveItem file in files) { _list.Items.Add(file); } _nextPageRequest = files.NextPageRequest; HasMore = _nextPageRequest != null; VisualStateManager.GoToState(this, NavStatesFolderReadonly, false); _pathVisualState = NavStatesFolderReadonly; if (_driveItemPath.Count > 1) { IDriveItemPermissionsCollectionPage permissions = await graphClient.Drives[_driveId].Items[driveItemId].Permissions.Request().GetAsync(); foreach (Permission permission in permissions) { if (permission.Roles.Contains("write") || permission.Roles.Contains("owner")) { VisualStateManager.GoToState(this, NavStatesFolderEdit, false); _pathVisualState = NavStatesFolderEdit; break; } } } else { _pathVisualState = NavStatesFolderEdit; VisualStateManager.GoToState(this, NavStatesFolderEdit, false); } } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } } }
private async void List_SelectionChanged(object sender, SelectionChangedEventArgs e) { _cancelGetDetails.Cancel(false); _cancelGetDetails.Dispose(); _cancelGetDetails = new CancellationTokenSource(); if (_list.SelectedItem is DriveItem driveItem && driveItem.File != null) { try { SelectedFile = driveItem; FileSize = driveItem.Size ?? 0; LastModified = driveItem.LastModifiedDateTime?.LocalDateTime.ToString() ?? string.Empty; if (FileSelected != null) { FileSelected.Invoke(this, new FileSelectedEventArgs(driveItem)); } ThumbnailImageSource = null; VisualStateManager.GoToState(this, NavStatesFileReadonly, false); GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { Task <IDriveItemPermissionsCollectionPage> taskPermissions = graphClient.Drives[_driveId].Items[driveItem.Id].Permissions.Request().GetAsync(_cancelGetDetails.Token); IDriveItemPermissionsCollectionPage permissions = await taskPermissions; if (!taskPermissions.IsCanceled) { foreach (Permission permission in permissions) { if (permission.Roles.Contains("write") || permission.Roles.Contains("owner")) { VisualStateManager.GoToState(this, NavStatesFileEdit, false); break; } } Task <IDriveItemThumbnailsCollectionPage> taskThumbnails = graphClient.Drives[_driveId].Items[driveItem.Id].Thumbnails.Request().GetAsync(_cancelGetDetails.Token); IDriveItemThumbnailsCollectionPage thumbnails = await taskThumbnails; if (!taskThumbnails.IsCanceled) { ThumbnailSet thumbnailsSet = thumbnails.FirstOrDefault(); if (thumbnailsSet != null) { Thumbnail thumbnail = thumbnailsSet.Large; if (thumbnail.Url.Contains("inputFormat=svg")) { SvgImageSource source = new SvgImageSource(); using (Stream inputStream = await graphClient.Drives[_driveId].Items[driveItem.Id].Content.Request().GetAsync()) { SvgImageSourceLoadStatus status = await source.SetSourceAsync(inputStream.AsRandomAccessStream()); if (status == SvgImageSourceLoadStatus.Success) { ThumbnailImageSource = source; } } } else { ThumbnailImageSource = new BitmapImage(new Uri(thumbnail.Url)); } } } IsDetailPaneVisible = true; ShowDetailsPane(); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } }
private async Task SearchPeopleAsync(string searchPattern) { if (string.IsNullOrWhiteSpace(searchPattern)) { ClearAndHideSearchResultListBox(); return; } IsLoading = true; try { GraphServiceClient graphClient = await GraphServiceHelper.GetGraphServiceClientAsync(); if (graphClient != null) { int searchLimit = SearchResultLimit > 0 ? SearchResultLimit : DefaultSearchResultLimit; int queryLimit = searchLimit + Selections.Count; IEnumerable <Person> rawResults; if (string.IsNullOrWhiteSpace(GroupId)) { var options = new List <QueryOption> { new QueryOption("$search", $"\"{searchPattern}\""), new QueryOption("$filter", "personType/class eq 'Person' and personType/subclass eq 'OrganizationUser'"), new QueryOption("$top", queryLimit.ToString()) }; rawResults = await graphClient.Me.People.Request(options).GetAsync(); } else { IGroupMembersCollectionWithReferencesPage userRequest = await graphClient.Groups[GroupId].Members.Request().GetAsync(); List <Person> allPersons = new List <Person>(); while (true) { foreach (User user in userRequest) { if (string.IsNullOrEmpty(searchPattern) || (!string.IsNullOrEmpty(user.DisplayName) && user.DisplayName.StartsWith(searchPattern, StringComparison.OrdinalIgnoreCase)) || (!string.IsNullOrEmpty(user.Surname) && user.Surname.StartsWith(searchPattern, StringComparison.OrdinalIgnoreCase))) { Person person = GetPersonFromUser(user); allPersons.Add(person); } if (allPersons.Count >= queryLimit) { break; } } if (allPersons.Count >= queryLimit || userRequest.NextPageRequest == null) { break; } userRequest = await userRequest.NextPageRequest.GetAsync(); } rawResults = allPersons; } SearchResults.Clear(); var results = rawResults.Where(o => !Selections.Any(s => s.Id == o.Id)) .Take(searchLimit); foreach (var item in results) { SearchResults.Add(item); } if (SearchResults.Count > 0) { ShowSearchResults(); } else { ClearAndHideSearchResultListBox(); } } } catch (Exception exception) { MessageDialog messageDialog = new MessageDialog(exception.Message); await messageDialog.ShowAsync(); } finally { IsLoading = false; } }