Esempio n. 1
0
        public static StylerService CreateInstance(IStylerOptions options)
        {
            var stylerServiceInstance = new StylerService {
                Options = options
            };

            stylerServiceInstance.NoNewLineElementsList         = stylerServiceInstance.Options.NoNewLineElements.ToList();
            stylerServiceInstance.NoNewLineMarkupExtensionsList = stylerServiceInstance.Options.NoNewLineMarkupExtensions.ToList();

            stylerServiceInstance.OrderRules = new AttributeOrderRules(options);

            stylerServiceInstance._elementProcessStatusStack.Clear();
            stylerServiceInstance._elementProcessStatusStack.Push(new ElementProcessStatus());

            return(stylerServiceInstance);
        }
Esempio n. 2
0
        public static StylerService CreateInstance(IStylerOptions options)
        {
            var stylerServiceInstance = new StylerService { Options = options };

            if (!String.IsNullOrEmpty(stylerServiceInstance.Options.NoNewLineElements))
            {
                stylerServiceInstance.NoNewLineElementsList = stylerServiceInstance.Options.NoNewLineElements.Split(',')
                    .Where(x => !String.IsNullOrWhiteSpace(x))
                    .Select(x => x.Trim())
                    .ToList();
            }
            stylerServiceInstance.OrderRules = new AttributeOrderRules(options);

            stylerServiceInstance._elementProcessStatusStack.Clear();
            stylerServiceInstance._elementProcessStatusStack.Push(new ElementProcessStatus());

            return stylerServiceInstance;
        }
Esempio n. 3
0
        public static StylerService CreateInstance(IStylerOptions options)
        {
            var stylerServiceInstance = new StylerService {
                Options = options
            };

            if (!String.IsNullOrEmpty(stylerServiceInstance.Options.NoNewLineElements))
            {
                stylerServiceInstance.NoNewLineElementsList = stylerServiceInstance.Options.NoNewLineElements.Split(',')
                                                              .Where(x => !String.IsNullOrWhiteSpace(x))
                                                              .Select(x => x.Trim())
                                                              .ToList();
            }
            stylerServiceInstance.OrderRules = new AttributeOrderRules(options);

            stylerServiceInstance._elementProcessStatusStack.Clear();
            stylerServiceInstance._elementProcessStatusStack.Push(new ElementProcessStatus());

            return(stylerServiceInstance);
        }
Esempio n. 4
0
        private void DoTest(string testInput, StylerService styler)
        {
            string actualOutputFile = testInput.Replace(".xaml", "_output.xaml");
            string expectedOutputFile = testInput.Replace(".xaml", "_output_expected.xaml");

            string output = styler.FormatFile(testInput);

            File.WriteAllText(actualOutputFile, output);

            Assert.IsTrue(FileCompare(actualOutputFile, expectedOutputFile));
        }
Esempio n. 5
0
        private void Execute(Document document)
        {
            if (!IsFormatableDocument(document))
            {
                return;
            }

            Properties xamlEditorProps = _dte.Properties["TextEditor", "XAML"];

            var stylerOptions = GetDialogPage(typeof (PackageOptions)).AutomationObject as IStylerOptions;

            stylerOptions.IndentSize = Int32.Parse(xamlEditorProps.Item("IndentSize").Value.ToString());
            stylerOptions.IndentWithTabs = (bool) xamlEditorProps.Item("InsertTabs").Value;

            StylerService styler = new StylerService(stylerOptions);

            var textDocument = (TextDocument) document.Object("TextDocument");

            TextPoint currentPoint = textDocument.Selection.ActivePoint;
            int originalLine = currentPoint.Line;
            int originalOffset = currentPoint.LineCharOffset;

            EditPoint startPoint = textDocument.StartPoint.CreateEditPoint();
            EditPoint endPoint = textDocument.EndPoint.CreateEditPoint();

            string xamlSource = startPoint.GetText(endPoint);
            xamlSource = styler.StyleDocument(xamlSource);

            startPoint.ReplaceText(endPoint, xamlSource, 0);

            if (originalLine <= textDocument.EndPoint.Line)
            {
                textDocument.Selection.MoveToLineAndOffset(originalLine, originalOffset);
            }
            else
            {
                textDocument.Selection.GotoLine(textDocument.EndPoint.Line);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Parse input document and verify output against 
        /// </summary>
        /// <param name="styler"></param>
        /// <param name="callerMemberName"></param>
        private void DoTest(StylerService styler, [System.Runtime.CompilerServices.CallerMemberName] string callerMemberName = "")
        {
            var testFileBaseName = Path.Combine("TestFiles", callerMemberName);

            // Excercise stylerService using supplied test xaml data
            string actualOutput = styler.ManipulateTreeAndFormatInput(File.ReadAllText(testFileBaseName + ".testxaml"));

            // Write output to ".actual" file for further investigation
            File.WriteAllText(testFileBaseName + ".actual", actualOutput, Encoding.UTF8);

            // Check result
            Assert.That(actualOutput, Is.EqualTo(File.ReadAllText(testFileBaseName + ".expected")));
        }