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 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 static void OpenWorksheetOrGraph(string filename) { object deserObject; Altaxo.Serialization.Xml.XmlStreamDeserializationInfo info; using (System.IO.Stream myStream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { info = new Altaxo.Serialization.Xml.XmlStreamDeserializationInfo(); info.BeginReading(myStream); deserObject = info.GetValue("Table", null); info.EndReading(); myStream.Close(); } // if it is a table, add it to the DataTableCollection if (deserObject is Altaxo.Data.DataTable) { Altaxo.Data.DataTable table = deserObject as Altaxo.Data.DataTable; if (table.Name == null || table.Name == string.Empty) { table.Name = Current.Project.DataTableCollection.FindNewTableName(); } else if (Current.Project.DataTableCollection.ContainsTable(table.Name)) { table.Name = Current.Project.DataTableCollection.FindNewTableName(table.Name); } Current.Project.DataTableCollection.Add(table); info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references Current.ProjectService.CreateNewWorksheet(table); } // if it is a table, add it to the DataTableCollection else if (deserObject is Altaxo.Worksheet.TablePlusLayout) { Altaxo.Worksheet.TablePlusLayout tableAndLayout = deserObject as Altaxo.Worksheet.TablePlusLayout; Altaxo.Data.DataTable table = tableAndLayout.Table; if (table.Name == null || table.Name == string.Empty) { table.Name = Current.Project.DataTableCollection.FindNewTableName(); } else if (Current.Project.DataTableCollection.ContainsTable(table.Name)) { table.Name = Current.Project.DataTableCollection.FindNewTableName(table.Name); } Current.Project.DataTableCollection.Add(table); if (tableAndLayout.Layout != null) { Current.Project.TableLayouts.Add(tableAndLayout.Layout); } info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references tableAndLayout.Layout.DataTable = table; // this is the table for the layout now Current.ProjectService.CreateNewWorksheet(table, tableAndLayout.Layout); } else if (deserObject is Altaxo.Graph.Gdi.GraphDocument) { Altaxo.Graph.Gdi.GraphDocument graph = deserObject as Altaxo.Graph.Gdi.GraphDocument; if (graph.Name == null || graph.Name == string.Empty) { graph.Name = Current.Project.GraphDocumentCollection.FindNewName(); } else if (Current.Project.GraphDocumentCollection.Contains(graph.Name)) { graph.Name = Current.Project.GraphDocumentCollection.FindNewName(graph.Name); } Current.Project.GraphDocumentCollection.Add(graph); info.AnnounceDeserializationEnd(Current.Project); // fire the event to resolve path references in the graph Current.ProjectService.CreateNewGraph(graph); } }