Esempio n. 1
0
		XamlContext TestContext(string xaml, int offset)
		{
			var fileName = new FileName("test.xaml");
			var textSource = new StringTextSource(xaml);
			SetUpWithCode(fileName, textSource);
			return XamlContextResolver.ResolveContext(fileName, textSource, offset);
		}
        public void CanGetTextFromReaderReturnedFromTextBufferCreateReader()
        {
            string expectedText = "abc";
            ITextSource textBuffer = new StringTextSource("abc");

            StringBuilder text = new StringBuilder();
            using (TextReader reader = textBuffer.CreateReader()) {
                Assert.AreEqual(expectedText, reader.ReadToEnd());
            }
        }
Esempio n. 3
0
 public static void Run(string fileName)
 {
     var textSource = new StringTextSource(File.ReadAllText(fileName));
     using (var textReader = textSource.CreateReader()) {
         using (var xmlReader = new XmlTextReader(textReader)) {
             Run(xmlReader);
         }
     }
     var doc = new AXmlParser().Parse(textSource);
     using (var xmlReader = doc.CreateReader()) {
         Run(xmlReader);
     }
     var xmlDocument = new XmlDocument();
     xmlDocument.Load(doc.CreateReader());
     xmlDocument.Save(Path.Combine(Program.TempPath, "savedXmlDocument.xml"));
     var xDocument = XDocument.Load(doc.CreateReader());
     xDocument.Save(Path.Combine(Program.TempPath, "savedXDocument.xml"));
 }
Esempio n. 4
0
		public static void Run(string fileName)
		{
			bool includeAttributes = true;
			var textSource = new StringTextSource(File.ReadAllText(fileName));
			using (var textReader = textSource.CreateReader()) {
				using (var xmlReader = new XmlTextReader(textReader)) {
					Run(xmlReader, includeAttributes);
				}
			}
			var doc = new AXmlParser().Parse(textSource);
			using (var xmlReader = doc.CreateReader()) {
				Run(xmlReader, includeAttributes);
			}
			var xmlDocument = new XmlDocument();
			xmlDocument.Load(doc.CreateReader());
			xmlDocument.Save(Path.Combine(Program.TempPath, "savedXmlDocument.xml"));
			var xDocument = XDocument.Load(doc.CreateReader());
			xDocument.Save(Path.Combine(Program.TempPath, "savedXDocument.xml"));
			File.WriteAllText(Path.Combine(Program.TempPath, "inputDocument.xml"), textSource.Text);
		}
Esempio n. 5
0
        internal static IVbpProjectSymbolCache FromProject(IVbpProject project)
        {
            VbpProjectSymbolCache impl = new VbpProjectSymbolCache(project);

            /* Initially iterate over each module, create its parse information, and cache it!
             */
            List<ElementBase> files = new List<ElementBase>();
            files.AddRange(project.GetOwnedProject().Modules);
            files.AddRange(project.GetOwnedProject().Classes);
            files.AddRange(project.GetOwnedProject().Forms);
            files.AddRange(project.GetOwnedProject().UserControls);

            foreach (ElementBase file in files)
            {
                string fn = file.GetAbsoluteFileName(project.GetOwnedProject());

                ITextSource ts = new StringTextSource(File.ReadAllText(fn));
                impl._cache[fn] = CreateParseInformation(fn, ts, project);
            }

            return impl;
        }
 public IList<FoldingRegion> GetFolds(string xml)
 {
     ITextSource textBuffer = new StringTextSource(xml);
     Folds = Parser.GetFolds(textBuffer);
     return Folds;
 }
        public static void Run(ITextSource originalXmlFile)
        {
            int seed;
            lock (sharedRnd) {
                seed = sharedRnd.Next();
            }
            Console.WriteLine(seed);
            Random rnd = new Random(seed);

            AXmlParser parser = new AXmlParser();
            StringBuilder b = new StringBuilder(originalXmlFile.Text);
            IncrementalParserState parserState = null;
            var versionProvider = new TextSourceVersionProvider();
            int totalCharactersParsed = 0;
            int totalCharactersChanged = originalXmlFile.TextLength;
            TimeSpan incrementalParseTime = TimeSpan.Zero;
            TimeSpan nonIncrementalParseTime = TimeSpan.Zero;
            Stopwatch w = new Stopwatch();
            for (int iteration = 0; iteration < 100; iteration++) {
                totalCharactersParsed += b.Length;
                var textSource = new StringTextSource(b.ToString(), versionProvider.CurrentVersion);
                w.Restart();
                var incrementalResult = parser.ParseIncremental(parserState, textSource, out parserState);
                w.Stop();
                incrementalParseTime += w.Elapsed;
                w.Restart();
                var nonIncrementalResult = parser.Parse(textSource);
                w.Stop();
                nonIncrementalParseTime += w.Elapsed;
                CompareResults(incrementalResult, nonIncrementalResult);

                incrementalResult.AcceptVisitor(new ValidationVisitor(textSource));

                // Randomly mutate the file:

                List<TextChangeEventArgs> changes = new List<TextChangeEventArgs>();
                int modifications = rnd.Next(0, 25);
                int offset = 0;
                for (int i = 0; i < modifications; i++) {
                    if (i == 0 || rnd.Next(0, 10) == 0)
                        offset = rnd.Next(0, b.Length);
                    else
                        offset += rnd.Next(0, Math.Min(10, b.Length - offset));
                    int originalOffset = rnd.Next(0, originalXmlFile.TextLength);
                    int insertionLength;
                    int removalLength;
                    switch (rnd.Next(0, 21) / 10) {
                        case 0:
                            removalLength = 0;
                            insertionLength = rnd.Next(0, Math.Min(50, originalXmlFile.TextLength - originalOffset));
                            break;
                        case 1:
                            removalLength = rnd.Next(0, Math.Min(20, b.Length - offset));
                            insertionLength = rnd.Next(0, Math.Min(20, originalXmlFile.TextLength - originalOffset));
                            break;
                        default:
                            removalLength = rnd.Next(0, b.Length - offset);
                            insertionLength = rnd.Next(0, originalXmlFile.TextLength - originalOffset);
                            break;
                    }
                    string removedText = b.ToString(offset, removalLength);
                    b.Remove(offset, removalLength);
                    string insertedText = originalXmlFile.GetText(originalOffset, insertionLength);
                    b.Insert(offset, insertedText);
                    versionProvider.AppendChange(new TextChangeEventArgs(offset, removedText, insertedText));
                    totalCharactersChanged += insertionLength;
                }
            }
            Console.WriteLine("Incremental parse time:     " + incrementalParseTime + " for " + totalCharactersChanged + " characters changed");
            Console.WriteLine("Non-Incremental parse time: " + nonIncrementalParseTime + " for " + totalCharactersParsed + " characters");
        }
 public void CanGetTextFromTextBufferTextProperty()
 {
     string expectedText = "abc";
     ITextSource textBuffer = new StringTextSource(expectedText);
     Assert.AreEqual(expectedText, textBuffer.Text);
 }