当前位置: 首页>>代码示例>>C#>>正文


C# IInputStream.AsStreamForRead方法代码示例

本文整理汇总了C#中IInputStream.AsStreamForRead方法的典型用法代码示例。如果您正苦于以下问题:C# IInputStream.AsStreamForRead方法的具体用法?C# IInputStream.AsStreamForRead怎么用?C# IInputStream.AsStreamForRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IInputStream的用法示例。


在下文中一共展示了IInputStream.AsStreamForRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadTileSetAsync

 private static async Task<TileSet> LoadTileSetAsync(IInputStream stream)
 {
     using (var reader = new StreamReader(stream.AsStreamForRead()))
     {
         return JsonConvert.DeserializeObject<TileSet>(await reader.ReadToEndAsync());
     }
 }
开发者ID:ChinaRAUnion,项目名称:RedAlertPlus,代码行数:7,代码来源:TileSetReader.cs

示例2: CreateFromMVmap

 public static Vmap CreateFromMVmap(IInputStream stream)
 {
     return CreateFromVmap(stream.AsStreamForRead());
 }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:4,代码来源:VmapFactory.cs

示例3: UploadFromStreamAsync

        public IAsyncAction UploadFromStreamAsync(IInputStream source, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            CommonUtils.AssertNotNull("source", source);
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.BlockBlob, this.ServiceClient);
            operationContext = operationContext ?? new OperationContext();

            Stream sourceAsStream = source.AsStreamForRead();
            return AsyncInfo.Run(async (token) =>
            {
                DateTime streamCopyStartTime = DateTime.Now;
                CancellationToken streamCopyToken = token;
                if (modifiedOptions.MaximumExecutionTime.HasValue)
                {
                    // Setup token
                    CancellationTokenSource cts = new CancellationTokenSource(modifiedOptions.MaximumExecutionTime.Value);
                    CancellationToken tokenWithTimeout = cts.Token;

                    // Hookup users token
                    token.Register(() => cts.Cancel());

                    streamCopyToken = tokenWithTimeout;
                }

                if ((this.ServiceClient.ParallelOperationThreadCount == 1) &&
                    sourceAsStream.CanSeek &&
                    ((sourceAsStream.Length - sourceAsStream.Position) <= this.ServiceClient.SingleBlobUploadThresholdInBytes))
                {
                    string contentMD5 = null;
                    if (modifiedOptions.StoreBlobContentMD5.Value)
                    {
                        OperationContext tempOperationContext = new OperationContext();
                        StreamDescriptor streamCopyState = new StreamDescriptor();
                        long startPosition = sourceAsStream.Position;
                        await sourceAsStream.WriteToAsync(Stream.Null, null /* maxLength */, true, tempOperationContext, streamCopyState, streamCopyToken);
                        sourceAsStream.Position = startPosition;
                        contentMD5 = streamCopyState.Md5;
                    }

                    if (modifiedOptions.MaximumExecutionTime.HasValue)
                    {
                        modifiedOptions.MaximumExecutionTime -= DateTime.Now.Subtract(streamCopyStartTime);
                    }

                    await Executor.ExecuteAsyncNullReturn(
                        this.PutBlobImpl(sourceAsStream, contentMD5, accessCondition, modifiedOptions),
                        modifiedOptions.RetryPolicy,
                        operationContext,
                        token);
                }
                else
                {
                    await Task.Run(async () =>
                    {
                        IOutputStream writeStream = await this.OpenWriteAsync(accessCondition, options, operationContext);

                        // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                        // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                        using (Stream blobStream = writeStream.AsStreamForWrite(0))
                        {
                            await sourceAsStream.WriteToAsync(blobStream, null /* maxLength */, false, new OperationContext(), null /* streamCopyState */, streamCopyToken);
                        }
                    });
                }
            });
        }
开发者ID:nberardi,项目名称:azure-sdk-for-net,代码行数:66,代码来源:CloudBlockBlob.cs

