示例#1
0
        /// <summary>
        /// Opens an file for writing
        /// </summary>
        /// <param name="path">The path.</param>
        /// <remarks>
        /// There could be one steps a) in case its to be uploaded a temp file will be created
        /// </remarks>
        public static ImprovedStream OpenWrite(string path, IProcessDisplay processDisplay = null, string recipient = null)
        {
            var retVal = new ImprovedStream()
            {
                WritePath      = path.RemovePrefix(),
                ProcessDisplay = processDisplay,
                Recipient      = recipient
            };

            if (path.AssumePgp() || path.AssumeGZip())
            {
                Log.Debug("Creating temporary file");
                retVal.TempFile = Path.GetTempFileName();

                // download the file to a temp file
                retVal.BaseStream = File.Create(retVal.TempFile);
            }
            else
            {
                FileSystemUtils.FileDelete(path.LongPathPrefix());
                retVal.BaseStream = File.Create(path.LongPathPrefix());
            }

            retVal.Stream = retVal.BaseStream;
            return(retVal);
        }
示例#2
0
 /// <summary>
 /// Closes the stream in case of a file opened for writing it would be uploaded to the sFTP
 /// </summary>
 public void Close()
 {
     if (Stream != null)
     {
         Stream.Close();
     }
     if (BaseStream != null)
     {
         BaseStream.Close();
     }
     try
     {
         if (!string.IsNullOrEmpty(WritePath))
         {
             CloseWrite();
         }
     }
     finally
     {
         FileSystemUtils.FileDelete(TempFile);
     }
 }