예제 #1
0
            /// <summary>
            /// Saves a user defined fit function in the user's application directory. The user is prompted
            /// by a message box if the function already exists.
            /// </summary>
            /// <param name="doc">The fit function script to save.</param>
            /// <returns>True if the function is saved, otherwise (error or user action) returns false.</returns>
            public bool SaveFitFunction(Altaxo.Scripting.FitFunctionScript doc)
            {
                if (doc.ScriptObject == null)
                {
                    Current.Gui.ErrorMessageBox("Only a successfully compiled fit function can be saved in the user fit function directory!");
                    return(false);
                }



                string filename     = Altaxo.Serialization.FileIOHelper.GetValidFileName(doc.FitFunctionCategory + "-" + doc.FitFunctionName + ".xml");
                string fullfilename = System.IO.Path.Combine(this._fitFunctionDirectory, filename);

                if (System.IO.File.Exists(fullfilename))
                {
                    if (!Current.Gui.YesNoMessageBox(string.Format("The file {0} already exists. Do you really want to overwrite the file?", filename), "Overwrite?", false))
                    {
                        return(false); // Cancel the end of dialog
                    }
                }

                System.IO.Stream stream = new System.IO.FileStream(fullfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                info.BeginWriting(stream);
                info.AddValue("FitFunctionScript", doc);
                info.EndWriting();
                stream.Close();

                AddFitFunctionEntry(doc.FitFunctionCategory, doc.FitFunctionName, doc.CreationTime, doc.FitFunctionDescription, fullfilename);

                return(true);
            }
예제 #2
0
        /// <summary>
        /// Saves the state of the main window into a zipped file.
        /// </summary>
        /// <param name="zippedStream">The file stream of the zip file.</param>
        /// <param name="info">The serialization info used to serialize the state of the main window.</param>
        public void SaveWindowStateToZippedFile(ICompressedFileContainerStream zippedStream, Altaxo.Serialization.Xml.XmlStreamSerializationInfo info)
        {
            System.Text.StringBuilder errorText = new System.Text.StringBuilder();

            {
                // first, we save our own state
                zippedStream.StartFile("Workbench/MainWindow.xml", 0);
                try
                {
                    info.BeginWriting(zippedStream.Stream);
                    info.AddValue("MainWindow", Current.Workbench);
                    info.EndWriting();
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // second, we save all workbench windows into the Workbench/Views
            int i = 0;

            foreach (IViewContent ctrl in Current.Workbench.ViewContentCollection)
            {
                if (info.IsSerializable(ctrl))
                {
                    i++;
                    zippedStream.StartFile("Workbench/Views/View" + i.ToString() + ".xml", 0);
                    try
                    {
                        info.BeginWriting(zippedStream.Stream);
                        info.AddValue("WorkbenchViewContent", ctrl);
                        info.EndWriting();
                    }
                    catch (Exception exc)
                    {
                        errorText.Append(exc.ToString());
                    }
                }
            }

            if (errorText.Length != 0)
            {
                throw new ApplicationException(errorText.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// Serializes the provided object <paramref name="toSerialize"/> into a new <see cref="T:System.Text.StringBuilder"/>.
        /// </summary>
        /// <param name="toSerialize">The object to serialize.</param>
        /// <returns>A <see cref="T:System.Text.StringBuilder"/> which contains the serialized object.</returns>
        /// <remarks>The object is serialized into a root node named 'Object'.</remarks>
        public static StringBuilder SerializeToStringBuilder(object toSerialize)
        {
            var stb  = new System.Text.StringBuilder();
            var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();

            info.BeginWriting(stb);

            info.AddValue("Object", toSerialize);

            info.EndWriting();
            return(stb);
        }
예제 #4
0
        protected virtual void InternalSaveUserSettingsBag()
        {
            var thisVersion = UserSettings.GetType().Assembly.GetName().Version;

            if (null != _userSettings.AssemblyVersionLoadedFrom && thisVersion < _userSettings.AssemblyVersionLoadedFrom)
            {
                var answer = Current.Gui.YesNoMessageBox(
                    string.Format(
                        "The existing UserSettings file was stored with a newer version of Altaxo (version {0}).\r\n" +
                        "Do you want to store and thus overwrite UserSettings now (with version {1})?", _userSettings.AssemblyVersionLoadedFrom, thisVersion),
                    "Attention!", false);

                if (false == answer)
                {
                    return; // User settings are not stored again if they originate from a newer version of Altaxo
                }
            }

            using (LockPropertyFile())
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(PropertiesFileName));

                System.IO.FileStream streamForWriting = null;
                for (int i = 500; i >= 0; --i) // Try to save the file, wait up to 10 seconds for getting the file (avoid exception if another instance is currently reading the properties file, especially with Com
                {
                    try
                    {
                        streamForWriting = new System.IO.FileStream(PropertiesFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, FileShare.None);
                        break;
                    }
                    catch (Exception)
                    {
                        if (0 == i)
                        {
                            throw;
                        }
                    }

                    System.Threading.Thread.Sleep(20);
                }

                using (var stream = streamForWriting)
                {
                    var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                    info.BeginWriting(stream);
                    info.AddValue("UserSettings", UserSettings);
                    info.EndWriting();
                    stream.Close();
                }
            }
        }
예제 #5
0
        public static void Save(WorksheetController ctrl, System.IO.Stream myStream, bool saveAsTemplate)
        {
            Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
            if (saveAsTemplate)
            {
                info.SetProperty("Altaxo.Data.DataColumn.SaveAsTemplate", "true");
            }
            info.BeginWriting(myStream);

            // TODO there is an issue with TableLayout that prevents a nice deserialization
            // this is because TableLayout stores the name of its table during serialization
            // onto deserialization this works well if the entire document is restored, but
            // doesn't work if only a table and its layout is to be restored. In this case, the layout
            // references the already present table with the same name in the document instead of the table
            // deserialized. Also, the GUID isn't unique if the template is deserialized more than one time.

            Altaxo.Worksheet.TablePlusLayout tableAndLayout =
                new Altaxo.Worksheet.TablePlusLayout(ctrl.DataTable, ctrl.WorksheetLayout);
            info.AddValue("TablePlusLayout", tableAndLayout);
            info.EndWriting();
        }
예제 #6
0
        protected void EhMenuFileSaveGraphAs_OnClick(object sender, System.EventArgs e)
        {
            System.IO.Stream myStream;
            SaveFileDialog   saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "Xml files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                    info.BeginWriting(myStream);
                    info.AddValue("Graph", this.Doc);
                    info.EndWriting();
                    myStream.Close();
                }
            }
        }
예제 #7
0
    public static void Save(WorksheetController ctrl, System.IO.Stream myStream, bool saveAsTemplate)
    {
      Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
      if(saveAsTemplate)
      {
        info.SetProperty("Altaxo.Data.DataColumn.SaveAsTemplate","true");
      }
      info.BeginWriting(myStream);

      // TODO there is an issue with TableLayout that prevents a nice deserialization 
      // this is because TableLayout stores the name of its table during serialization
      // onto deserialization this works well if the entire document is restored, but
      // doesn't work if only a table and its layout is to be restored. In this case, the layout
      // references the already present table with the same name in the document instead of the table
      // deserialized. Also, the GUID isn't unique if the template is deserialized more than one time.

      Altaxo.Worksheet.TablePlusLayout tableAndLayout = 
        new Altaxo.Worksheet.TablePlusLayout(ctrl.DataTable, ctrl.WorksheetLayout);
      info.AddValue("TablePlusLayout",tableAndLayout);
      info.EndWriting();    
    }
예제 #8
0
        public override void Run(Altaxo.Graph.GUI.GraphController ctrl)
        {
            System.IO.Stream myStream;
            SaveFileDialog   saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter           = "Altaxo graph files (*.axogrp)|*.axogrp|All files (*.*)|*.*";
            saveFileDialog1.FilterIndex      = 1;
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                    info.BeginWriting(myStream);
                    info.AddValue("Graph", ctrl.Doc);
                    info.EndWriting();
                    myStream.Close();
                }
            }
        }
