Пример #1
0
        /// <summary>
        /// Shows the Loading status bar, if necessary. Also, it inserts the Loading... indicator, if necesary
        /// </summary>
        /// <param name="loader">Current loader</param>
        /// <param name="state">Progress reported by the <c>Progress</c> callback</param>
        private void HandleItemLoaderStateChange(IItemLoader <PackageItemListViewModel> loader, IItemLoaderState state)
        {
            _joinableTaskFactory.Value.Run(async() =>
            {
                await _joinableTaskFactory.Value.SwitchToMainThreadAsync();

                if (loader == _loader)
                {
                    _loadingStatusBar.UpdateLoadingState(state);

                    // decide when to show status bar
                    var desiredVisibility = EvaluateStatusBarVisibility(loader, state);

                    if (_loadingStatusBar.Visibility != Visibility.Visible &&
                        desiredVisibility == Visibility.Visible)
                    {
                        _loadingStatusBar.Visibility = desiredVisibility;
                    }

                    _loadingStatusIndicator.Status = state.LoadingStatus;

                    if (!Items.Contains(_loadingStatusIndicator))
                    {
                        await _list.ItemsLock.ExecuteAsync(() =>
                        {
                            Items.Add(_loadingStatusIndicator);
                            return(Task.CompletedTask);
                        });
                    }
                }
            });
        }
Пример #2
0
        private Visibility EvaluateStatusBarVisibility(IItemLoader <PackageItemListViewModel> loader, IItemLoaderState state)
        {
            var statusBarVisibility = Visibility.Hidden;

            if (state.LoadingStatus == LoadingStatus.Cancelled ||
                state.LoadingStatus == LoadingStatus.ErrorOccurred)
            {
                statusBarVisibility = Visibility.Visible;
            }

            if (loader.IsMultiSource)
            {
                var hasMore = _loadingStatusBar.ItemsLoaded != 0 && state.ItemsCount > _loadingStatusBar.ItemsLoaded;
                if (hasMore)
                {
                    statusBarVisibility = Visibility.Visible;
                }

                if (state.LoadingStatus == LoadingStatus.Loading && state.ItemsCount > 0)
                {
                    statusBarVisibility = Visibility.Visible;
                }
            }

            return(statusBarVisibility);
        }
Пример #3
0
        private void HandleItemLoaderStateChange(IItemLoader <PackageItemListViewModel> loader, IItemLoaderState state)
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                if (loader == _loader)
                {
                    _loadingStatusBar.UpdateLoadingState(state);

                    // decide when to show status bar
                    var desiredVisibility = EvaluateStatusBarVisibility(loader, state);

                    if (_loadingStatusBar.Visibility != Visibility.Visible &&
                        desiredVisibility == Visibility.Visible)
                    {
                        _loadingStatusBar.Visibility = desiredVisibility;
                    }

                    _loadingStatusIndicator.Status = state.LoadingStatus;

                    if (!Items.Contains(_loadingStatusIndicator))
                    {
                        Items.Add(_loadingStatusIndicator);
                    }
                }
            });
        }
Пример #4
0
        private async Task LoadItemsCoreAsync(IItemLoader <PackageItemListViewModel> currentLoader, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            var loadedItems = await LoadNextPageAsync(currentLoader, token);

            token.ThrowIfCancellationRequested();

            await NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async() =>
            {
                await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // multiple loads may occur at the same time as a result of multiple instances,
                // makes sure we update using the relevant one.
                if (currentLoader == _loader)
                {
                    _loadingStatusBar.ItemsLoaded = currentLoader.State.ItemsCount;
                    UpdatePackageList(loadedItems, refresh: false);
                }
            });

            token.ThrowIfCancellationRequested();

            // keep waiting till completion
            await WaitForCompletionAsync(currentLoader, token);

            token.ThrowIfCancellationRequested();
        }
