Exemplo n.º 1
0
        private static void CreateTemporaryDirectory(ITempStorage tempStorage)
        {
            using ITempDirectory tempDir = tempStorage.NewTempDirectory();

            using ITempFile tempFile = tempDir.NewTempFile();
            tempFile.WriteAllText("some file content");

            using ITempDirectory subDir = tempDir.NewTempDirectory();
        }
Exemplo n.º 2
0
        /// <summary>Gets the full path to a file with the supplied name inside this temp directory.</summary>
        /// <param name="tempDirectory">The <see cref="ITempDirectory"/> instance to act on.</param>
        /// <param name="fileName">File name of the file path to generate.</param>
        /// <returns>The current <see cref="ITempDirectory.Name"/> combined with
        /// <paramref name="fileName"/>.</returns>
        public static string Combine(this ITempDirectory tempDirectory, string fileName)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException("tempDirectory");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            return(Path.Combine(tempDirectory.Name, fileName));
        }
Exemplo n.º 3
0
        /// <summary>Touches the given file in the temp directory.</summary>
        /// <param name="tempDirectory">The <see cref="ITempDirectory"/> instance to act on.</param>
        /// <param name="fileName">File name of the file path to generate.</param>
        /// <returns>The full path to the file created or updated.</returns>
        public static string Touch(this ITempDirectory tempDirectory, string fileName)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException("tempDirectory");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            string filePath = tempDirectory.Combine(fileName);

            EnsureDirectory(filePath);
            new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read | FileShare.Write | FileShare.Delete).Dispose();
            return(filePath);
        }
Exemplo n.º 4
0
        /// <summary>Writes text to the given file in the temp directory.</summary>
        /// <param name="tempDirectory">The <see cref="ITempDirectory"/> instance to act on.</param>
        /// <param name="fileName">File name of the file path to generate.</param>
        /// <param name="text">The text to write.</param>
        /// <returns>The full path to the file created or updated.</returns>
        public static string Write(this ITempDirectory tempDirectory, string fileName, string text)
        {
            if (tempDirectory == null)
            {
                throw new ArgumentNullException("tempDirectory");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            string filePath = tempDirectory.Combine(fileName);

            EnsureDirectory(filePath);
            File.WriteAllText(filePath, text, Encoding.UTF8);
            return(filePath);
        }
Exemplo n.º 5
0
 internal TempStorage(ITempDirectory directory)
 {
     this.directory = directory;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets directory for storing temporary files during the build process.
 /// </summary>
 public static string TempDirectory(this ITempDirectory config)
 {
     return($@"{config.WorkingDirectory()}\temp");
 }