Ejemplo n.º 1
0
        public static AskReplacementWriter Create(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            ReplaceOptions replaceOptions,
            Lazy <TextWriter> lazyWriter,
            ContentWriterOptions options,
            MatchOutputInfo outputInfo)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new AskValueReplacementWriter(input, replaceOptions, lazyWriter, options, outputInfo));

            case ContentDisplayStyle.Line:
                return(new AskLineReplacementWriter(input, replaceOptions, lazyWriter, options));

            case ContentDisplayStyle.UnmatchedLines:
            case ContentDisplayStyle.AllLines:
                throw new InvalidOperationException();

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
Ejemplo n.º 2
0
        protected override void ExecuteResult(
            FileSystemFinderResult result,
            SearchContext context,
            ContentWriterOptions writerOptions,
            Match match,
            string input,
            Encoding encoding,
            string baseDirectoryPath  = null,
            ColumnWidths columnWidths = null)
        {
            string indent = GetPathIndent(baseDirectoryPath);

            if (!Options.OmitPath)
            {
                WritePath(context, result, baseDirectoryPath, indent, columnWidths);
            }

            if (ContentFilter.IsNegative)
            {
                WriteLineIf(!Options.OmitPath, Verbosity.Minimal);
            }
            else
            {
                WriteMatches(input, match, writerOptions, context);
            }

            AskToContinue(context, indent);
        }
Ejemplo n.º 3
0
        public static ContentWriter CreateReplace(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            ReplaceOptions replaceOptions,
            ContentWriterOptions options,
            TextWriter?textWriter      = null,
            MatchOutputInfo?outputInfo = null)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new ValueReplacementWriter(input, replaceOptions, options, textWriter, outputInfo));

            case ContentDisplayStyle.Line:
                return(new LineReplacementWriter(input, replaceOptions, options, textWriter));

            case ContentDisplayStyle.AllLines:
                return(new AllLinesReplacementWriter(input, replaceOptions, options, textWriter));

            case ContentDisplayStyle.UnmatchedLines:
                throw new NotSupportedException($"Value '{contentDisplayStyle}' is not supported.");

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
Ejemplo n.º 4
0
        private void ExecuteInput(SearchContext context, string input)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Match?match = ContentFilter !.Match(input);

            ContentWriterOptions writerOptions = CreateContentWriterOptions("");

            if (match != null)
            {
                WriteContent(
                    context,
                    match,
                    input,
                    writerOptions,
                    fileMatch: null,
                    baseDirectoryPath: null,
                    isPathDisplayed: false);
            }

            stopwatch.Stop();

            if (ShouldWriteSummary())
            {
                context.Telemetry.Elapsed = stopwatch.Elapsed;

                Verbosity verbosity = (Options.IncludeSummary) ? Verbosity.Quiet : Verbosity.Detailed;

                WriteLine(verbosity);
                WriteContentSummary(context.Telemetry, verbosity);
                WriteLine(verbosity);
            }
        }
Ejemplo n.º 5
0
        private void ProcessResult(
            FileSystemFinderResult result,
            SearchContext context,
            ContentWriterOptions writerOptions,
            string baseDirectoryPath = null)
        {
            string indent = GetPathIndent(baseDirectoryPath);

            Encoding encoding = Options.DefaultEncoding;

            string input = ReadFile(result.Path, baseDirectoryPath, ref encoding, context, indent);

            if (input == null)
            {
                return;
            }

            Match match = Options.ContentFilter.Match(input, context.CancellationToken);

            if (match == null)
            {
                return;
            }

            ExecuteOrAddResult(result, context, writerOptions, match, input, encoding, baseDirectoryPath);
        }
