Exemplo n.º 1
0
        public async Task <List <FileDiscoveryCache> > PreformFileDiscoveryAll(IProgress <IndicatorProgressReport> progress)
        {
            // Cache the old Progress Variable
            allCacheProgress = progress;

            // Create a Progress Wrapper so we don't end up turning off the progress indicator by accident
            Progress <IndicatorProgressReport> internalProgress = new Progress <IndicatorProgressReport>();

            internalProgress.ProgressChanged += new EventHandler <IndicatorProgressReport>(delegate(object sender, IndicatorProgressReport e)
            {
                double percentage = e.Percentage;
                if (percentage >= 100.0)
                {
                    percentage -= 1.0;
                }
                allCacheProgress?.Report(new IndicatorProgressReport(e.RingEnabled, percentage, e.StatusMessage, e.WriteToDebugConsole));
            });

            // Clear the FileDiscoveryCache
            progress?.Report(new IndicatorProgressReport(true, 0.0, $"Clearing the Cache - 1/1", true));
            FileCacheRepo.Clear();

            // Go through all the themes and begin the caching process
            List <FileDiscoveryCache> updatedThemeFilesCache = new List <FileDiscoveryCache>();
            var allThemes = ThemeRepo.GetAll();

            // Update the Cache Discovery Date
            foreach (var theme in allThemes)
            {
                theme.DateCacheDiscovered = DateTime.UtcNow;
                ThemeRepo.UpdateAndCommit(theme);
            }

            // Update the Cache
            foreach (var theme in allThemes)
            {
                var cache = await PreformFileDiscovery(theme, internalProgress);

                updatedThemeFilesCache.AddRange(cache);
            }

            // Update the Last Run
            var fileDiscoveryLastRunSetting = new FileDiscoveryLastRunSetting();

            fileDiscoveryLastRunSetting.Value = DateTime.UtcNow;

            // Report back completion and return
            allCacheProgress = null;
            progress?.Report(new IndicatorProgressReport(true, 100.0, $"File Discovery Completed", true));
            return(updatedThemeFilesCache);
        }
Exemplo n.º 2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Run)} - Begun");

            // Register the Monitoring Events
            taskInstance.Canceled       += TaskInstance_Canceled;
            taskInstance.Task.Completed += Task_Completed;
            taskInstance.Task.Progress  += Task_Progress;

            // If the task is not allowed to run, return early
            if (!IsTaskAllowedToRun())
            {
                return;
            }

            // Otherwise, we jump into File Discovery Process
            _deferral = taskInstance.GetDeferral();
            using (var context = new WallpaperManagerContext())
            {
                var themeRepo            = new WallpaperThemeRepository(context);
                var fileDiscoveryService = new FileDiscoveryService(context);

                // Preform File Discovery for ALL of the themes
                //_deferral = taskInstance.GetDeferral();
                //await fileDiscoveryService.PreformFileDiscoveryAll(null);
                //_deferral.Complete();

                // Preform File Discovery for the Desktop Wallpaper Theme
                Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveDesktopThemeSetting)} - Started");
                var activeDesktopThemeSetting      = new ActiveDesktopThemeSetting();
                var activeDesktopThemeSettingValue = activeDesktopThemeSetting.Value;
                if (activeDesktopThemeSettingValue.HasValue)
                {
                    var activeWallpaperTheme = themeRepo.Find(activeDesktopThemeSettingValue.Value);
                    await fileDiscoveryService.PreformFileDiscovery(activeWallpaperTheme, null);
                }
                Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveDesktopThemeSetting)} - Completed");

                // Preform File Discovery for the Lockscreen Theme
                Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveLockscreenThemeSetting)} - Started");
                var activeLockscreenThemeSetting      = new ActiveLockscreenThemeSetting();
                var activeLockscreenThemeSettingValue = activeLockscreenThemeSetting.Value;
                if (activeLockscreenThemeSettingValue.HasValue &&
                    activeLockscreenThemeSettingValue != activeDesktopThemeSettingValue)
                {
                    var activeLockscreenTheme = themeRepo.Find(activeLockscreenThemeSettingValue.Value);
                    await fileDiscoveryService.PreformFileDiscovery(activeLockscreenTheme, null);
                }

                Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(ActiveLockscreenThemeSetting)} - Completed");
            }

            // Update the FileDiscovery Last Run
            var fileDiscoveryLastRunSetting = new FileDiscoveryLastRunSetting();

            fileDiscoveryLastRunSetting.Value = DateTime.UtcNow;

            // Update the FileDiscovery Background Task Last Run
            var fileDiscoveryTaskLastRunSetting = new FileDiscoveryTaskLastRunSetting();

            fileDiscoveryTaskLastRunSetting.Value = DateTime.UtcNow;

            Debug.WriteLine($"{nameof(FileDiscoveryBackgroundTask)} - {nameof(Run)} - Completed");
            _deferral.Complete();
        }