/// <summary> /// Saves the document at the given URI</summary> /// <param name="document">Document to save</param> /// <param name="uri">New document URI</param> public void Save(IDocument document, Uri uri) { string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(m_schemaLoader.TypeCollection); WinGuiCommonDataDocument eventSequenceDocument = (WinGuiCommonDataDocument)document; writer.Write(eventSequenceDocument.DomNode, stream, uri); } }
/// <summary> /// Notifies the client that its Control has been activated. Activation occurs when /// the Control gets focus, or a parent "host" Control gets focus.</summary> /// <param name="control">Client Control that was activated</param> /// <remarks>This method is only called by IControlHostService if the Control was previously /// registered for this IControlHostClient.</remarks> void IControlHostClient.Activate(Control control) { WinGuiCommonDataDocument document = control.Tag as WinGuiCommonDataDocument; if (document != null) { m_documentRegistry.ActiveDocument = document; WinGuiCommonDataContext context = document.As <WinGuiCommonDataContext>(); m_contextRegistry.ActiveContext = context; } }
/// <summary> /// Requests permission to close the client's Control. /// Allows user to save document before it closes.</summary> /// <param name="control">Client Control to be closed</param> /// <returns>True if the Control can close, or false to cancel</returns> /// <remarks> /// 1. This method is only called by IControlHostService if the Control was previously /// registered for this IControlHostClient. /// 2. If true is returned, the IControlHostService calls its own /// UnregisterControl. The IControlHostClient has to call RegisterControl again /// if it wants to re-register this Control.</remarks> bool IControlHostClient.Close(Control control) { bool closed = true; WinGuiCommonDataDocument document = control.Tag as WinGuiCommonDataDocument; if (document != null) { closed = m_documentService.Close(document); if (closed) { m_contextRegistry.RemoveContext(document); } } return(closed); }
/// <summary> /// Opens or creates a document at the given URI</summary> /// <param name="uri">Document URI</param> /// <returns>Document, or null if the document couldn't be opened or created</returns> public IDocument Open(Uri uri) { DomNode node = null; string filePath = uri.LocalPath; string fileName = Path.GetFileName(filePath); if (File.Exists(filePath)) { // read existing document using standard XML reader using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { DomXmlReader reader = new DomXmlReader(m_schemaLoader); node = reader.Read(stream, uri); } } else { // create new document by creating a Dom node of the root type defined by the schema node = new DomNode(Schema.winGuiCommonDataType.Type, Schema.winGuiCommonDataRootElement); } WinGuiCommonDataDocument document = null; if (node != null) { // Initialize Dom extensions now that the data is complete node.InitializeExtensions(); WinGuiCommonDataContext context = node.As <WinGuiCommonDataContext>(); ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center); context.ControlInfo = controlInfo; // set document URI document = node.As <WinGuiCommonDataDocument>(); document.Uri = uri; context.ListView.Tag = document; // show the ListView control m_controlHostService.RegisterControl(context.ListView, controlInfo, this); } return(document); }