Ejemplo n.º 6
0
        public static AskReplacementWriter Create(
            ContentDisplayStyle contentDisplayStyle,
            string input,
            IReplacer replacer,
            Lazy <TextWriter>?lazyWriter,
            ContentWriterOptions options,
            MatchOutputInfo?outputInfo,
            bool isInteractive,
            SpellcheckState?spellcheckState = null)
        {
            switch (contentDisplayStyle)
            {
            case ContentDisplayStyle.Value:
            case ContentDisplayStyle.ValueDetail:
                return(new AskValueReplacementWriter(
                           input,
                           replacer,
                           lazyWriter,
                           options,
                           outputInfo,
                           isInteractive,
                           spellcheckState));

            case ContentDisplayStyle.Line:
                return(new AskLineReplacementWriter(input, replacer, lazyWriter, options, isInteractive, spellcheckState));

            case ContentDisplayStyle.UnmatchedLines:
            case ContentDisplayStyle.AllLines:
                throw new InvalidOperationException();

            default:
                throw new InvalidOperationException($"Unknown enum value '{contentDisplayStyle}'.");
            }
        }
Ejemplo n.º 7
0
 public EmptyContentWriter(
     string input,
     ContentWriterOptions options,
     IResultStorage resultStorage = null) : base(input, options)
 {
     ResultStorage = resultStorage;
 }
Ejemplo n.º 8
0
 public ValueContentWriter(
     string input,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : this(input, ContentTextWriter.Default, options, storage, outputInfo)
 {
 }
Ejemplo n.º 9
0
 public AskLineContentWriter(
     string input,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, options, storage)
 {
     Ask = true;
 }
Ejemplo n.º 10
0
 public AllLinesContentWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, writer, options)
 {
     ResultStorage = storage;
 }
Ejemplo n.º 11
0
 public AskLineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options) : base(input, replaceOptions, lazyWriter, options)
 {
     MatchingLineCount = 0;
 }
Ejemplo n.º 12
0
 public AskValueContentWriter(
     string input,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : base(input, options, storage, outputInfo)
 {
     Ask = true;
 }
Ejemplo n.º 13
0
 public LineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     ContentWriterOptions options = null,
     TextWriter textWriter        = null) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
Ejemplo n.º 14
0
 public TextWriterContentWriter(
     string input,
     ReplaceOptions replaceOptions,
     TextWriter textWriter,
     ContentWriterOptions options) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
Ejemplo n.º 15
0
 public AskLineReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     bool isInteractive) : base(input, replaceOptions, lazyWriter, options, isInteractive)
 {
     MatchingLineCount = 0;
 }
Ejemplo n.º 16
0
 public AskValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo outputInfo) : base(input, replaceOptions, lazyWriter, options)
 {
     OutputInfo = outputInfo;
 }
Ejemplo n.º 17
0
 public UnmatchedLineWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options,
     IResultStorage?storage = null) : base(input, writer, options)
 {
     ResultStorage     = storage;
     MatchingLineCount = 0;
 }
Ejemplo n.º 18
0
 protected override void ExecuteMatchWithContentCore(
     FileMatch fileMatch,
     SearchContext context,
     ContentWriterOptions writerOptions,
     string?baseDirectoryPath  = null,
     ColumnWidths?columnWidths = null)
 {
     ExecuteMatchCore(fileMatch, context, baseDirectoryPath, columnWidths);
 }
Ejemplo n.º 19
0
        protected override void ExecuteMatchWithContentCore(
            FileMatch fileMatch,
            SearchContext context,
            ContentWriterOptions writerOptions,
            string?baseDirectoryPath  = null,
            ColumnWidths?columnWidths = null)
        {
            List <Capture>?groups = null;

            try
            {
                groups = ListCache <Capture> .GetInstance();

                MaxReason maxReason = GetCaptures(
                    fileMatch.ContentMatch !,
                    writerOptions.GroupNumber,
                    context,
                    isPathDisplayed: false,
                    predicate: Options.ContentFilter !.Predicate,
                    captures: groups);

                List <ICapture>?captures = GetCaptures(groups, context.CancellationToken);

                using (IEnumerator <ICapture> en = (captures ?? groups.Select(f => (ICapture) new RegexCapture(f))).GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        if (SpellcheckState != null)
                        {
                            SpellcheckState.CurrentPath = fileMatch.Path;
                        }

                        ExecuteMatchWithContentCore(
                            en,
                            captures?.Count ?? groups.Count,
                            maxReason,
                            fileMatch,
                            context,
                            writerOptions,
                            baseDirectoryPath,
                            columnWidths);
                    }
                }
            }
            finally
            {
                if (groups != null)
                {
                    ListCache <Capture> .Free(groups);
                }

                if (SpellcheckState != null)
                {
                    SpellcheckState.CurrentPath = null;
                }
            }
        }
