示例#1
0
 /// <summary>
 /// Write string contents to a file. See: https://github.com/FrendsPlatform/Frends.File#Write
 /// </summary>
 /// <returns>Object {string Path, double SizeInMegaBytes}</returns>
 public static async Task <WriteResult> Write([PropertyTab] WriteInput input, [PropertyTab] WriteOption options)
 {
     return(await ExecuteActionAsync(
                () => ExecuteWrite(input, options),
                options.UseGivenUserCredentialsForRemoteConnections,
                options.UserName,
                options.Password)
            .ConfigureAwait(false));
 }
示例#2
0
        private static async Task <WriteResult> ExecuteWrite(WriteInput input, WriteOption options)
        {
            var encoding = GetEncoding(options.FileEncoding, options.EnableBom, options.EncodingInString);
            var fileMode = GetAndCheckWriteMode(options.WriteBehaviour, input.Path);

            using (var fileStream = new FileStream(input.Path, fileMode, FileAccess.Write, FileShare.Write, 4096, useAsync: true))
                using (var writer = new StreamWriter(fileStream, encoding))
                {
                    await writer.WriteAsync(input.Content).ConfigureAwait(false);
                }

            return(new WriteResult(new FileInfo(input.Path)));
        }