예제 #1
0
        /// <summary>
        /// Creates an instance of the <see cref="Change"/> class
        /// </summary>
        /// <param name="file">File affected by the change</param>
        /// <param name="changeType">Type of change that occured</param>
        public Change(WatchedFile file, ChangeType changeType)
        {
            File       = file;
            ChangeType = changeType;

            if (ChangeType == ChangeType.Added)
            {
                Details = "'" + File.ShortPath + "' was added.";
            }
            else if (ChangeType == ChangeType.Edited)
            {
                Details = "'" + File.ShortPath + "' was edited on " +
                          File.LastModified.ToString(WatchedFile.DateFormatString) + ".";
            }
            else if (ChangeType == ChangeType.Removed)
            {
                Details = "'" + File.ShortPath + "' was removed.";
            }
            else if (ChangeType == ChangeType.ArchiveChanged)
            {
                Details = "'" + File.ShortPath + "' archive changed to " + file.Archive.ToString() + ".";
            }
            else if (ChangeType == ChangeType.HiddenChanged)
            {
                Details = "'" + File.ShortPath + "' hidden changed to " + file.Hidden.ToString() + ".";
            }
            else if (ChangeType == ChangeType.ReadOnlyChanged)
            {
                Details = "'" + File.ShortPath + "' read only changed to " + file.ReadOnly.ToString() + ".";
            }
            else
            {
                throw new ArgumentException("Unsupported ChangeType", "changeType");
            }
        }
예제 #2
0
        /// <summary>
        /// Recursively searches for all files within <see cref="RootDirectory"/> and its subdirectories,
        /// and adds them to <see cref="Files"/>.
        /// </summary>
        /// <param name="writeToConsole">When set to true, each file will be echoed to the Console.</param>
        public void PopulateFiles(bool writeToConsole)
        {
            foreach (var file in RootDirectory.GetFiles("*", SearchOption.AllDirectories))
            {
                var watchedFile = new WatchedFile(file, RootDirectory);
                watchedFile.Refresh();

                Files.Add(watchedFile);

                if (writeToConsole)
                {
                    Console.WriteLine("Registered " + file.Name + ".");
                }
            }
        }