// Private methods /// <summary> /// Attempts to read manifest.json file in directory at DirPath and create a new /// DynamicWallpaper object from its data. Calls Stop() if there's an error; otherwise /// sets WallpaperName and "starts running" by calling SyncToSunProgress() /// </summary> private void DirPath_Change() { _timer.Enabled = false; // stop timer // Try to read manifest file string json = ""; try { json = File.ReadAllText(_dirPath + Path.DirectorySeparatorChar + "manifest.json"); } catch (Exception e) { Console.Error.Write($"WallpaperScheduler.DirPath_Change - {e.ToString()}"); Stop(); return; } // Try to instantiate DynamicWallpaper object from json try { _wallpaper = new DynamicWallpaper(json); } catch (Exception e) { Console.Error.Write($"WallpaperScheduler.DirPath_Change - {e.ToString()}"); Stop(); return; } WallpaperName = _wallpaper.Name; // Set wallpaper based on sun's current progress SyncToSunProgress(); }
/// <summary> /// Disables timer, sets all properties and instance variables to indicate this WallpaperScheduler is not /// controlling the wallpaper /// </summary> private void Stop() { _timer.Enabled = false; DirPath = null; Index = -1; IsRunning = false; NextChangeTime = DateTime.MinValue; // maybe NextChangeTime should be nullable ? WallpaperName = ""; _wallpaper = null; }