/// <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)) { EventSequenceDocument eventSequenceDocument = (EventSequenceDocument)document; EventSequenceDocument.Write(eventSequenceDocument, stream); } }
/// <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) { EventSequenceDocument document = control.Tag as EventSequenceDocument; if (document != null) { m_documentRegistry.ActiveDocument = document; EventSequenceContext context = document.As <EventSequenceContext>(); m_contextRegistry.ActiveContext = context; } }
/// <summary> /// Writes the given document to the given stream</summary> /// <param name="document">EventSequenceDocument</param> /// <param name="stream">Stream to write to</param> public static void Write(EventSequenceDocument document, Stream stream) { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("eventSequence"); DomNode root = document.DomNode; foreach (DomNode eventNode in root.GetChildren(DomTypes.eventSequenceType.eventChild)) { WriteEvent(eventNode, writer); } } }
/// <summary> /// Requests permission to close the client's Control. /// Allows user to save document before closing.</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; EventSequenceDocument document = control.Tag as EventSequenceDocument; 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 a custom file reader using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { node = EventSequenceDocument.Read(stream).DomNode; } } else { // create new document by creating a Dom node of the root type node = new DomNode(DomTypes.eventSequenceType.Type, DomTypes.eventSequenceRootElement); } EventSequenceDocument document = null; if (node != null) { // Initialize Dom extensions now that the data is complete node.InitializeExtensions(); EventSequenceContext context = node.As <EventSequenceContext>(); ControlInfo controlInfo = new ControlInfo(fileName, filePath, StandardControlGroup.Center); context.ControlInfo = controlInfo; // set document URI document = node.As <EventSequenceDocument>(); document.Uri = uri; context.ListView.Tag = document; // show the ListView control m_controlHostService.RegisterControl(context.ListView, controlInfo, this); } return(document); }
/// <summary> /// Writes the given document to the given stream</summary> /// <param name="document">EventSequenceDocument</param> /// <param name="stream">Stream to write to</param> public static void Write(EventSequenceDocument document, Stream stream) { using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("eventSequence"); DomNode root = document.DomNode; foreach (DomNode eventNode in root.GetChildren(DomTypes.eventSequenceType.eventChild)) WriteEvent(eventNode, writer); } }