示例4: CreateFromVast

 public static IAsyncOperation<AdDocumentPayload> CreateFromVast(IInputStream stream, int? maxRedirectDepth, bool allowMultipleAds)
 {
     return AsyncInfo.Run(c => CreateFromVast(stream.AsStreamForRead(), maxRedirectDepth, allowMultipleAds));
 }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:4,代码来源:AdModelFactory.cs

示例5: ReadFromStream

 public static StorageExtendedErrorInformation ReadFromStream(IInputStream inputStream)
 {
     return ReadFromStream(inputStream.AsStreamForRead());
 }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:4,代码来源:StorageExtendedErrorInformation.cs

示例6: UploadFromStreamAsyncHelper

        internal IAsyncAction UploadFromStreamAsyncHelper(IInputStream source, long? length, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
#endif
        {
            CommonUtility.AssertNotNull("source", source);

            Stream sourceAsStream = source.AsStreamForRead();
            if (!sourceAsStream.CanSeek)
            {
                throw new InvalidOperationException();
            }

            if (length.HasValue)
            {
                CommonUtility.AssertInBounds("length", length.Value, 1, sourceAsStream.Length - sourceAsStream.Position);
            }
            else
            {
                length = sourceAsStream.Length - sourceAsStream.Position;
            }

            FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient);
            operationContext = operationContext ?? new OperationContext();
            ExecutionState<NullType> tempExecutionState = CommonUtility.CreateTemporaryExecutionState(modifiedOptions);

#if ASPNET_K
            return Task.Run(async () =>
            {
                using (CloudFileStream fileStream = await this.OpenWriteAsync(length, accessCondition, options, operationContext, cancellationToken))
                {
                    // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                    // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                    await sourceAsStream.WriteToAsync(fileStream, length, null /* maxLength */, false, tempExecutionState, null /* streamCopyState */, cancellationToken);
                    await fileStream.CommitAsync();
                }
            }, cancellationToken);
#else
            return AsyncInfo.Run(async (token) =>
            {
                using (ICloudFileStream fileStream = await this.OpenWriteAsync(length, accessCondition, options, operationContext).AsTask(token))
                {
                    // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                    // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                    await sourceAsStream.WriteToAsync(fileStream.AsStreamForWrite(0), length, null /* maxLength */, false, tempExecutionState, null /* streamCopyState */, token);
                    await fileStream.CommitAsync().AsTask(token);
                }
            });
#endif
        }
开发者ID:DaC24,项目名称:azure-storage-net,代码行数:48,代码来源:CloudFile.cs

示例7: WriteRangeAsync

        public IAsyncAction WriteRangeAsync(IInputStream rangeData, long startOffset, string contentMD5, AccessCondition accessCondition, FileRequestOptions options, OperationContext operationContext)
#endif
        {
        CommonUtility.AssertNotNull("rangeData", rangeData);

            FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient);
            bool requiresContentMD5 = (contentMD5 == null) && modifiedOptions.UseTransactionalMD5.Value;
            operationContext = operationContext ?? new OperationContext();
            ExecutionState<NullType> tempExecutionState = CommonUtility.CreateTemporaryExecutionState(modifiedOptions);

