/// <summary> /// Performs preview loading on images. /// </summary> /// <param name="ownerViewModel">The owner view model.</param> /// <param name="cancelToken">The cancel token.</param> private async Task LoadPreviewContentImagesAsync(FolderViewModel ownerViewModel, CancellationToken cancelToken) { // Load all details Dictionary<string, object> loadedFiles = new Dictionary<string, object>(); // Load all thumbnails int loadedThumbnailCount = 0; foreach (string actFileName in Directory.GetFiles(ownerViewModel.BasePath, Constants.BROWSING_SEARCH_PATTERN_THUMBNAIL)) { // Do only load supported formats if (Array.IndexOf(Constants.SUPPORTED_IMAGE_FORMATS, Path.GetExtension(actFileName)) < 0) { continue; } // Load the bitmap ImageViewModel actThumbnailVM = new ImageViewModel(); actThumbnailVM.FilePath = actFileName; ownerViewModel.ThumbnailViewModels.Add(actThumbnailVM); loadedThumbnailCount++; // Register currently loaded file loadedFiles[actFileName] = null; } // Handle all remaining files foreach (string actFileName in Directory.GetFiles(ownerViewModel.BasePath) .OrderBy((actPath) => actPath)) { if (loadedFiles.ContainsKey(actFileName)) { continue; } // Handle images if (Array.IndexOf(Constants.SUPPORTED_IMAGE_FORMATS, Path.GetExtension(actFileName)) >= 0) { // Load the bitmap m_fullViewsPreview.Add(new ImageViewModel() { FilePath = actFileName }); continue; } } // Take some images from full-size collection if there are no explicit thumbnails if ((loadedThumbnailCount == 0) && (m_fullViewsPreview.Count > 0)) { ImageViewModel[] fullImages = m_fullViewsPreview.OfType<ImageViewModel>().ToArray(); if (fullImages.Length > 0) { List<int> takenRandomValues = new List<int>(); for (int loop = 0; loop < 5 && loop < fullImages.Length; loop++) { int nextRandom = Constants.UI_RANDOMIZER.Next(0, fullImages.Length); while(takenRandomValues.Contains(nextRandom)) { nextRandom = Constants.UI_RANDOMIZER.Next(0, fullImages.Length); } ownerViewModel.ThumbnailViewModels.Add( fullImages[nextRandom]); } } } // Preload thumbnail images foreach (ImageViewModel actThumbnailVM in ownerViewModel.ThumbnailViewModels.OfType<ImageViewModel>()) { await actThumbnailVM.PreloadAsync(Constants.THUMBNAIL_WDITH, Constants.THUMBNAIL_HEIGHT); // Cancel here if cancellation is requested if (cancelToken.IsCancellationRequested) { return; } } }
/// <summary> /// Performs preview loading on videos. /// </summary> /// <param name="ownerViewModel">The owner view model.</param> private void LoadPreviewContentVideos(FolderViewModel ownerViewModel) { // Load all thumbnails foreach (string actFileName in Directory.GetFiles(ownerViewModel.BasePath)) { // Do only load supported formats if (Array.IndexOf(Constants.SUPPORTED_VIDEO_FORMATS, Path.GetExtension(actFileName)) < 0) { continue; } // Load the bitmap VideoViewModel videoVM = new VideoViewModel(); videoVM.VideoUri = new Uri(actFileName, UriKind.Absolute); // Register currently loaded file m_fullViewsPreview.Add(videoVM); } }
/// <summary> /// Loads all folder contents. /// </summary> /// <param name="cancelToken">The cancellation token.</param> protected override async Task LoadDetailContentInternalAsync(CancellationToken cancelToken) { if (string.IsNullOrEmpty(m_basePath)) { return; } string[] subdirectories = Directory.Exists(m_basePath) ? Directory.GetDirectories(m_basePath) : new string[0]; base.HasBigSizeChildren = subdirectories.Length <= Constants.MAX_SUBITEM_COUNT_FOR_BIG_TILES; // Load all subfolders folder-by-folder // Trigger loading of the description (image, displayname, ...) before coninuing with next one List<FolderViewModel> foundSubdirectories = new List<FolderViewModel>(); foreach (string actSubdirectory in subdirectories) { FolderViewModel actSubdirVM = new FolderViewModel(this, actSubdirectory); foundSubdirectories.Add(actSubdirVM); await actSubdirVM.LoadPreviewContentAsync(cancelToken); await Task.Delay(Constants.BROWSING_DELAY_TIME_PER_FOLDER_LOAD_MS); base.SubViewModels.Add(actSubdirVM); // Return here if cancellation is requested if (cancelToken.IsCancellationRequested) { return; } } }