示例#1
0
        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 System.IO.Compression.ZipArchive(stream, System.IO.Compression.ZipArchiveMode.Create))
                    {
                        var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
                        projectToSave.SaveToZippedFile(zippedStream, info);
                    }
                    stream.Close();
                }

                if (null != saveEx)
                {
                    throw saveEx;
                }
            }
            catch (Exception ex)
            {
                ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex);
            }
            finally
            {
                Marshal.ReleaseComObject(pStgSave);
            }

            ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END");
        }
示例#2
0
        public void Save(IStorage pStgSave, bool fSameAsLoad)
        {
            ComDebug.ReportInfo("{0}.IPersistStorage.Save fSameAsLoad={1}", GetType().Name, fSameAsLoad);

            try
            {
                Exception saveEx = null;
                Ole32Func.WriteClassStg(pStgSave, GetType().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(_document.Name);
                    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))
                {
                    _comManager.InvokeGuiThread(() =>
                    {
                        saveEx = Current.IProjectService.SaveProject(stream);
                    }
                                                );
                }

                _isDocumentDirty = false;

                if (null != saveEx)
                {
                    throw saveEx;
                }
            }
            catch (Exception ex)
            {
                ComDebug.ReportError("{0}.IPersistStorage:Save threw an exception: {1}", GetType().Name, ex);
            }
            finally
            {
                Marshal.ReleaseComObject(pStgSave);
            }
        }
示例#3
0
		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 void Save(IStorage pStgSave, bool fSameAsLoad)
		{
			ComDebug.ReportInfo("{0}.IPersistStorage.Save fSameAsLoad={1}", this.GetType().Name, fSameAsLoad);

			try
			{
				Exception saveEx = null;
				Ole32Func.WriteClassStg(pStgSave, this.GetType().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(_document.Name);
					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))
				{
					_comManager.InvokeGuiThread(() =>
					{
						saveEx = Current.ProjectService.SaveProject(stream);
					}
					);
				}

				_isDocumentDirty = false;

				if (null != saveEx)
					throw saveEx;
			}
			catch (Exception ex)
			{
				ComDebug.ReportError("{0}.IPersistStorage:Save threw an exception: {1}", this.GetType().Name, ex);
			}
			finally
			{
				Marshal.ReleaseComObject(pStgSave);
			}
		}