コード例 #1
0
ファイル: PvcWatcher.cs プロジェクト: pauljz/pvc
        static void ProcessQueueItem()
        {
            FileSystemEventArgs eventQueueItem = null;

            if (EventQueue.TryDequeue(out eventQueueItem))
            {
                foreach (var item in Items)
                {
                    var pipe         = new PvcPipe();
                    var relativePath = PvcUtil.PathRelativeToCurrentDirectory(eventQueueItem.FullPath);

                    // if eventQueueItem.FullPath matches any items or their additional files, re-run that pipeline
                    var matchingFiles   = pipe.FilterPaths(item.Globs);
                    var additionalFiles = pipe.FilterPaths(item.AdditionalFiles);

                    if (matchingFiles.Contains(relativePath) || additionalFiles.Contains(relativePath))
                    {
                        var newStreams = new List <PvcStream>();

                        // if its an 'additional file' match we need to run on the whole matching set to find the 'real'
                        // file that should be processed. Same if it was a deletion event.
                        if (additionalFiles.Contains(relativePath) || eventQueueItem.ChangeType == WatcherChangeTypes.Deleted)
                        {
                            newStreams.AddRange(matchingFiles.Select(x => PvcUtil.PathToStream(x)));
                        }
                        // otherwise we run against only the changed item
                        else
                        {
                            newStreams.Add(PvcUtil.PathToStream(eventQueueItem.FullPath));
                        }

                        pipe.streams = newStreams;

                        newStreams.ForEach(x => Console.WriteLine("Processing pipeline for '{0}'", x.StreamName.Magenta()));
                        var stopwatch = new Stopwatch();
                        stopwatch.Start();

                        foreach (var pipeline in item.Pipeline)
                        {
                            try
                            {
                                pipe = pipeline(pipe);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }

                        stopwatch.Stop();
                        Console.WriteLine("Finished pipeline processing in {0}", stopwatch.Elapsed.Humanize().White());

                        newStreams.ForEach(x => x.UnloadStream());
                    }
                }
            }
        }
コード例 #2
0
        public PvcPipe Source(params string[] inputs)
        {
            inputs = inputs.Select(x => x.TrimStart('~')).ToArray();
            this.globs.AddRange(inputs);

            var globs   = inputs.Where(x => Regex.IsMatch(x, @"(\*|\!)"));
            var streams = inputs.Except(globs).Concat(FilterPaths(globs))
                          .Select(x => new { RelativePath = PvcUtil.PathRelativeToCurrentDirectory(x), FullPath = Path.GetFullPath(x) })
                          .Select(x => new PvcStream(() => new FileStream(x.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)).As(x.RelativePath, x.FullPath));

            this.streams = this.streams.Concat(streams);
            return(this);
        }
コード例 #3
0
        internal IEnumerable <string> FilterPaths(IEnumerable <string> globs)
        {
            var allPaths    = Directory.EnumerateFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories).Select(x => PvcUtil.PathRelativeToCurrentDirectory(x));
            var miniMatches = globs.Select(g => new Minimatcher(g, minimatchOptions));

            return(miniMatches.SelectMany(m => m.Filter(allPaths)));
        }
コード例 #4
0
 public static PvcStream PathToStream(string path, string streamName = null)
 {
     return(new PvcStream(() => new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)).As(streamName ?? PvcUtil.PathRelativeToCurrentDirectory(path), path));
 }
コード例 #5
0
 public static PvcStream StringToStream(string data, string streamName)
 {
     return(PvcUtil.StringToStream(data, streamName, null));
 }