Ejemplo n.º 20
0
 protected AskReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter> lazyWriter,
     ContentWriterOptions options) : base(input, options)
 {
     ReplaceOptions = replaceOptions;
     _lazyWriter    = lazyWriter;
 }
Ejemplo n.º 21
0
 public LineContentWriter(
     string input,
     ContentTextWriter writer,
     ContentWriterOptions options = null,
     IResultStorage storage       = null) : base(input, writer, options)
 {
     ResultStorage     = storage;
     MatchingLineCount = 0;
 }
Ejemplo n.º 22
0
 private ContentWriter CreateReplacementWriter(
     ContentDisplayStyle contentDisplayStyle,
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter      = null,
     MatchOutputInfo?outputInfo = null)
 {
     return(ContentWriter.CreateReplace(contentDisplayStyle, input, replacer, options, textWriter, outputInfo, SpellcheckState));
 }
Ejemplo n.º 23
0
 public AskLineReplacementWriter(
     string input,
     IReplacer replacer,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     bool isInteractive,
     SpellcheckState?spellcheckState = null) : base(input, replacer, lazyWriter, options, isInteractive, spellcheckState)
 {
     MatchingLineCount = 0;
 }
Ejemplo n.º 24
0
 protected ContentWriter(
     string input,
     ContentTextWriter?writer,
     ContentWriterOptions options)
 {
     Input             = input;
     Options           = options;
     MatchingLineCount = -1;
     Writer            = writer;
 }
Ejemplo n.º 25
0
 public ValueContentWriter(
     string input,
     ContentTextWriter writer,
     ContentWriterOptions options = null,
     IResultStorage storage       = null,
     MatchOutputInfo outputInfo   = null) : base(input, writer, options)
 {
     ResultStorage = storage;
     OutputInfo    = outputInfo;
 }
Ejemplo n.º 26
0
 public ValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     ContentWriterOptions options,
     TextWriter?textWriter      = null,
     MatchOutputInfo?outputInfo = null) : base(input, options, outputInfo: outputInfo)
 {
     ReplaceOptions = replaceOptions;
     _textWriter    = textWriter;
 }
Ejemplo n.º 27
0
 public AskValueReplacementWriter(
     string input,
     ReplaceOptions replaceOptions,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo?outputInfo,
     bool isInteractive) : base(input, replaceOptions, lazyWriter, options, isInteractive)
 {
     OutputInfo = outputInfo;
 }
Ejemplo n.º 28
0
 public AskValueReplacementWriter(
     string input,
     IReplacer replacer,
     Lazy <TextWriter>?lazyWriter,
     ContentWriterOptions options,
     MatchOutputInfo?outputInfo,
     bool isInteractive,
     SpellcheckState?spellcheckState = null) : base(input, replacer, lazyWriter, options, isInteractive, spellcheckState)
 {
     OutputInfo = outputInfo;
 }
Ejemplo n.º 29
0
 public LineReplacementWriter(
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter           = null,
     SpellcheckState?spellcheckState = null) : base(input, options)
 {
     Replacer        = replacer;
     _textWriter     = textWriter;
     SpellcheckState = spellcheckState;
 }
Ejemplo n.º 30
0
 public ValueReplacementWriter(
     string input,
     IReplacer replacer,
     ContentWriterOptions options,
     TextWriter?textWriter           = null,
     MatchOutputInfo?outputInfo      = null,
     SpellcheckState?spellcheckState = null) : base(input, options, outputInfo: outputInfo)
 {
     Replacer        = replacer;
     _textWriter     = textWriter;
     SpellcheckState = spellcheckState;
 }