Ejemplo n.º 1
0
        public void WriteFile(string filePath, Stream fileContents)
        {
            ITransaction transaction = ObtainCurrentTransaction();

            if (transaction != null)
            {
                // We're participating in a transaction, use the TransactionalFileWriter to write the file.
                TransactionalFileWriter fileWriter = GetFileWriterForTransaction(transaction);
                transaction.Enlist(fileWriter);
                fileWriter.CreateFromStream(filePath, fileContents);
            }
            else
            {
                // No transaction, just write the stream to a file.
                FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                StreamUtil.Copy(fileContents, fs);
                fs.Flush();
                fs.Close();
            }
        }