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(); }
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(); } } }
/// <summary> /// Internal routine to save a project under a given name. /// </summary> /// <param name="filename"></param> private void Save(string filename) { Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); bool fileAlreadyExists = System.IO.File.Exists(filename); System.IO.Stream myStream; string tempFileName = null; if (fileAlreadyExists) { tempFileName = System.IO.Path.GetTempFileName(); myStream = new System.IO.FileStream(tempFileName, System.IO.FileMode.Create, FileAccess.Write, FileShare.None); } else myStream = new System.IO.FileStream(filename, System.IO.FileMode.Create, FileAccess.Write, FileShare.None); ZipOutputStream zippedStream = new ZipOutputStream(myStream); ZipOutputStreamWrapper zippedStreamWrapper = new ZipOutputStreamWrapper(zippedStream); Exception savingException = null; try { this.openProject.SaveToZippedFile(zippedStreamWrapper, info); SaveWindowStateToZippedFile(zippedStreamWrapper, info); } catch (Exception exc) { savingException = exc; } zippedStream.Close(); myStream.Close(); try { if (savingException == null) { // Test the file for integrity string testfilename = tempFileName != null ? tempFileName : filename; myStream = new System.IO.FileStream(testfilename, System.IO.FileMode.Open, FileAccess.Read, FileShare.None); ZipFile zipFile = new ZipFile(myStream); foreach (ZipEntry zipEntry in zipFile) { if (!zipEntry.IsDirectory) { System.IO.Stream zipinpstream = zipFile.GetInputStream(zipEntry); } } zipFile.Close(); // end test } } catch (Exception exc) { savingException = exc; } // now, if no exception happened, copy the temporary file back to the original file if (null != tempFileName && null == savingException) { System.IO.File.Copy(tempFileName, filename, true); System.IO.File.Delete(tempFileName); } if (null != savingException) throw savingException; this.openProject.IsDirty = false; }
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(); } } }
public void RunOld1() { SaveFileDialog dlg = this.GetSaveAsDialog(); if(dlg.ShowDialog(Current.MainWindow) == DialogResult.OK) { System.IO.Stream myStream; if((myStream = dlg.OpenFile()) != null) { try { Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); ZipOutputStream zippedStream = new ZipOutputStream(myStream); Current.Project.SaveToZippedFile(new ZipOutputStreamWrapper(zippedStream), info); Current.ProjectService.SaveWindowStateToZippedFile(new ZipOutputStreamWrapper(zippedStream), info); zippedStream.Close(); Current.Project.IsDirty=false; } catch(Exception exc) { System.Windows.Forms.MessageBox.Show(Current.MainWindow,"An error occured saving the document, details see below:\n" + exc.ToString(),"Error",System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); } finally { myStream.Close(); } } } }
/// <summary> /// Internal routine to save a project under a given name. /// </summary> /// <param name="projectToSave">The project to save.</param> /// <param name="filename"></param> public static void SaveProject(Altaxo.AltaxoDocument projectToSave, string filename) { using (var myStream = new System.IO.FileStream(filename, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.None)) { using (var zippedStream = new ZipOutputStream(myStream)) { var zippedStreamWrapper = new ZipOutputStreamWrapper(zippedStream); var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); projectToSave.SaveToZippedFile(zippedStreamWrapper, info); zippedStream.Close(); } myStream.Close(); } }
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(); } } }
public static void InternalSaveMiniProject(IStorage pStgSave, AltaxoDocument projectToSave, string graphDocumentName) { ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject BEGIN"); try { Exception saveEx = null; Ole32Func.WriteClassStg(pStgSave, typeof(GraphDocumentEmbeddedComObject).GUID); // Store the version of this assembly { var assembly = System.Reflection.Assembly.GetExecutingAssembly(); Version version = assembly.GetName().Version; using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { string text = version.ToString(); byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text); stream.Write(nameBytes, 0, nameBytes.Length); } } // Store the name of the item using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(graphDocumentName); stream.Write(nameBytes, 0, nameBytes.Length); } // Store the project using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true)) { using (var zippedStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(stream)) { var zippedStreamWrapper = new Altaxo.Main.ZipOutputStreamWrapper(zippedStream); var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); projectToSave.SaveToZippedFile(zippedStreamWrapper, info); zippedStream.Close(); } stream.Close(); } if (null != saveEx) throw saveEx; } catch (Exception ex) { ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex); } finally { Marshal.ReleaseComObject(pStgSave); } ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END"); }
public Exception SaveProject(System.IO.Stream myStream) { Altaxo.Serialization.Xml.XmlStreamSerializationInfo info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo(); ZipOutputStream zippedStream = new ZipOutputStream(myStream); ZipOutputStreamWrapper zippedStreamWrapper = new ZipOutputStreamWrapper(zippedStream); Exception savingException = null; try { this._currentProject.SaveToZippedFile(zippedStreamWrapper, info); if (!Current.Gui.InvokeRequired()) SaveWindowStateToZippedFile(zippedStreamWrapper, info); } catch (Exception exc) { savingException = exc; } zippedStream.Flush(); zippedStream.Close(); myStream.Close(); return savingException; }
/// <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; }