#if ASPNET_K
            return Task.Run(async () =>
#else
            return AsyncInfo.Run(async (cancellationToken) =>
#endif
            {
                DateTime streamCopyStartTime = DateTime.Now;

                Stream rangeDataAsStream = rangeData.AsStreamForRead();
                Stream seekableStream = rangeDataAsStream;
                if (!rangeDataAsStream.CanSeek || requiresContentMD5)
                {
                    Stream writeToStream;
                    if (rangeDataAsStream.CanSeek)
                    {
                        writeToStream = Stream.Null;
                    }
                    else
                    {
                        seekableStream = new MultiBufferMemoryStream(this.ServiceClient.BufferManager);
                        writeToStream = seekableStream;
                    }

                    StreamDescriptor streamCopyState = new StreamDescriptor();
                    long startPosition = seekableStream.Position;
                    await rangeDataAsStream.WriteToAsync(writeToStream, null /* copyLength */, Constants.MaxBlockSize, requiresContentMD5, tempExecutionState, streamCopyState, cancellationToken);
                    seekableStream.Position = startPosition;

                    if (requiresContentMD5)
                    {
                        contentMD5 = streamCopyState.Md5;
                    }

                    if (modifiedOptions.MaximumExecutionTime.HasValue)
                    {
                        modifiedOptions.MaximumExecutionTime -= DateTime.Now.Subtract(streamCopyStartTime);
                    }
                }

                await Executor.ExecuteAsyncNullReturn(
                    this.PutRangeImpl(seekableStream, startOffset, contentMD5, accessCondition, modifiedOptions),
                    modifiedOptions.RetryPolicy,
                    operationContext,
                    cancellationToken);
#if ASPNET_K
            }, cancellationToken);
#else
            });
开发者ID:DaC24,项目名称:azure-storage-net,代码行数:58,代码来源:CloudFile.cs

示例8: LoadXmlKeyFile

        /// <summary>
        /// Loads the specified XML key file.
        /// </summary>
        /// <param name="input">The keyfile stream.</param>
        /// <returns>The binary data buffer, or <c>null</c> if not a valid XML keyfile.</returns>
        private static IBuffer LoadXmlKeyFile(IInputStream input)
        {
            try
            {
                var doc = XDocument.Load(input.AsStreamForRead());

                // Root
                var root = doc.Root;
                if (root == null || root.Name != "KeyFile")
                    return null;

                // Key
                var key = root.Element("Key");
                if (key == null)
                    return null;

                // Data
                var data = key.Element("Data");
                if (data == null)
                    return null;

                try
                {
                    return CryptographicBuffer
                        .DecodeFromBase64String(data.Value);
                }
                catch (Exception)
                {
                    return null;
                }
            }
            catch (XmlException)
            {
                return null;
            }
        }
开发者ID:Confuset,项目名称:7Pass-Remake,代码行数:41,代码来源:PasswordData.cs

示例9: PutBlockAsync

        public IAsyncAction PutBlockAsync(string blockId, IInputStream blockData, string contentMD5, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.BlockBlob, this.ServiceClient);
            bool requiresContentMD5 = (contentMD5 == null) && modifiedOptions.UseTransactionalMD5.Value;
            operationContext = operationContext ?? new OperationContext();
            ExecutionState<NullType> tempExecutionState = CommonUtility.CreateTemporaryExecutionState(modifiedOptions);

            return AsyncInfo.Run(async (token) =>
            {
                Stream blockDataAsStream = blockData.AsStreamForRead();
                Stream seekableStream = blockDataAsStream;
                if (!blockDataAsStream.CanSeek || requiresContentMD5)
                {
                    Stream writeToStream;
                    if (blockDataAsStream.CanSeek)
                    {
                        writeToStream = Stream.Null;
                    }
                    else
                    {
                        seekableStream = new MultiBufferMemoryStream(this.ServiceClient.BufferManager);
                        writeToStream = seekableStream;
                    }

                    StreamDescriptor streamCopyState = new StreamDescriptor();
                    long startPosition = seekableStream.Position;
                    await blockDataAsStream.WriteToAsync(writeToStream, null /* copyLength */, Constants.MaxBlockSize, requiresContentMD5, tempExecutionState, streamCopyState, token);
                    seekableStream.Position = startPosition;

                    if (requiresContentMD5)
                    {
                        contentMD5 = streamCopyState.Md5;
                    }
                }

                await Executor.ExecuteAsyncNullReturn(
                    this.PutBlockImpl(seekableStream, blockId, contentMD5, accessCondition, modifiedOptions),
                    modifiedOptions.RetryPolicy,
                    operationContext,
                    token);
            });
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:42,代码来源:CloudBlockBlob.cs

