本文整理汇总了C#中System.IO.FileStream.WriteRawAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.WriteRawAsync方法的具体用法?C# FileStream.WriteRawAsync怎么用?C# FileStream.WriteRawAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.WriteRawAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: persistStage
private async Task<Errorable<Stage>> persistStage(Stage stg)
{
FileInfo tmpFile = system.getTemporaryFile();
using (var fs = new FileStream(tmpFile.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, bufferSize: 16386, useAsync: true))
{
await fs.WriteRawAsync(stg.WriteTo(new StringBuilder()).ToString());
}
lock (FileSystem.SystemLock)
{
FileInfo fi = system.getStagePathByStageName(stg.Name);
if (fi.Exists)
fi.Delete();
// Create directory if it doesn't exist:
if (!fi.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
fi.Directory.Create();
}
// Write the contents to the file:
Debug.WriteLine(String.Format("New STAGE '{0}'", fi.FullName));
File.Move(tmpFile.FullName, fi.FullName);
}
return stg;
}
示例2: persistRef
private async Task<Errorable<Ref>> persistRef(Ref rf)
{
FileInfo tmpFile = system.getTemporaryFile();
// Write the ref's contents to the temporary file:
using (var fs = new FileStream(tmpFile.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 16384, true))
await fs.WriteRawAsync(rf.WriteTo(new StringBuilder()).ToString());
lock (FileSystem.SystemLock)
{
// TODO: would love to see FileInfo.DeleteAsync, DirectoryInfo.CreateAsync, etc.
FileInfo fi = system.getRefPathByRefName(rf.Name);
if (fi.Exists) fi.Delete();
else
// Create directory if it doesn't exist:
if (!fi.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
fi.Directory.Create();
}
// Move the temp file to the real file:
Debug.WriteLine(String.Format("New REF '{0}'", fi.FullName));
File.Move(tmpFile.FullName, fi.FullName);
}
return rf;
}
示例3: persistCommit
private async Task<Errorable<Commit>> persistCommit(Commit cm)
{
FileInfo tmpFile = system.getTemporaryFile();
// Write the commit contents to the file:
using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None, bufferSize: 16834, useAsync: true))
{
await fs.WriteRawAsync(cm.WriteTo(new StringBuilder()).ToString());
}
lock (FileSystem.SystemLock)
{
FileInfo fi = system.getPathByID(cm.ID);
// NOTE: if the record already exists we can either error out or overwrite the existing file with contents known to be good in the case the existing file got corrupt.
// Let's stick with the self-repair scenario since erroring out doesn't help anyone.
if (fi.Exists)
{
Debug.WriteLine(String.Format("Self-repair scenario: overwriting old CommitID {0} with new contents", cm.ID));
fi.Delete();
}
// Create directory if it doesn't exist:
if (!fi.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
fi.Directory.Create();
}
Debug.WriteLine(String.Format("New COMMIT '{0}'", fi.FullName));
File.Move(tmpFile.FullName, fi.FullName);
}
return cm;
}
示例4: persistTree
private async Task<Errorable<TreeNode>> persistTree(TreeNode tr)
{
Debug.Assert(tr != null);
// Check that all referenced blobs are already persisted:
foreach (var trbl in tr.Blobs)
{
if (!system.getPathByID(trbl.BlobID).Exists)
return new BlobIDRecordDoesNotExistError(trbl.BlobID);
}
// Check that all referenced blobs are already persisted:
foreach (var trtr in tr.Trees)
{
if (!system.getPathByID(trtr.TreeID).Exists)
return new TreeIDRecordDoesNotExistError(trtr.TreeID);
}
// Write the tree contents to the file:
FileInfo tmpFile = system.getTemporaryFile();
using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None, bufferSize: 16384, useAsync: true))
{
await fs.WriteRawAsync(tr.WriteTo(new StringBuilder()).ToString());
}
lock (FileSystem.SystemLock)
{
FileInfo fi = system.getPathByID(tr.ID);
// NOTE: if the record already exists we can either error out or overwrite the existing file with contents known to be good in the case the existing file got corrupt.
// Let's stick with the self-repair scenario since erroring out doesn't help anyone.
if (fi.Exists)
{
Debug.WriteLine(String.Format("Self-repair scenario: overwriting old TreeID {0} with new contents", tr.ID));
fi.Delete();
File.Move(tmpFile.FullName, fi.FullName);
return tr;
}
// Create directory if it doesn't exist:
if (!fi.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
fi.Directory.Create();
}
Debug.WriteLine(String.Format("New TREE '{0}'", fi.FullName));
File.Move(tmpFile.FullName, fi.FullName);
}
return tr;
}
示例5: persistTag
private async Task<Errorable<Tag>> persistTag(Tag tg)
{
// Write the commit contents to the file:
FileInfo tmpFile = system.getTemporaryFile();
using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
await fs.WriteRawAsync(tg.WriteTo(new StringBuilder()).ToString());
}
lock (FileSystem.SystemLock)
{
FileInfo fi = system.getPathByID(tg.ID);
// NOTE: if the record already exists we can either error out or overwrite the existing file with contents known to be good in the case the existing file got corrupt.
// Let's stick with the self-repair scenario since erroring out doesn't help anyone.
if (fi.Exists)
{
Debug.WriteLine(String.Format("Self-repair scenario: overwriting old TagID {0} with new contents", tg.ID));
fi.Delete();
}
// Create directory if it doesn't exist:
if (!fi.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fi.Directory.FullName));
fi.Directory.Create();
}
Debug.WriteLine(String.Format("New TAG '{0}'", fi.FullName));
File.Move(tmpFile.FullName, fi.FullName);
}
// Now keep track of the tag by its name:
tmpFile = system.getTemporaryFile();
using (var fs = new FileStream(tmpFile.FullName, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
await fs.WriteRawAsync(tg.ID.ToString());
}
lock (FileSystem.SystemLock)
{
FileInfo fiTracker = system.getTagPathByTagName(tg.Name);
// Does this tag name exist already?
if (fiTracker.Exists)
{
tmpFile.Delete();
return new TagNameAlreadyExistsError(tg.Name);
}
// Create directory if it doesn't exist:
if (!fiTracker.Directory.Exists)
{
Debug.WriteLine(String.Format("New DIR '{0}'", fiTracker.Directory.FullName));
fiTracker.Directory.Create();
}
Debug.WriteLine(String.Format("New TAG '{0}'", fiTracker.FullName));
File.Move(tmpFile.FullName, fiTracker.FullName);
}
return tg;
}