private static void AfterStartingService <T>(ServiceConfigurator <T> configurator,
                                                     IEnumerable <FileSystemWatcherConfigurator.DirectoryConfiguration> configs, LogWriter log,
                                                     Action <TopshelfFileSystemEventArgs> fileSystemChanged) where T : class
        {
            configurator.AfterStartingService(() =>
            {
                foreach (FileSystemWatcherConfigurator.DirectoryConfiguration config in configs)
                {
                    if (config.GetInitialStateEvent)
                    {
                        log.Info("[Topshelf.FileSystemWatcher] Checking for InitialState Events");

                        string[] paths;
                        if (!string.IsNullOrWhiteSpace(config.FileFilter))
                        {
                            paths = Directory.GetFiles(config.Path, config.FileFilter);
                        }
                        else
                        {
                            paths = Directory.GetFiles(config.Path);
                        }

                        if (paths.Any())
                        {
                            foreach (string path in paths)
                            {
                                fileSystemChanged(FileSystemEventFactory.CreateCurrentStateFileSystemEvent(Path.GetDirectoryName(path), Path.GetFileName(path)));
                            }
                        }
                    }
                }
            });
        }
        private static FileSystemEventHandler CreateEventHandler(Action <TopshelfFileSystemEventArgs> fileSystemAction)
        {
            FileSystemEventHandler eventHandler = null;

            if (fileSystemAction != null)
            {
                eventHandler =
                    (sender, args) => fileSystemAction(FileSystemEventFactory.CreateNormalFileSystemEvent(args));
            }

            return(eventHandler);
        }