示例10: UploadFromStreamAsyncHelper

        internal IAsyncAction UploadFromStreamAsyncHelper(IInputStream source, long? length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            CommonUtility.AssertNotNull("source", source);

            Stream sourceAsStream = source.AsStreamForRead();

            if (length.HasValue)
            {
                CommonUtility.AssertInBounds("length", length.Value, 1);

                if (sourceAsStream.CanSeek && length > sourceAsStream.Length - sourceAsStream.Position)
                {
                    throw new ArgumentOutOfRangeException("length", SR.StreamLengthShortError);
                }
            }

            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.BlockBlob, this.ServiceClient);
            operationContext = operationContext ?? new OperationContext();
            ExecutionState<NullType> tempExecutionState = CommonUtility.CreateTemporaryExecutionState(modifiedOptions);

            return AsyncInfo.Run(async (token) =>
            {
                bool lessThanSingleBlobThreshold = sourceAsStream.CanSeek
                                                   && (length ?? sourceAsStream.Length - sourceAsStream.Position)
                                                   <= this.ServiceClient.SingleBlobUploadThresholdInBytes;
                if (this.ServiceClient.ParallelOperationThreadCount == 1 && lessThanSingleBlobThreshold)
                {
                    string contentMD5 = null;
                    if (modifiedOptions.StoreBlobContentMD5.Value)
                    {
                        StreamDescriptor streamCopyState = new StreamDescriptor();
                        long startPosition = sourceAsStream.Position;
                        await sourceAsStream.WriteToAsync(Stream.Null, length, null /* maxLength */, true, tempExecutionState, streamCopyState, token);
                        sourceAsStream.Position = startPosition;
                        contentMD5 = streamCopyState.Md5;
                    }
                    else
                    {
                        if (modifiedOptions.UseTransactionalMD5.Value)
                        {
                            throw new ArgumentException(SR.PutBlobNeedsStoreBlobContentMD5, "options");
                        }
                    }

                    await Executor.ExecuteAsyncNullReturn(
                        this.PutBlobImpl(sourceAsStream, length, contentMD5, accessCondition, modifiedOptions),
                        modifiedOptions.RetryPolicy,
                        operationContext,
                        token);
                }
                else
                {
                    using (ICloudBlobStream blobStream = await this.OpenWriteAsync(accessCondition, options, operationContext).AsTask(token))
                    {
                        // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                        // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                        await sourceAsStream.WriteToAsync(blobStream.AsStreamForWrite(0), length, null /* maxLength */, false, tempExecutionState, null /* streamCopyState */, token);
                        await blobStream.CommitAsync().AsTask(token);
                    }
                }
            });
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:63,代码来源:CloudBlockBlob.cs

示例11: UploadFromStreamAsyncHelper

        internal IAsyncAction UploadFromStreamAsyncHelper(IInputStream source, long? length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            CommonUtility.AssertNotNull("source", source);

            Stream sourceAsStream = source.AsStreamForRead();

            if (!sourceAsStream.CanSeek)
            {
                throw new InvalidOperationException();
            }

            if (length.HasValue)
            {
                CommonUtility.AssertInBounds("length", length.Value, 1, sourceAsStream.Length - sourceAsStream.Position);
            }
            else
            {
                length = sourceAsStream.Length - sourceAsStream.Position;
            }

            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.PageBlob, this.ServiceClient);
            operationContext = operationContext ?? new OperationContext();
            ExecutionState<NullType> tempExecutionState = CommonUtility.CreateTemporaryExecutionState(modifiedOptions);

            if ((length % Constants.PageSize) != 0)
            {
                throw new ArgumentException(SR.InvalidPageSize, "source");
            }

            return AsyncInfo.Run(async (token) =>
            {
                using (ICloudBlobStream blobStream = await this.OpenWriteAsync(length, accessCondition, options, operationContext).AsTask(token))
                {
                    // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                    // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                    await sourceAsStream.WriteToAsync(blobStream.AsStreamForWrite(0), length, null /* maxLength */, false, tempExecutionState, null /* streamCopyState */, token);
                    await blobStream.CommitAsync().AsTask(token);
                }
            });
        }