예제 #9
0
        public override void Run(Graph3DController ctrl)
        {
            System.IO.Stream myStream;
            var saveFileDialog1 = new Microsoft.Win32.SaveFileDialog
            {
                Filter           = "Altaxo graph files (*.axogrp)|*.axogrp|All files (*.*)|*.*",
                FilterIndex      = 1,
                RestoreDirectory = true
            };

            if (true == saveFileDialog1.ShowDialog((System.Windows.Window)Current.Workbench.ViewObject))
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                    info.BeginWriting(myStream);
                    info.AddValue("Graph", ctrl.Doc);
                    info.EndWriting();
                    myStream.Close();
                }
            }
        }
예제 #10
0
        public void SaveToZippedFile(ICompressedFileContainerStream zippedStream, Altaxo.Serialization.Xml.XmlStreamSerializationInfo info)
        {
            System.Text.StringBuilder errorText = new System.Text.StringBuilder();

            // first, we save all tables into the tables subdirectory
            foreach (Altaxo.Data.DataTable table in this.m_DataSet)
            {
                try
                {
                    zippedStream.StartFile("Tables/" + table.Name + ".xml", 0);
                    //ZipEntry ZipEntry = new ZipEntry("Tables/"+table.Name+".xml");
                    //zippedStream.PutNextEntry(ZipEntry);
                    //zippedStream.SetLevel(0);
                    info.BeginWriting(zippedStream.Stream);
                    info.AddValue("Table", table);
                    info.EndWriting();
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // second, we save all graphs into the Graphs subdirectory
            foreach (GraphDocument graph in this.m_GraphSet)
            {
                try
                {
                    zippedStream.StartFile("Graphs/" + graph.Name + ".xml", 0);
                    //ZipEntry ZipEntry = new ZipEntry("Graphs/"+graph.Name+".xml");
                    //zippedStream.PutNextEntry(ZipEntry);
                    //zippedStream.SetLevel(0);
                    info.BeginWriting(zippedStream.Stream);
                    info.AddValue("Graph", graph);
                    info.EndWriting();
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // third, we save all TableLayouts into the TableLayouts subdirectory
            foreach (Altaxo.Worksheet.WorksheetLayout layout in this.m_TableLayoutList)
            {
                try
                {
                    zippedStream.StartFile("TableLayouts/" + layout.Name + ".xml", 0);
                    //ZipEntry ZipEntry = new ZipEntry("TableLayouts/"+layout.Name+".xml");
                    //zippedStream.PutNextEntry(ZipEntry);
                    //zippedStream.SetLevel(0);
                    info.BeginWriting(zippedStream.Stream);
                    info.AddValue("WorksheetLayout", layout);
                    info.EndWriting();
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // 4th, we save all FitFunctions into the FitFunctions subdirectory
            foreach (Altaxo.Scripting.FitFunctionScript fit in this._FitFunctionScripts)
            {
                try
                {
                    zippedStream.StartFile("FitFunctionScripts/" + fit.CreationTime.ToString() + ".xml", 0);
                    //ZipEntry ZipEntry = new ZipEntry("TableLayouts/"+layout.Name+".xml");
                    //zippedStream.PutNextEntry(ZipEntry);
                    //zippedStream.SetLevel(0);
                    info.BeginWriting(zippedStream.Stream);
                    info.AddValue("FitFunctionScript", fit);
                    info.EndWriting();
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }


            if (errorText.Length != 0)
            {
                throw new ApplicationException(errorText.ToString());
            }
        }
예제 #11
0
    public override void Run(Altaxo.Graph.GUI.GraphController ctrl)
    {
      System.IO.Stream myStream ;
      SaveFileDialog saveFileDialog1 = new SaveFileDialog();
 
      saveFileDialog1.Filter = "Altaxo graph files (*.axogrp)|*.axogrp|All files (*.*)|*.*"  ;
      saveFileDialog1.FilterIndex = 1 ;
      saveFileDialog1.RestoreDirectory = true ;
 
      if(saveFileDialog1.ShowDialog() == DialogResult.OK)
      {
        if((myStream = saveFileDialog1.OpenFile()) != null)
        {
          Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
          info.BeginWriting(myStream);
          info.AddValue("Graph",ctrl.Doc);
          info.EndWriting();
          myStream.Close();
        }
      }
    }
예제 #12
0
 /// <summary>
 /// Converts an object into its XML representation.
 /// </summary>
 /// <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param>
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     _xmlWriting.BeginWriting(writer);
     _xmlWriting.AddValue("WrappedObject", _wrappedObject);
     _xmlWriting.EndWriting();
 }
예제 #13
0
        public void SaveToZippedFile(ZipArchive zippedStream, Altaxo.Serialization.Xml.XmlStreamSerializationInfo info)
        {
            var errorText        = new System.Text.StringBuilder();
            int compressionLevel = 1;

            // DateTime time1 = DateTime.UtcNow;

            // first, we save all tables into the tables subdirectory
            foreach (Altaxo.Data.DataTable table in _dataTables)
            {
                try
                {
                    var zipEntry = zippedStream.CreateEntry("Tables/" + table.Name + ".xml");
                    using (var zs = zipEntry.Open())
                    {
                        //ZipEntry ZipEntry = new ZipEntry("Tables/"+table.Name+".xml");
                        //zippedStream.PutNextEntry(ZipEntry);
                        //zippedStream.SetLevel(0);
                        info.BeginWriting(zs);
                        info.AddValue("Table", table);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // second, we save all graphs into the Graphs subdirectory
            foreach (Graph.Gdi.GraphDocument graph in _graphs)
            {
                try
                {
                    var zipEntry = zippedStream.CreateEntry("Graphs/" + graph.Name + ".xml");
                    using (var zs = zipEntry.Open())
                    {
                        //ZipEntry ZipEntry = new ZipEntry("Graphs/"+graph.Name+".xml");
                        //zippedStream.PutNextEntry(ZipEntry);
                        //zippedStream.SetLevel(0);
                        info.BeginWriting(zs);
                        info.AddValue("Graph", graph);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // second, we save all graphs into the Graphs3D subdirectory
            foreach (Graph.Graph3D.GraphDocument graph in _graphs3D)
            {
                try
                {
                    var zipEntry = zippedStream.CreateEntry("Graphs3D/" + graph.Name + ".xml");
                    using (var zs = zipEntry.Open())
                    {
                        //ZipEntry ZipEntry = new ZipEntry("Graphs/"+graph.Name+".xml");
                        //zippedStream.PutNextEntry(ZipEntry);
                        //zippedStream.SetLevel(0);
                        info.BeginWriting(zs);
                        info.AddValue("Graph", graph);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // next, we save all notes documents
            foreach (var item in _textDocuments)
            {
                try
                {
                    var zipEntry = zippedStream.CreateEntry("Texts/" + item.Name + ".xml");
                    using (var zs = zipEntry.Open())
                    {
                        info.BeginWriting(zs);
                        info.AddValue("Text", item);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // third, we save all TableLayouts into the TableLayouts subdirectory
            foreach (Altaxo.Worksheet.WorksheetLayout layout in _tableLayouts)
            {
                if (layout.DataTable == null)
                {
                    continue; // dont save orphaned layouts
                }
                try
                {
                    var zipEntry = zippedStream.CreateEntry("TableLayouts/" + layout.Name + ".xml");
                    using (var zs = zipEntry.Open())
                    {
                        //ZipEntry ZipEntry = new ZipEntry("TableLayouts/"+layout.Name+".xml");
                        //zippedStream.PutNextEntry(ZipEntry);
                        //zippedStream.SetLevel(0);
                        info.BeginWriting(zs);
                        info.AddValue("WorksheetLayout", layout);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // 4th, we save all FitFunctions into the FitFunctions subdirectory
            foreach (Altaxo.Scripting.FitFunctionScript fit in _fitFunctionScripts)
            {
                try
                {
                    var zipEntry = zippedStream.CreateEntry("FitFunctionScripts/" + fit.CreationTime.ToString() + ".xml");
                    //ZipEntry ZipEntry = new ZipEntry("TableLayouts/"+layout.Name+".xml");
                    //zippedStream.PutNextEntry(ZipEntry);
                    //zippedStream.SetLevel(0);
                    using (var zs = zipEntry.Open())
                    {
                        info.BeginWriting(zs);
                        info.AddValue("FitFunctionScript", fit);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }
            {
                // 5th, we save all folder properties
                foreach (var folderProperty in _projectFolderProperties)
                {
                    try
                    {
                        var zipEntry = zippedStream.CreateEntry("FolderProperties/" + folderProperty.Name + ".xml");
                        //ZipEntry ZipEntry = new ZipEntry("TableLayouts/"+layout.Name+".xml");
                        //zippedStream.PutNextEntry(ZipEntry);
                        //zippedStream.SetLevel(0);
                        using (var zs = zipEntry.Open())
                        {
                            info.BeginWriting(zs);
                            info.AddValue("FolderProperty", folderProperty);
                            info.EndWriting();
                        }
                    }
                    catch (Exception exc)
                    {
                        errorText.Append(exc.ToString());
                    }
                }
            }

            {
                // nun noch den DocumentIdentifier abspeichern
                var zipEntry = zippedStream.CreateEntry("DocumentInformation.xml");
                using (var zs = zipEntry.Open())
                {
                    info.BeginWriting(zs);
                    info.AddValue("DocumentInformation", _documentInformation);
                    info.EndWriting();
                }
            }
            //  Current.Console.WriteLine("Saving took {0} sec.", (DateTime.UtcNow - time1).TotalSeconds);

            if (errorText.Length != 0)
            {
                throw new ApplicationException(errorText.ToString());
            }
        }
예제 #14
0
		protected void EhMenuFileSaveGraphAs_OnClick(object sender, System.EventArgs e)
		{
			System.IO.Stream myStream;
			SaveFileDialog saveFileDialog1 = new SaveFileDialog();

			saveFileDialog1.Filter = "Xml files (*.xml)|*.xml|All files (*.*)|*.*";
			saveFileDialog1.FilterIndex = 1;
			saveFileDialog1.RestoreDirectory = true;

			if (saveFileDialog1.ShowDialog() == DialogResult.OK)
			{
				if ((myStream = saveFileDialog1.OpenFile()) != null)
				{
					Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
					info.BeginWriting(myStream);
					info.AddValue("Graph", this.Doc);
					info.EndWriting();
					myStream.Close();
				}
			}
		}
예제 #15
0
      /// <summary>
      /// Saves a user defined fit function in the user's application directory. The user is prompted
      /// by a message box if the function already exists.
      /// </summary>
      /// <param name="doc">The fit function script to save.</param>
      /// <returns>True if the function is saved, otherwise (error or user action) returns false.</returns>
      public bool SaveFitFunction(Altaxo.Scripting.FitFunctionScript doc)
      {
        if (doc.ScriptObject == null)
        {
          Current.Gui.ErrorMessageBox("Only a successfully compiled fit function can be saved in the user fit function directory!");
          return false;
        }



        string filename = Altaxo.Serialization.FileIOHelper.GetValidFileName(doc.FitFunctionCategory + "-" + doc.FitFunctionName + ".xml");
        string fullfilename = System.IO.Path.Combine(this._fitFunctionDirectory, filename);

        if (System.IO.File.Exists(fullfilename))
        {
          if (!Current.Gui.YesNoMessageBox(string.Format("The file {0} already exists. Do you really want to overwrite the file?", filename), "Overwrite?", false))
            return false; // Cancel the end of dialog
        }

        System.IO.Stream stream = new System.IO.FileStream(fullfilename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
        Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
        info.BeginWriting(stream);
        info.AddValue("FitFunctionScript", doc);
        info.EndWriting();
        stream.Close();

        AddFitFunctionEntry(doc.FitFunctionCategory, doc.FitFunctionName, doc.CreationTime, doc.FitFunctionDescription, fullfilename);

        return true;
      }
예제 #16
0
		public override void Run(GraphController ctrl)
		{
			System.IO.Stream myStream;
			var saveFileDialog1 = new Microsoft.Win32.SaveFileDialog();

			saveFileDialog1.Filter = "Altaxo graph files (*.axogrp)|*.axogrp|All files (*.*)|*.*";
			saveFileDialog1.FilterIndex = 1;
			saveFileDialog1.RestoreDirectory = true;

			if (true == saveFileDialog1.ShowDialog((System.Windows.Window)Current.Workbench.ViewObject))
			{
				if ((myStream = saveFileDialog1.OpenFile()) != null)
				{
					Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
					info.BeginWriting(myStream);
					info.AddValue("Graph", ctrl.Doc);
					info.EndWriting();
					myStream.Close();
				}
			}
		}
예제 #17
0
        /// <summary>
        /// Saves the state of the main window into a zipped file.
        /// </summary>
        /// <param name="zippedStream">The file stream of the zip file.</param>
        /// <param name="info">The serialization info used to serialize the state of the main window.</param>
        public void SaveWindowStateToZippedFile(ZipArchive zippedStream, Altaxo.Serialization.Xml.XmlStreamSerializationInfo info)
        {
            var errorText = new System.Text.StringBuilder();

            {
                // first, we save our own state
                var zipEntry = zippedStream.CreateEntry("Workbench/MainWindow.xml", 0);
                try
                {
                    using (var zipEntryStream = zipEntry.Open())
                    {
                        info.BeginWriting(zipEntryStream);
                        info.AddValue("MainWindow", Current.Workbench.CreateMemento());
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            // second, we save all workbench windows into the Workbench/Views
            var selectedViewsMemento = new Altaxo.Gui.Workbench.ViewStatesMemento();
            int i = 0;

            foreach (IViewContent ctrl in Current.Workbench.ViewContentCollection)
            {
                if (info.IsSerializable(ctrl.ModelObject))
                {
                    i++;
                    var entryName = "Workbench/Views/View" + i.ToString() + ".xml";
                    if (ctrl.IsSelected)
                    {
                        selectedViewsMemento.SelectedView_EntryName = entryName;
                    }
                    var zipEntry = zippedStream.CreateEntry(entryName, 0);
                    try
                    {
                        using (var zipEntryStream = zipEntry.Open())
                        {
                            info.BeginWriting(zipEntryStream);
                            info.AddValue("ViewContentModel", ctrl.ModelObject);
                            info.EndWriting();
                        }
                    }
                    catch (Exception exc)
                    {
                        errorText.Append(exc.ToString());
                    }
                }
            }

            {
                // Save the states of the views
                var zipEntry = zippedStream.CreateEntry("Workbench/ViewStates.xml", 0);
                try
                {
                    using (var zipEntryStream = zipEntry.Open())
                    {
                        info.BeginWriting(zipEntryStream);
                        info.AddValue("ViewStates", selectedViewsMemento);
                        info.EndWriting();
                    }
                }
                catch (Exception exc)
                {
                    errorText.Append(exc.ToString());
                }
            }

            if (errorText.Length != 0)
            {
                throw new ApplicationException(errorText.ToString());
            }
        }