/// <summary>
        /// Executes the query.
        /// </summary>
        public override DocumentResults? ExecuteQuery(String input, String text)
        {
            try
            {
                var textDocument = new TextDocument(text);
                var root = csvCompiler.Parse(textDocument.Text);
                var response = input + " | convert-to-string";
                var controlFlowDescriptor = bootstrapper.Compiler.Parse(response);
                var controlFlow = bootstrapper.ControlFlowFactory.Create(controlFlowDescriptor);
                var result = controlFlow.Execute(new[] { root }) as String;

                var documentResults = new DocumentResults() {
                    Source = root.TextDocument.Text,
                    Results = result
                };

                return documentResults;
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error message: {0}", exception.Message);
                Console.WriteLine("Stacktrace: ");
                Console.WriteLine(exception.StackTrace);

                return null;
            }
        }
        /// <summary>
        /// Executes the query.
        /// </summary>
        public override DocumentResults?ExecuteQuery(String input, String text)
        {
            try
            {
                var textDocument          = new TextDocument(text);
                var root                  = csvCompiler.Parse(textDocument.Text);
                var response              = input + " | convert-to-string";
                var controlFlowDescriptor = bootstrapper.Compiler.Parse(response);
                var controlFlow           = bootstrapper.ControlFlowFactory.Create(controlFlowDescriptor);
                var result                = controlFlow.Execute(new[] { root }) as String;

                var documentResults = new DocumentResults()
                {
                    Source  = root.TextDocument.Text,
                    Results = result
                };

                return(documentResults);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error message: {0}", exception.Message);
                Console.WriteLine("Stacktrace: ");
                Console.WriteLine(exception.StackTrace);

                return(null);
            }
        }
            public void ShouldReturnTextRangeLength_WhenNotEmptyTextRangeIsPassed()
            {
                // Given in setup
                var textDocument = new TextDocument("hello");
                var textRange = textDocument.TextRange;

                // When
                var result = underTest.Run(textRange);

                // Then
                Assert.That(result, Is.EquivalentTo(new[] {5}));
            }
 public static TextRange CreateTextRange(String text)
 {
     var document = new TextDocument(text);
     return document.TextRange;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextRange"/> class.
 /// </summary>
 public TextRange(Int32 start, Int32 stop, TextDocument textDocument)
 {
     Start        = start;
     Stop         = stop;
     TextDocument = textDocument;
 }
            public void ShouldHandleHugeAmountTextSpans_WhenBatchModeIsActive(Int32 lines)
            {
                // Given
                var textBuilder = new StringBuilder();
                var line = "one,two,three,four";
                for (var i = 0; i < lines; i++)
                {
                    textBuilder.AppendLine(line);
                }

                var underTest = new TextDocument(textBuilder.ToString());
                var ranges = new List<TextRange>();

                for (var i = 0; i < lines; i++)
                {
                    var offset = (line.Length + Environment.NewLine.Length)*i;
                    ranges.Add(underTest.CreateOrGetTextRange(offset + 0, offset + 3));
                    underTest.CreateOrGetTextRange(offset + 4, offset + 7);
                }

                // When
                var watch = Stopwatch.StartNew();
                underTest.BeginTransaction();
                foreach (var range in ranges)
                {
                    underTest.ChangeText(range, "onetwo");
                }
                underTest.EndTransaction();
                watch.Stop();

                // Then
                Console.WriteLine(watch.Elapsed);
            }
 public override void Setup()
 {
     base.Setup();
     UnderTest = new TextDocument("Hello World!");
 }
            public void ShouldUpdateOverlappingTextRanges_AfterItChangedText()
            {
                // Given 
                var underTest = new TextDocument("0123456789");

                var words = new[]
                {
                    underTest.CreateOrGetTextRange(0, 4),
                    underTest.CreateOrGetTextRange(2, 10),
                };

                // When
                underTest.ChangeText(words[0], "9");
                var result = underTest.TextRanges
                                      .Where(range => range != underTest.TextRange)
                                      .Select(textRange => underTest.GetText(textRange)).ToArray();

                // Then
                Assert.That(result, Is.EquivalentTo(new[] {"9", "9456789"}));
            }