开发者ID:BurtHarris,项目名称:azure-storage-net,代码行数:41,代码来源:CloudPageBlob.cs

示例12: SocketStream

 public SocketStream(IInputStream inputStream, IOutputStream outputStream)
 {
     this.inputStream = inputStream.AsStreamForRead();
     this.outputStream = outputStream.AsStreamForWrite();
 }
开发者ID:dsmithson,项目名称:KnightwareCore,代码行数:5,代码来源:SocketStream.cs

示例13: CreateFromSmartXml

 public static FWAdResponse CreateFromSmartXml(IInputStream stream)
 {
     return CreateFromSmartXml(stream.AsStreamForRead());
 }
开发者ID:bondarenkod,项目名称:pf-arm-deploy-error,代码行数:4,代码来源:FreewheelFactory.cs

示例14: ParseFileContent

        private async Task ParseFileContent(IInputStream inputStream)
        {
            using (var reader = new StreamReader(inputStream.AsStreamForRead()))
            {
                var encodedBytes = Convert.FromBase64String(reader.ReadToEnd());
                var cardString = Encoding.UTF8.GetString(encodedBytes, 0, encodedBytes.Length);

                var cards = JsonConvert.DeserializeObject<ObservableCollection<Card>>(cardString);

                Messenger.Default.Send(new NotificationMessage(cards, "RestoreCards"));

                ProgressText = string.Empty;
                ProgressVisibility = Visibility.Collapsed;
            }
        }
开发者ID:ntomlinson,项目名称:StoreCardBuddy,代码行数:15,代码来源:BackupRestoreViewModel.cs

示例15: UploadFromStreamAsync

        public IAsyncAction UploadFromStreamAsync(IInputStream source, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            CommonUtils.AssertNotNull("source", source);
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.PageBlob, this.ServiceClient);
            operationContext = operationContext ?? new OperationContext();

            Stream sourceAsStream = source.AsStreamForRead();
            if (!sourceAsStream.CanSeek)
            {
                throw new InvalidOperationException();
            }

            long size = sourceAsStream.Length - sourceAsStream.Position;
            if ((size % Constants.PageSize) != 0)
            {
                throw new ArgumentException(SR.InvalidPageSize, "source");
            }

            return AsyncInfo.Run(async (token) =>
            {
                CancellationToken streamCopyToken = token;
                if (modifiedOptions.MaximumExecutionTime.HasValue)
                {
                    // Setup token
                    CancellationTokenSource cts = new CancellationTokenSource(modifiedOptions.MaximumExecutionTime.Value);
                    CancellationToken tokenWithTimeout = cts.Token;

                    // Hookup users token
                    token.Register(() => cts.Cancel());

                    streamCopyToken = tokenWithTimeout;
                }

                await Task.Run(async () =>
                {
                    IOutputStream writeStream = await this.OpenWriteAsync(size, accessCondition, options, operationContext);

                    // We should always call AsStreamForWrite with bufferSize=0 to prevent buffering. Our
                    // stream copier only writes 64K buffers at a time anyway, so no buffering is needed.
                    using (Stream blobStream = writeStream.AsStreamForWrite(0))
                    {
                        await sourceAsStream.WriteToAsync(blobStream, null /* maxLength */, false, new OperationContext(), null /* streamCopyState */, streamCopyToken);
                    }
                });
            });
        }
开发者ID:nberardi,项目名称:azure-sdk-for-net,代码行数:47,代码来源:CloudPageBlob.cs


注:本文中的IInputStream.AsStreamForRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。