Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                ShowHelp();
                return;
            }

            var configurationPath = args[0];
            var configuration     = ConfigurationLoader.LoadConfiguration(configurationPath);

            bool listeningForChanges = false;

            var watchers     = new List <FileSystemWatcher>();
            var projectCount = configuration.Projects != null ? configuration.Projects.Length : 0;

            Console.WriteLine("Found projects: {0}", projectCount);
            if (projectCount > 0)
            {
                Console.WriteLine(string.Join(", ", configuration.Projects.Select(s => s.Name).ToArray()));
                foreach (var project in configuration.Projects)
                {
                    Console.WriteLine("{0}. Folders: {1}. Listening for changes: {2}", project.Name, project.Folders != null ? project.Folders.Length : 0, project.ListenChanges);
                    if (project.Folders != null)
                    {
                        listeningForChanges = listeningForChanges || project.ListenChanges;
                        foreach (var folder in project.Folders)
                        {
                            Console.WriteLine("{2}: {0} -> {1}. Special items: {3}", folder.Method, folder.Source, folder.Destination,
                                              folder.SpecialCareItems != null ? folder.SpecialCareItems.Length : 0);

                            if (project.ListenChanges)
                            {
                                var watcher = new FileSystemWatcher(folder.Source)
                                {
                                    Filter = "*.*",
                                    IncludeSubdirectories = true,
                                    NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName,
                                    EnableRaisingEvents   = false
                                };
                                watcher.Created += watcher_Created;
                                watcher.Renamed += watcher_Renamed;
                                watcher.Changed += watcher_Changed;
                                watcher.Deleted += watcher_Deleted;

                                watchers.Add(watcher);

                                watcher.EnableRaisingEvents = true;
                            }
                        }
                    }
                }
            }

            _configuration = configuration;
            InvokeLoop();

            if (listeningForChanges)
            {
                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
                foreach (var watcher in watchers)
                {
                    watcher.Dispose();
                }
                watchers.Clear();
            }
        }