本文整理汇总了C#中Windows.Storage.StorageFile.OpenTransactedWriteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.OpenTransactedWriteAsync方法的具体用法?C# StorageFile.OpenTransactedWriteAsync怎么用?C# StorageFile.OpenTransactedWriteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFile
的用法示例。
在下文中一共展示了StorageFile.OpenTransactedWriteAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveToFileAsync
private async void SaveToFileAsync(StorageFile f, string content)
{
try
{
using (StorageStreamTransaction transaction = await f.OpenTransactedWriteAsync())
{
using (DataWriter dataWriter = new DataWriter(transaction.Stream))
{
dataWriter.WriteString(content);
transaction.Stream.Size = await dataWriter.StoreAsync(); // reset stream size to override the file
await transaction.CommitAsync();
}
}
}
catch (Exception ex)
{
AddLog("AddToFileAsync Error: " + ex.Message);
}
}
示例2: DownloadToFileAsync
public IAsyncOperation<bool> DownloadToFileAsync(IRecord record, StorageFile file)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
return AsyncInfo.Run(cancelToken => Task.Run(async () =>
{
using (
StorageStreamTransaction transaction =
await file.OpenTransactedWriteAsync().AsTask(cancelToken))
{
return await DownloadAsync(record, transaction.Stream).AsTask(cancelToken);
}
}));
}
示例3: writeXmlAsync
public static async Task writeXmlAsync(object value, StorageFile file)
{
if (file != null) {
using (var transaction = await file.OpenTransactedWriteAsync()) {
using (var writer = new DataWriter(transaction.Stream)) {
writer.WriteString(writeXml(value));
transaction.Stream.Size = await writer.StoreAsync();
await transaction.CommitAsync();
}
}
}
}
示例4: DownloadToFileAsync
public IAsyncAction DownloadToFileAsync(StorageFile target, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
{
CommonUtility.AssertNotNull("target", target);
return AsyncInfo.Run(async (token) =>
{
using (StorageStreamTransaction transaction = await target.OpenTransactedWriteAsync().AsTask(token))
{
await this.DownloadToStreamAsync(transaction.Stream, accessCondition, options, operationContext).AsTask(token);
await transaction.CommitAsync();
}
});
}
示例5: DownloadToFileAsync
public virtual Task DownloadToFileAsync(StorageFile target, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
{
return Task.Run(async () =>
{
using (StorageStreamTransaction transaction = await target.OpenTransactedWriteAsync().AsTask(cancellationToken))
{
await this.DownloadToStreamAsync(transaction.Stream.AsStream(), accessCondition, options, operationContext, cancellationToken);
await transaction.CommitAsync();
}
});
}
示例6: file_serialization
private async void file_serialization(StorageFile temp, string str)
{
int n;
if (temp.Name != "README.md")
{
str = "#" + title + "\n\n" + str;
}
n = str.IndexOf(advertisement);
if (n < 0)
{
str += advertisement;
}
//title
//str = "#" + title + "\n" + str;
str = str.Replace("\n", "\n\n");
str = str.Replace("\n\n\n\n", "\n\n");
str = str.Replace("\n", "\r\n");
//StorageFile temp = _file_storage.file;
if (temp != null)
{
using (StorageStreamTransaction transaction = await temp.OpenTransactedWriteAsync())
{
using (DataWriter data_writer = new DataWriter(transaction.Stream))
{
data_writer.WriteString(str);
transaction.Stream.Size = await data_writer.StoreAsync();
await transaction.CommitAsync();
}
}
}
}
示例7: SaveFile
public async void SaveFile()
{
if (Saved)
{
return;
}
var fileBuffer = await Response.Content.ReadAsBufferAsync();
int dotIndex = FullName.LastIndexOf('.');
var extName = FullName.Substring(dotIndex);
var savePicker = new Windows.Storage.Pickers.FileSavePicker();
savePicker.SuggestedStartLocation =
Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
savePicker.FileTypeChoices.Add(new KeyValuePair<string, IList<string>>("file", new List<string> { extName }));
savePicker.SuggestedFileName = FullName;
LocalStorage = await savePicker.PickSaveFileAsync();
var writeStream = await LocalStorage.OpenTransactedWriteAsync();
await writeStream.Stream.WriteAsync(fileBuffer);
await writeStream.CommitAsync();
Saved = true;
}