public static void Run(Altaxo.Graph.GraphDocumentBase doc) { var miniProjectBuilder = new Altaxo.Graph.Procedures.MiniProjectBuilder(); var newDocument = miniProjectBuilder.GetMiniProject(doc, false); SaveProjectAs(newDocument); }
public int Load(IStorage pstg) { if (!(null == _document)) { throw new InvalidOperationException(nameof(_document) + " should be null"); } string documentName = null; Version altaxoVersion; ComDebug.ReportInfo("{0}.IPersistStorage.Load", GetType().Name); try { using (var stream = new ComStreamWrapper(pstg.OpenStream("AltaxoVersion", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true)) { var bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); var versionString = System.Text.Encoding.UTF8.GetString(bytes); altaxoVersion = Version.Parse(versionString); } ComDebug.ReportInfo("{0}.IPersistStorage.Load -> Version: {1}", GetType().Name, altaxoVersion); } catch (Exception ex) { ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoVersion, exception: {1}", GetType().Name, ex); } try { using (var stream = new ComStreamWrapper(pstg.OpenStream("AltaxoGraphName", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true)) { var bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); documentName = System.Text.Encoding.UTF8.GetString(bytes); } ComDebug.ReportInfo("{0}.IPersistStorage.Load -> Name of GraphDocument: {1}", GetType().Name, documentName); } catch (Exception ex) { ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoGraphName, exception: {1}", GetType().Name, ex); } try { Exception exInner = null; string loadErrors = null; using (var streamWrapper = new ComStreamWrapper(pstg.OpenStream("AltaxoProjectZip", IntPtr.Zero, (int)(STGM.READ | STGM.SHARE_EXCLUSIVE), 0), true)) { _comManager.InvokeGuiThread(() => { try { Current.IProjectService.CloseProject(true); loadErrors = Current.IProjectService.LoadProjectFromStream(streamWrapper); } catch (Exception ex) { exInner = ex; } }); } if (null != exInner) { throw exInner; } if (!string.IsNullOrEmpty(loadErrors)) { ComDebug.ReportInfo("{0}.IPersistStorage.Load Project loaded with errors: {1}", GetType().Name, loadErrors); } else { ComDebug.ReportInfo("{0}.IPersistStorage.Load Project loaded successfully", GetType().Name); } } catch (Exception ex) { ComDebug.ReportInfo("{0}.IPersistStorage.Load Failed to load stream AltaxoProjectZip, exception: {1}", GetType().Name, ex); } Marshal.ReleaseComObject(pstg); Altaxo.Graph.GraphDocumentBase newDocument = null; if (null != documentName) { if (Current.Project.GraphDocumentCollection.TryGetValue(documentName, out var newDocGdi)) { newDocument = newDocGdi; } else if (Current.Project.Graph3DDocumentCollection.TryGetValue(documentName, out var newDoc3D)) { newDocument = newDoc3D; } } if (null == newDocument) { if (null != Current.Project.GraphDocumentCollection.FirstOrDefault()) { newDocument = Current.Project.GraphDocumentCollection.First(); } else if (null != Current.Project.Graph3DDocumentCollection.FirstOrDefault()) { newDocument = Current.Project.Graph3DDocumentCollection.First(); } } if (null != newDocument) { Document = newDocument; _comManager.InvokeGuiThread(() => Current.IProjectService.ShowDocumentView(Document)); ComDebug.ReportInfo("{0}.IPersistStorage.Load ShowDocumentView for {1}", GetType().Name, Document.Name); } if (null == Document) { ComDebug.ReportError("{0}.IPersistStorage.Load Document is null, have to throw an exception now!!", GetType().Name); throw new InvalidOperationException(); } _isDocumentDirty = false; return(ComReturnValue.S_OK); }