コード例 #1
0
        /// <summary>
        ///   Forces a resynchronization of the containing <see cref="Wallpaper" /> objects with the physical image files on the
        ///   users hard disk.
        /// </summary>
        /// <commondoc select='IDisposable/Methods/All/*' />
        public void Resynchronize()
        {
            if (this.IsDisposed)
            {
                throw new ObjectDisposedException("this");
            }

            string[] existingFiles = Directory.GetFiles(this.SynchronizedDirectoryPath);

            // Add wallpapers that are on the hard disk but not in this category.
            for (int i = 0; i < existingFiles.Length; i++)
            {
                Path existingPath = new Path(existingFiles[i]);

                if (this.IndexOfByImagePath(existingPath) == -1)
                {
                    if (SynchronizedWallpaperCategory.IsImageFileExtensionSupported(existingPath))
                    {
                        this.AddAsync(existingPath);
                    }
                }
            }

            // Remove wallpapers which are in this category but doesn't exist on the hard disk.
            for (int i = this.Count - 1; i >= 0; i--)
            {
                if ((this[i].ImagePath == Path.None) || (!existingFiles.Contains(this[i].ImagePath)))
                {
                    base.RemoveItem(i);
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///   Handles the <see cref="System.IO.FileSystemWatcher.Changed" /> event of a <see cref="System.IO.FileSystemWatcher" />
        ///   object.
        /// </summary>
        /// <commondoc select='All/Methods/EventHandlers[@Params="Object,+EventArgs"]/*' />
        private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            Action <Path> code = (filePath) => {
                // Make sure the item doesn't already exist.
                if (this.IndexOfByImagePath(filePath) == -1 && SynchronizedWallpaperCategory.IsImageFileExtensionSupported(filePath))
                {
                    this.AddAsync(filePath);
                }
            };

            this.InvokeDispatcher.Invoke(DispatcherPriority.Background, code, new Path(e.FullPath));
        }