/// <summary> /// Opens a Altaxo project from a project file (without asking the user). /// </summary> /// <param name="filename"></param> private void Load(string filename) { System.Text.StringBuilder errorText = new System.Text.StringBuilder(); System.IO.FileStream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); ZipFile zipFile = new ZipFile(myStream); Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); AltaxoDocument newdocument = new AltaxoDocument(); ZipFileWrapper zipFileWrapper = new ZipFileWrapper(zipFile); try { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { Current.Workbench.CloseAllViews(); this.CurrentOpenProject = newdocument; RestoreWindowStateFromZippedFile(zipFile, info, newdocument); this.CurrentOpenProject.IsDirty = false; } catch (Exception exc) { errorText.Append(exc.ToString()); System.Windows.Forms.MessageBox.Show(Current.MainWindow, errorText.ToString(), "An error occured"); } finally { myStream.Close(); } if (errorText.Length != 0) { throw new ApplicationException(errorText.ToString()); } }
/// <summary> /// Opens a Altaxo project from a project file (without asking the user). /// </summary> /// <param name="filename"></param> private void Load(string filename) { System.Text.StringBuilder errorText = new System.Text.StringBuilder(); System.IO.FileStream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open); ZipFile zipFile = new ZipFile(myStream); Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); AltaxoDocument newdocument = new AltaxoDocument(); ZipFileWrapper zipFileWrapper = new ZipFileWrapper(zipFile); try { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { Current.Workbench.CloseAllViews(); this.CurrentOpenProject = newdocument; RestoreWindowStateFromZippedFile(zipFile, info, newdocument); this.CurrentOpenProject.IsDirty = false; } catch (Exception exc) { errorText.Append(exc.ToString()); System.Windows.Forms.MessageBox.Show(Current.MainWindow, errorText.ToString(), "An error occured"); } finally { myStream.Close(); } if (errorText.Length != 0) throw new ApplicationException(errorText.ToString()); }
/// <summary> /// Opens a Altaxo project from a stream. Any existing old project will be closed without confirmation. /// </summary> /// <param name="myStream">The stream from which to load the project.</param> /// <param name="filename">Either the filename of the file which stored the document, or null (e.g. myStream is a MemoryStream).</param> protected override string InternalLoadProjectFromStream(System.IO.Stream myStream, string filename) { var errorText = new System.Text.StringBuilder(); var oldProject = CurrentOpenProject; if (null != oldProject) { OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosing)); } try { Current.Workbench.CloseAllViews(); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { SetCurrentProject(null, string.Empty); } catch (Exception exc) { errorText.Append(exc.ToString()); } // Old project is now closed if (null != oldProject) { OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosed)); } // Now open new project OnProjectChanged(new ProjectEventArgs(null, filename, ProjectEventKind.ProjectOpening)); ZipArchive zipFile = null; ; AltaxoDocument newdocument = null; ; Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info; try { newdocument = new AltaxoDocument(); zipFile = new ZipArchive(myStream, ZipArchiveMode.Read); info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); } catch (Exception exc) { errorText.Append(exc.ToString()); return(errorText.ToString()); // this is unrecoverable - we must return } try { using (var suspendToken = newdocument.SuspendGetToken()) { newdocument.RestoreFromZippedFile(zipFile, info); } } catch (Exception exc) { errorText.Append(exc.ToString()); } try { SetCurrentProject(newdocument, filename); RestoreWindowStateFromZippedFile(zipFile, info, newdocument); info.AnnounceDeserializationEnd(newdocument, true); // Final call to deserialization end CurrentOpenProject.IsDirty = false; info.AnnounceDeserializationHasCompletelyFinished(); // Annonce completly finished deserialization, activate data sources of the Altaxo document OnProjectChanged(new ProjectEventArgs(CurrentOpenProject, filename, ProjectEventKind.ProjectOpened)); } catch (Exception exc) { errorText.Append(exc.ToString()); } return(errorText.ToString()); }
/// <summary> /// Opens a Altaxo project from a stream. Any existing old project will be closed without confirmation. /// </summary> /// <param name="myStream">The stream from which to load the project.</param> /// <param name="filename">Either the filename of the file which stored the document, or null (e.g. myStream is a MemoryStream).</param> private string InternalLoadProjectFromStream(System.IO.Stream myStream, string filename) { var errorText = new System.Text.StringBuilder(); var oldProject = CurrentOpenProject; if (null != oldProject) OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosing)); try { Current.Workbench.CloseAllViews(); } catch (Exception exc) { errorText.Append(exc.ToString()); } try { this.SetCurrentProject(null, string.Empty); } catch (Exception exc) { errorText.Append(exc.ToString()); } // Old project is now closed if (null != oldProject) OnProjectChanged(new ProjectEventArgs(oldProject, oldProject.Name, ProjectEventKind.ProjectClosed)); // Now open new project OnProjectChanged(new ProjectEventArgs(null, filename, ProjectEventKind.ProjectOpening)); ZipFile zipFile = null; ; AltaxoDocument newdocument = null; ; Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info; ZipFileWrapper zipFileWrapper; try { newdocument = new AltaxoDocument(); zipFile = new ZipFile(myStream); info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); zipFileWrapper = new ZipFileWrapper(zipFile); } catch (Exception exc) { errorText.Append(exc.ToString()); return errorText.ToString(); // this is unrecoverable - we must return } try { using (var suspendToken = newdocument.SuspendGetToken()) { newdocument.RestoreFromZippedFile(zipFileWrapper, info); } } catch (Exception exc) { errorText.Append(exc.ToString()); } try { this.SetCurrentProject(newdocument, filename); RestoreWindowStateFromZippedFile(zipFile, info, newdocument); info.AnnounceDeserializationEnd(newdocument, true); // Final call to deserialization end this.CurrentOpenProject.IsDirty = false; info.AnnounceDeserializationHasCompletelyFinished(); // Annonce completly finished deserialization, activate data sources of the Altaxo document OnProjectChanged(new ProjectEventArgs(this.CurrentOpenProject, filename, ProjectEventKind.ProjectOpened)); } catch (Exception exc) { errorText.Append(exc.ToString()); } return errorText.ToString(); }