/// <summary>
        /// Creates ManagerViewModel using given library and settings represented by given ManagerSettings
        /// object
        /// </summary>
        /// <param name="library">LibraryViewModel representing library to be used with this manager</param>
        /// <param name="settings">ManagerSettings object representing settings to be used</param>
        public ManagerViewModel(LibraryViewModel library, ManagerSettings settings)
        {
            // Set assigned library
            Library = library;

            // Pull settings from the settings object
            _updateIntervalHours = settings.UpdateIntervalHours;
            _updateIntervalMins  = settings.UpdateIntervalMins;
            _checkInterval       = new TimeSpan(_updateIntervalHours, _updateIntervalMins, 0);
            _brightestTime       = settings.BrightestTime;
            _darkestTime         = settings.DarkestTime;
            StartsOnStartup      = settings.StartsOnStartup;
            WallpaperStyle       = settings.WallpaperStyle;

            // Create WallpaperStyles
            WallpaperStyles = new List <string>()
            {
                "Tiled",
                "Centered",
                "Stretched",
                "Fill",
                "Fit"
            };

            // Create timers and start checking
            CreateTimers();
            CheckAndUpdate();

            CreateCommands();
        }
        /// <summary>
        /// Creates new ManagerViewModel using default settings and given library
        /// </summary>
        /// <param name="library">LibraryViewModel representing library to be used with this manager</param>
        public ManagerViewModel(LibraryViewModel library)
        {
            // Set assigned library
            Library = library;

            // Set default property values
            // Update interval 1 min; brightest time 1:00 PM; darkest time 11:00 PM; start on startup false;
            // Fill wallpaper style
            _updateIntervalHours = 0;
            _updateIntervalMins  = 1;
            _checkInterval       = new TimeSpan(_updateIntervalMins, _updateIntervalHours, 0);
            DateTime now = DateTime.Now;

            _brightestTime  = new DateTime(now.Year, now.Month, now.Day, 13, 0, 0);
            _darkestTime    = new DateTime(now.Year, now.Month, now.Day, 23, 0, 0);
            StartsOnStartup = false;
            WallpaperStyle  = "Fill";

            // Create WallpaperStyles
            WallpaperStyles = new List <string>()
            {
                "Tiled",
                "Centered",
                "Stretched",
                "Fill",
                "Fit"
            };

            // Create timers and start checking
            CreateTimers();
            CheckAndUpdate();

            CreateCommands();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new empty library and links the current Manager to it
        /// </summary>
        private void NewLibrary()
        {
            Library         = new LibraryViewModel(Manager, _notifier, _imageGrid);
            Manager.Library = Library;

            // Reset timers and set progress report (progress bar message) to blank
            Manager.ResetTimers();
            Manager.ProgressReport = null;
        }
Esempio n. 4
0
        /// <summary>
        /// Creates new MainViewModel; attempts to pull Library and Manager from file and creates default
        /// ones if either fails
        /// </summary>
        /// <param name="mainWindow">Main display window</param>
        /// <param name="startingMinimized">True when starting minimized (ie from Windows startup), false
        /// otherwise; will only show window after startup if this is set true</param>
        /// <param name="imageGrid">Front-end ListView element used for displaying images on main window</param>
        public MainViewModel(MainWindow mainWindow, bool startingMinimized, ListView imageGrid)
        {
            // Create notifier for sending toast notifs
            CreateNotifier();

            // Only show window if not starting minimized
            if (!startingMinimized)
            {
                mainWindow.Show();
            }

            // Try to pull library from last lib file
            LibraryViewModel libraryFromFile = GetLibraryFromLastLibFile(startingMinimized);

            // If successful, use the library from file
            if (libraryFromFile != null)
            {
                Library           = libraryFromFile;
                Library.ImageGrid = imageGrid;
            }
            // Otherwise create new empty library
            else
            {
                Library = new LibraryViewModel(Manager, _notifier, imageGrid);
            }

            // Try to pull new manager from settings file
            ManagerViewModel managerFromFile = GetManagerFromSettingsFile(startingMinimized);

            // If successful, use the manager from file
            if (managerFromFile != null)
            {
                Manager = managerFromFile;
            }
            // If unsuccessful (e.g. no settings file exists), just create new manager with default settings
            else
            {
                Manager = new ManagerViewModel(Library);
            }

            // Link library and manager after creation
            Library.Manager = Manager;
            Manager.Library = Library;

            // Check and update before displaying
            Manager.CheckAndUpdate();

            // Store window and image grid element
            _window    = mainWindow;
            _imageGrid = imageGrid;

            CreateCommands();
        }
Esempio n. 5
0
        /// <summary>
        /// Returns LibraryViewModel represented by given Stream
        /// </summary>
        /// <param name="fileStream">Stream representing library</param>
        /// <returns>LibraryViewModel represented by given Stream</returns>
        private LibraryViewModel GetLibraryFromStream(Stream fileStream)
        {
            var serializer = new JsonSerializer();

            // Use json serializer to read library file and create a new library
            using (var streamReader = new StreamReader(fileStream))
                using (var jsonTextReader = new JsonTextReader(streamReader))
                {
                    // Deserialize WBImage array from file
                    WBImage[] imageArray = (WBImage[])serializer.Deserialize(jsonTextReader, typeof(WBImage[]));

                    // Create new library VM using image array
                    LibraryViewModel newLibrary = new LibraryViewModel(imageArray, Manager, _notifier, _imageGrid);

                    // Check for missing files in opened library
                    newLibrary.CheckMissing();

                    return(newLibrary);
                }
        }