Пример #1
0
        static void Main(string[] args)
        {
            string root = @"C:\dotnetmentoring";

            FileSystemVisitor.Started        += () => { Console.WriteLine("FileSystemVisitor started searching..."); };
            FileSystemVisitor.Finished       += () => { Console.WriteLine("FileSystemVisitor finished searching..."); };
            FileSystemVisitor.DirectoryFound += (object sender, ItemFoundEventArgs <DirectoryInfo> e) =>
            {
                Console.WriteLine($"{e.FoundItemInfo.Name} is found");
                e.CancelRequested = true;
            };

            var fileSystemVisitor = new FileSystemVisitor(root);

            foreach (var item in fileSystemVisitor)
            {
                Console.WriteLine(item);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (!int.TryParse(ConfigurationManager.AppSettings["numberOfDirectories"], out var numberOfDirectories))
            {
                throw new ArgumentException($"Incorrect setting value {ConfigurationManager.AppSettings["numberOfDirectories"]}");
            }

            if (!int.TryParse(ConfigurationManager.AppSettings["numberOfFiles"], out var numberOfFiles))
            {
                throw new ArgumentException($"Incorrect setting value {ConfigurationManager.AppSettings["numberOfFiles"]}");
            }

            var visitor = new FileSystemVisitor(
                new Validator(x => x.Contains("Debug")),
                new SaveManager());

            var rootPath             = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["nameDirectory"]);
            var expectedItemsForSave = EnvironmentBuilder.Create(numberOfDirectories, numberOfFiles);
            var listener             = new Listener(visitor, expectedItemsForSave + 1, expectedItemsForSave + 1);

            visitor.Search(rootPath);

            Directory.Delete(rootPath, true);
        }