當前位置: 首頁>>代碼示例>>C#>>正文


C# StorageFile.OpenTransactedWriteAsync方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:CQE,項目名稱:AOU-Manager-DataHandler,代碼行數:20,代碼來源:TextFile.cs

示例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);
                    }
                }));
        }
開發者ID:CHBase,項目名稱:chbase-windows8-sdk,代碼行數:17,代碼來源:PersonalImage.cs

示例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();
             }
         }
     }
 }
開發者ID:jijixi,項目名稱:PlistCS,代碼行數:12,代碼來源:Plist.cs

示例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();
                }
            });
        }
開發者ID:DaC24,項目名稱:azure-storage-net,代碼行數:13,代碼來源:CloudFile.cs

示例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();
         }
     });
 }
開發者ID:tamram,項目名稱:azure-storage-net,代碼行數:11,代碼來源:CloudBlob.cs

示例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();
                    }
                }
            }
        }
開發者ID:lindexi,項目名稱:Markdown,代碼行數:33,代碼來源:winmain.cs

示例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;
        }
開發者ID:poiiii,項目名稱:QBox-1,代碼行數:22,代碼來源:Files.cs


注:本文中的Windows.Storage.StorageFile.OpenTransactedWriteAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。