private void NextImage()
        {
            // write stat every day at 8PM
            if (_settings._writeStat && _prevTime == 20 && DateTime.Now.Hour == _prevTime + 1)
            {
                _images.WriteStat(_settings._writeStatPath);
            }

            _prevTime = DateTime.Now.Hour;

            ImageInfo nextphoto = _images.GetNext();

            if (nextphoto != null)
            {
                try
                {
                    PhotoProperties.PhotoDescription = nextphoto.description;
                    var ft = TimeSpan.FromMilliseconds(_settings._noImageFading ||
                                                       (_isNightTime && _settings._noNightImageFading)
                                            ? 0 : _settings._fadeSpeed);

                    var mt = TimeSpan.MinValue;

                    if (!(_settings._noImageScaling || (_isNightTime && _settings._noNightImageScaling)))
                    {
                        mt = TimeSpan.FromSeconds(_settings._updateInterval);
                    }

                    bool acc = !_settings._noImageAccents && !(_isNightTime && _settings._noNightImageAccents);

                    if (!FirstImage.IsActive)
                    {
                        FirstImage.Activate(nextphoto, ft, mt, acc);
                        SecondImage.Deactivate(ft);
                    }
                    else
                    {
                        SecondImage.Activate(nextphoto, ft, mt, acc);
                        FirstImage.Deactivate(ft);
                    }

                    PhotoProperties.SetFacesFound(nextphoto.accent_count);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: " + ex.Message);
                }
            }
        }
        public ScreensaverViewModel()
        {
            _images.init(new string[] { _settings._path, _settings._writeStat ? _settings._writeStatPath : "" });
            FirstImage = new FrameViewModel("one")
            {
                IsActive = true
            };
            SecondImage = new FrameViewModel("two")
            {
                IsActive = false
            };
            PhotoProperties = new PhotoProperties();

            NextImage(); // to show from the very start
            _switchImage          = new DispatcherTimer();
            _switchImage.Interval = TimeSpan.FromSeconds(_settings._updateInterval);
            _switchImage.Tick    += new EventHandler(fade_Tick);

            _switchImage.Start();
        }
Ejemplo n.º 3
0
        public FileInformation Load(IFile file, Stream stream)
        {
            _logger.LogDebug("Load file information of {filename}", file.Filename);

            PhotoProperties?properties;
            Hash            fileHash;
            DateTimeOffset  fileCreatedOn;

            fileCreatedOn = GetCreationDate(stream, file);

            stream.Position = 0;
            try
            {
                using var bmp = new Bitmap(stream);

                var width   = bmp.Width;
                var height  = bmp.Height;
                var bmpHash = new Hash(BitmapHash.Compute(bmp));

                properties = new PhotoProperties(bmpHash, width, height);
            }
            catch (Exception)
            {
                properties = null;
            }

            stream.Position = 0;
            fileHash        = _fileHasher.ComputeHash(stream);

            var fileInformation = new FileInformation(file.Filename, file.CreatedOn, file.ModifiedOn, fileHash, file.Length,
                                                      fileCreatedOn, properties, file.RelativeFilename);

            _logger.LogDebug("FileInformation of file {filename} loaded: {@data}", file.Filename, fileInformation);

            return(fileInformation);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes the PhotoProperties tag properties using asynchronous 
        /// method invocation of the initialization.</summary>
        private void InitializePhotoProperties(string initXmlFile)
        {
            // Create an instance of the PhotoProperties
            _photoProps = new PhotoProperties();

            // Use the asynchronous method invocation of the initialization delegate
            // to initialize the photo properties in a worker thread.
            InitializePhotoPropertiesDelegate initDelegate =
                new InitializePhotoPropertiesDelegate(_photoProps.Initialize);
            AsyncCallback callback = new AsyncCallback(InitializePhotoPropertiesCompleted);
            initDelegate.BeginInvoke(initXmlFile, callback, initDelegate);
        }