예제 #1
0
    /// <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;
    }
예제 #2
0
		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;
		}
예제 #3
0
		/// <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();
			}
		}
예제 #4
0
        /// <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;
        }