Exemple #1
0
        static void Main(string[] args)
        {
            var settings = new Settings(args);
            if (!args.Any())
            {
                PrintHelp();
                return;
            }
            if (settings.Errors.Any())
            {
                settings.Errors.ForEach(Console.WriteLine);
                return;
            }

            var handler = new QueuedSqlChangeHandlerDecorator(new SqlChangeHandler(settings));
            handler.Prepare();

            CreateWatcher(settings,
                (sender, e) =>
                {
                    if (e.ChangeType.HasFlag(WatcherChangeTypes.Changed))
                    {
                        handler.Handle(oldPath: null, newPath: NormalizePath(e.FullPath));
                    }
                },
                (sender, e) =>
                {
                    handler.Handle(oldPath: NormalizePath(e.OldFullPath), newPath: NormalizePath(e.FullPath));
                });

            Console.ReadKey();
        }
Exemple #2
0
 public static SqlProjectInfo Create(Settings settings)
 {
     using (Profiling.Profile())
     {
         var project = new SqlProjectInfo();
         project.FileToEntityMapping = Profiling.Profile("GetFileToEntityMapping", () => GetFileToEntityMapping(settings));
         project.DependentEntities = Profiling.Profile("GetDependentEntities", () => GetDependentEntities(project.FileToEntityMapping));
         //project.VerifyNoCycles();
         //project.PrintCommonWords();
         return project;
     }
 }
Exemple #3
0
        private static void CreateWatcher(
            Settings settings,
            FileSystemEventHandler handler,
            RenamedEventHandler renamedHandler)
        {
            var watcher = new FileSystemWatcher(settings.Path)
            {
                IncludeSubdirectories = true,
                NotifyFilter = NotifyFilters.DirectoryName
                               | NotifyFilters.FileName
                               | NotifyFilters.LastWrite,
                EnableRaisingEvents = true,
                Filter = "*.sql"
            };

            watcher.Changed += handler;
            watcher.Created += handler;
            watcher.Deleted += handler;
            watcher.Renamed += renamedHandler;
        }
Exemple #4
0
 private static Dictionary<string, SqlEntity> GetFileToEntityMapping(Settings settings)
 {
     return Directory
         .EnumerateFiles(settings.Path, "*.sql", SearchOption.AllDirectories)
         .AsParallel().WithDegreeOfParallelism(4).WithExecutionMode(ParallelExecutionMode.ForceParallelism)
         .Select(filePath => new { path = filePath, content = GetContent(filePath) })
         .Select(e => SqlEntity.Create(e.path, e.content, settings))
         .Where(e => e.Type != SqlEntityType.Unknown)
         .AsSequential()
         .ToDictionary(e => e.Path, e => e);
 }
 public SqlChangeHandler(Settings settings)
 {
     this.settings = settings;
 }