private void RefreshEditor() { XmlEditorService es = GetService(typeof(XmlEditorService)) as XmlEditorService; _store = es.CreateXmlStore(); _store.UndoManager = _undoManager; _model = _store.OpenXmlModel(new Uri(_fileName)); _textBuffer.Reload(1); if (ManifestEditorFactory.ExcuteToCheckXmlRule(_fileName)) { _ManifestDesignerControl.IsEnabled = true; try { _ManifestDesignerControl.Refresh(new ViewModelTizen(_store, _model, this, _textBuffer)); var vsRunningDocumentTable = GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; var hr = vsRunningDocumentTable.NotifyDocumentChanged(_documentCookie, (uint)__VSRDTATTRIB.RDTA_DocDataReloaded); ErrorHandler.ThrowOnFailure(hr); } catch { } } else { _ManifestDesignerControl.IsEnabled = false; } }
protected virtual void addRegisteredSchema(object sender, System.EventArgs args) { string fileName = XmlEditorService.BrowseForSchemaFile(); if (string.IsNullOrEmpty(fileName)) { return; } string shortName = System.IO.Path.GetFileName(fileName); //load the schema XmlSchemaCompletionData schema = null; try { schema = new XmlSchemaCompletionData(fileName); } catch (Exception ex) { string msg = GettextCatalog.GetString("Error loading schema '{0}'.", shortName); MessageService.ShowException(ex, msg); return; } // Make sure the schema has a target namespace. if (schema.NamespaceUri == null) { MessageService.ShowError( GettextCatalog.GetString("Schema '{0}' has no target namespace.", shortName)); return; } //if namaspace conflict, ask user whether they want to replace existing schema XmlSchemaCompletionData oldSchema = GetRegisteredSchema(schema.NamespaceUri); if (oldSchema != null) { bool replace = MessageService.Confirm( GettextCatalog.GetString( "A schema is already registered with the namespace '{0}'. Would you like to replace it?", schema.NamespaceUri), new AlertButton(GettextCatalog.GetString("Replace")) ); if (!replace) { return; } //remove the old schema RemoveRegisteredSchema(oldSchema); } // Store the schema so we can add it for real later, if the "ok" button's clicked TreeIter newIter = AddRegisteredSchema(schema); registeredSchemasView.Selection.SelectIter(newIter); ScrollToSelection(registeredSchemasView); }
public async Task ValidateXsltValid() { var text = @"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:variable name='foo' select='bar' /> </xsl:stylesheet>"; var results = await XmlEditorService.Validate(text, "test.xslt", CancellationToken.None); Assert.AreEqual(0, results.Count); }
public void TestTransformCompileFile() { var xslt = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""> <xsl:emplate match='foo'><a>bar=<xsl:value-of select='bar'/>;<xsl:apply-templates select='baz'/></a></xsl:emplate> <xsl:template match='baz'>baz=<xsl:value-of select='.'/>;</xsl:template> </xsl:stylesheet>"; var expected = "'xsl:emplate' cannot be a child of the 'xsl:stylesheet' element."; (var transform, var error) = XmlEditorService.CompileStylesheet(xslt, "test.xml"); Assert.NotNull(error); Assert.IsNull(transform); Assert.AreEqual(expected, error.ErrorText); }
public async Task ValidateXsltInvalid() { var text = @"<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:varibble name='foo' select='bar' /> </xsl:stylesheet>"; var results = await XmlEditorService.Validate(text, "test.xslt", CancellationToken.None); Assert.AreEqual(1, results.Count); Assert.AreEqual("test.xslt", results [0].FileName); Assert.AreEqual(2, results [0].Line); Assert.AreEqual(2, results [0].Column); Assert.IsTrue(results [0].ErrorText.StartsWith("The element 'stylesheet' in namespace 'http://www.w3.org/1999/XSL/Transform' has invalid child element 'varibble'", System.StringComparison.Ordinal)); }
public void TestTransform() { var xml = @"<?xml-stylesheet type='text/xsl' href='hello.xsl'?> <foo><bar>thing</bar><baz>other</baz></foo>"; var xslt = @"<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""1.0""> <xsl:template match='foo'><a>bar=<xsl:value-of select='bar'/>;<xsl:apply-templates select='baz'/></a></xsl:template> <xsl:template match='baz'>baz=<xsl:value-of select='.'/>;</xsl:template> </xsl:stylesheet>"; var expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?><a>bar=thing;baz=other;</a>"; (var transform, var error) = XmlEditorService.CompileStylesheet(xslt, "test.xml"); Assert.NotNull(transform); Assert.IsNull(error); var outWriter = new EncodedStringWriter(System.Text.Encoding.UTF8); using (var reader = XmlReader.Create(new StringReader(xml))) { transform.Transform(reader, null, outWriter); } Assert.AreEqual(expected, outWriter.ToString()); }
/// <summary> /// Called after the WindowPane has been sited with an IServiceProvider from the environment /// protected override void Initialize() { base.Initialize(); // Create and initialize the editor #region Register with IOleComponentManager IOleComponentManager componentManager = (IOleComponentManager)GetService(typeof(SOleComponentManager)); if (this._componentId == 0 && componentManager != null) { OLECRINFO[] crinfo = new OLECRINFO[1]; crinfo[0].cbSize = (uint)Marshal.SizeOf(typeof(OLECRINFO)); crinfo[0].grfcrf = (uint)_OLECRF.olecrfNeedIdleTime | (uint)_OLECRF.olecrfNeedPeriodicIdleTime; crinfo[0].grfcadvf = (uint)_OLECADVF.olecadvfModal | (uint)_OLECADVF.olecadvfRedrawOff | (uint)_OLECADVF.olecadvfWarningsOff; crinfo[0].uIdleTimeInterval = 100; int hr = componentManager.FRegisterComponent(this, crinfo, out this._componentId); ErrorHandler.Succeeded(hr); } #endregion ComponentResourceManager resources = new ComponentResourceManager(typeof(ManifestEditorPane)); #region Hook Undo Manager // Attach an IOleUndoManager to our WindowFrame. Merely calling QueryService // for the IOleUndoManager on the site of our IVsWindowPane causes an IOleUndoManager // to be created and attached to the IVsWindowFrame. The WindowFrame automaticall // manages to route the undo related commands to the IOleUndoManager object. // Thus, our only responsibilty after this point is to add IOleUndoUnits to the // IOleUndoManager (aka undo stack). _undoManager = (IOleUndoManager)GetService(typeof(SOleUndoManager)); // In order to use the IVsLinkedUndoTransactionManager, it is required that you // advise for IVsLinkedUndoClient notifications. This gives you a callback at // a point when there are intervening undos that are blocking a linked undo. // You are expected to activate your document window that has the intervening undos. if (_undoManager != null) { IVsLinkCapableUndoManager linkCapableUndoMgr = (IVsLinkCapableUndoManager)_undoManager; if (linkCapableUndoMgr != null) { linkCapableUndoMgr.AdviseLinkedUndoClient(this); } } #endregion // hook up our XmlEditorService es = GetService(typeof(XmlEditorService)) as XmlEditorService; _store = es.CreateXmlStore(); _store.UndoManager = _undoManager; _model = _store.OpenXmlModel(new Uri(_fileName)); // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable, // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on // the object returned by the Content property. //_vsDesignerControl = new VsDesignerControl(new ViewModel(_store, _model, this, _textBuffer)); EnvDTE.DTE dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _ManifestDesignerControl = new TizenManifestDesignerControl(new ViewModelTizen(_store, _model, this, _textBuffer), dte); Content = _ManifestDesignerControl; _ManifestDesignerControl.IsEnabledChanged += _ManifestDesignerControl_IsEnabledChanged; RegisterIndependentView(true); if (GetService(typeof(IMenuCommandService)) is IMenuCommandService mcs) { // Now create one object derived from MenuCommnad for each command defined in // the CTC file and add it to the command service. // For each command we have to define its id that is a unique Guid/integer pair, then // create the OleMenuCommand object for this command. The EventHandler object is the // function that will be called when the user will select the command. Then we add the // OleMenuCommand to the menu service. The addCommand helper function does all this for us. AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSStd97CmdID.NewWindow, new EventHandler(OnNewWindow), new EventHandler(OnQueryNewWindow)); AddCommand(mcs, VSConstants.GUID_VSStandardCommandSet97, (int)VSStd97CmdID.ViewCode, new EventHandler(OnViewCode), new EventHandler(OnQueryViewCode)); } }