Пример #5
0
        // Load items using the specified loader
        internal void LoadItems(IItemLoader <PackageItemListViewModel> loader, string loadingMessage, INuGetUILogger logger)
        {
            _loader = loader;
            _logger = logger;
            _loadingStatusIndicator.Reset(loadingMessage);
            _loadingStatusBar.Visibility = Visibility.Hidden;
            _loadingStatusBar.Reset(loadingMessage, loader.IsMultiSource);

            var selectedPackageItem = SelectedPackageItem;

            _itemsLock.Wait();

            try
            {
                ClearPackageList();
            }
            finally
            {
                _itemsLock.Release();
            }


            _selectedCount = 0;

            // triggers the package list loader
            LoadItems(selectedPackageItem);
        }
Пример #6
0
 public CollectionLoader(ICollectionRepo collectionRepo, ICollectionRelationshipRepo collectionRelationshipRepo, IAttributeLoader attributeLoader, IImageLoader imageLoader, IItemLoader itemLoader)
 {
     _collectionRelationshipRepo = collectionRelationshipRepo;
     _collectionRepo             = collectionRepo;
     _attributeLoader            = attributeLoader;
     _imageLoader = imageLoader;
     _itemLoader  = itemLoader;
 }
Пример #7
0
        public void Initialize(IItemEventLoader eventLoader, IItemLoader itemLoader, IMonsterLoader monsterLoader)
        {
            EventLoader   = eventLoader ?? throw new ArgumentNullException(nameof(eventLoader));
            ItemLoader    = itemLoader ?? throw new ArgumentNullException(nameof(itemLoader));
            MonsterLoader = monsterLoader ?? throw new ArgumentNullException(nameof(monsterLoader));

            _map = new Map.Map(new WorldLoader(ServerResourcesManager.GetMap()));
        }
Пример #8
0
 private async Task WaitForInitialResultsAsync(
     IItemLoader <PackageItemListViewModel> currentLoader,
     IProgress <IItemLoaderState> progress,
     CancellationToken token)
 {
     while (currentLoader.State.LoadingStatus == LoadingStatus.Loading &&
            currentLoader.State.ItemsCount == 0)
     {
         token.ThrowIfCancellationRequested();
         await currentLoader.UpdateStateAsync(progress, token);
     }
 }
Пример #9
0
        private async Task WaitForCompletionAsync(IItemLoader <PackageItemListViewModel> currentLoader, CancellationToken token)
        {
            var progress = new Progress <IItemLoaderState>(
                s => HandleItemLoaderStateChange(currentLoader, s));

            // run to completion
            while (currentLoader.State.LoadingStatus == LoadingStatus.Loading)
            {
                token.ThrowIfCancellationRequested();
                await currentLoader.UpdateStateAsync(progress, token);
            }
        }
Пример #10
0
        /// <summary>
        ///     Stores the value.
        /// </summary>
        /// <param name="loader">
        ///     The loader.
        /// </param>
        /// <param name="properties">
        ///     The properties.
        /// </param>
        /// <param name="value">
        ///     The value.
        /// </param>
        private static void StoreValue(IItemLoader loader, Dictionary <string, string> properties, string value)
        {
            Contract.Requires(loader != null);
            Contract.Requires(properties != null);

            if (properties.TryGetValue(key: loader.Name, out string lastValue))
            {
                if (string.IsNullOrWhiteSpace(lastValue) && !string.IsNullOrWhiteSpace(value))
                {
                    properties[loader.Name] = NormalizeValue(name: loader.Name, value: value);
                }
            }
Пример #11
0
        private async Task <IEnumerable <PackageItemListViewModel> > LoadNextPageAsync(IItemLoader <PackageItemListViewModel> currentLoader, CancellationToken token)
        {
            var progress = new Progress <IItemLoaderState>(
                s => HandleItemLoaderStateChange(currentLoader, s));

            // trigger loading
            await currentLoader.LoadNextAsync(progress, token);

            // run till first results are ready
            for (var state = currentLoader.State;
                 state.LoadingStatus == LoadingStatus.Loading && state.ItemsCount == 0;
                 state = currentLoader.State)
            {
                token.ThrowIfCancellationRequested();
                await currentLoader.UpdateStateAsync(progress, token);
            }

            return(currentLoader.GetCurrent());
        }