Esempio n. 1
0
        private async Task AddFromSourceAsync(
            ITemplateSource source,
            string searchTerm,
            CategorizedViewModel parent,
            bool alterSelection,
            CancellationToken ct,
            string continuationToken = null,
            VisualStudio.Imaging.Interop.ImageMoniker?updateableImage = null
            )
        {
            var loading = new LoadingViewModel();

            parent.Templates.Add(loading);
            if (alterSelection)
            {
                loading.IsSelected = true;
            }

            try {
                var result = await source.GetTemplatesAsync(searchTerm, continuationToken, ct);

                foreach (var t in result.Templates)
                {
                    ct.ThrowIfCancellationRequested();

                    var vm = new TemplateViewModel();
                    vm.DisplayName       = t.Name;
                    vm.Description       = t.Description;
                    vm.AvatarUrl         = t.AvatarUrl;
                    vm.OwnerUrl          = t.OwnerUrl;
                    vm.RemoteUrl         = t.RemoteUrl;
                    vm.ClonedPath        = t.LocalFolderPath;
                    vm.Category          = parent.DisplayName;
                    vm.IsUpdateAvailable = t.UpdateAvailable == true;
                    parent.Templates.Add(vm);
                }

                ct.ThrowIfCancellationRequested();

                if (result.ContinuationToken != null)
                {
                    var loadMore = new ContinuationViewModel(result.ContinuationToken);
                    parent.Templates.Add(loadMore);
                }
            } catch (TemplateEnumerationException ex) {
                var template = new ErrorViewModel()
                {
                    ErrorDescription = ex.Message,
                    ErrorDetails     = ex.InnerException?.Message,
                };
                parent.Templates.Add(template);
            } finally {
                // Check if the loading item is still selected before we remove it, the user
                // may have selected something else while we were loading results.
                bool loadingStillSelected = loading.IsSelected;
                parent.Templates.Remove(loading);
                if (alterSelection && loadingStillSelected)
                {
                    // Loading was still selected, so select something else.
                    var newLast = parent.Templates.LastOrDefault() as TreeItemViewModel;
                    if (newLast != null)
                    {
                        newLast.IsSelected = true;
                    }
                }
            }
        }
Esempio n. 2
0
        private async Task AddFromSource(
            ITemplateSource source,
            string searchTerm,
            CategorizedViewModel parent,
            CancellationToken ct,
            string continuationToken = null,
            VisualStudio.Imaging.Interop.ImageMoniker? updateableImage = null
        ) {
            var loading = new LoadingViewModel();
            parent.Templates.Add(loading);

            try {
                var result = await source.GetTemplatesAsync(searchTerm, continuationToken, ct);
                foreach (var t in result.Templates) {
                    ct.ThrowIfCancellationRequested();

                    var vm = new TemplateViewModel();
                    vm.DisplayName = t.Name;
                    vm.Description = t.Description;
                    vm.AvatarUrl = t.AvatarUrl;
                    vm.OwnerUrl = t.OwnerUrl;
                    vm.RemoteUrl = t.RemoteUrl;
                    vm.ClonedPath = t.LocalFolderPath;
                    vm.IsUpdateAvailable = t.UpdateAvailable == true;
                    parent.Templates.Add(vm);
                }

                ct.ThrowIfCancellationRequested();

                if (result.ContinuationToken != null) {
                    parent.Templates.Add(new ContinuationViewModel(result.ContinuationToken));
                }
            } catch (TemplateEnumerationException ex) {
                var template = new ErrorViewModel() {
                    ErrorDescription = ex.Message,
                    ErrorDetails = ex.InnerException?.Message,
                };
                parent.Templates.Add(template);
            } finally {
                parent.Templates.Remove(loading);
            }
        }