本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Core.MultiBufferMemoryStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# MultiBufferMemoryStream.Seek方法的具体用法?C# MultiBufferMemoryStream.Seek怎么用?C# MultiBufferMemoryStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.WindowsAzure.Storage.Core.MultiBufferMemoryStream
的用法示例。
在下文中一共展示了MultiBufferMemoryStream.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteToMultiBufferMemoryStreamTestAsync
public async Task WriteToMultiBufferMemoryStreamTestAsync()
{
OperationContext tempOperationContext = new OperationContext();
RESTCommand<NullType> cmd = new RESTCommand<NullType>(TestBase.StorageCredentials, null);
ExecutionState<NullType> tempExecutionState = new ExecutionState<NullType>(cmd, null, tempOperationContext);
byte[] buffer = GetRandomBuffer(1 * 1024 * 1024);
MemoryStream stream1 = new MemoryStream(buffer);
MultiBufferMemoryStream stream2 = new MultiBufferMemoryStream(null /* bufferManager */);
await stream1.WriteToAsync(stream2, null, null, false, tempExecutionState, null, CancellationToken.None);
stream1.Seek(0, SeekOrigin.Begin);
stream2.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream1, stream2);
MultiBufferMemoryStream stream3 = new MultiBufferMemoryStream(null /* bufferManager */);
await TestHelper.ExpectedExceptionAsync<TimeoutException>(
() => stream2.FastCopyToAsync(stream3, DateTime.Now.AddMinutes(-1)),
"Past expiration time should immediately fail");
stream2.Seek(0, SeekOrigin.Begin);
stream3.Seek(0, SeekOrigin.Begin);
await stream2.FastCopyToAsync(stream3, DateTime.Now.AddHours(1));
stream2.Seek(0, SeekOrigin.Begin);
stream3.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream2, stream3);
MultiBufferMemoryStream stream4 = new MultiBufferMemoryStream(null /* bufferManager */, 12345);
await stream3.FastCopyToAsync(stream4, null);
stream3.Seek(0, SeekOrigin.Begin);
stream4.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream3, stream4);
MemoryStream stream5 = new MemoryStream();
await stream4.WriteToAsync(stream5, null, null, false, tempExecutionState, null, CancellationToken.None);
stream4.Seek(0, SeekOrigin.Begin);
stream5.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream4, stream5);
TestHelper.AssertStreamsAreEqual(stream1, stream5);
}
示例2: SetServicePropertiesImpl
private RESTCommand<NullType> SetServicePropertiesImpl(ServiceProperties properties, QueueRequestOptions requestOptions)
{
MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
try
{
properties.WriteServiceProperties(str);
}
catch (InvalidOperationException invalidOpException)
{
throw new ArgumentException(invalidOpException.Message, "properties");
}
str.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.BaseUri);
retCmd.SendStream = str;
retCmd.BuildRequestDelegate = QueueHttpWebRequestFactory.SetServiceProperties;
retCmd.RecoveryAction = RecoveryActions.RewindStream;
retCmd.SignRequest = this.AuthenticationHandler.SignRequest;
retCmd.PreProcessResponse =
(cmd, resp, ex, ctx) =>
HttpResponseParsers.ProcessExpectedStatusCodeNoException(System.Net.HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex);
retCmd.ApplyRequestOptions(requestOptions);
return retCmd;
}
示例3: SetPermissionsImpl
/// <summary>
/// Implementation for the SetPermissions method.
/// </summary>
/// <param name="acl">The permissions to set.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
/// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
/// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns>
private RESTCommand<NullType> SetPermissionsImpl(BlobContainerPermissions acl, AccessCondition accessCondition, BlobRequestOptions options)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
BlobRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.StorageUri);
options.ApplyToStorageCommand(putCmd);
putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => ContainerHttpWebRequestFactory.SetAcl(uri, serverTimeout, acl.PublicAccess, accessCondition, useVersionHeader, ctx);
putCmd.SendStream = memoryStream;
putCmd.StreamToDispose = memoryStream;
putCmd.RecoveryAction = RecoveryActions.RewindStream;
putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, NullType.Value, cmd, ex);
this.UpdateETagAndLastModified(resp);
return NullType.Value;
};
return putCmd;
}
示例4: UpdateMessageImpl
/// <summary>
/// Implementation for the UpdateMessage method.
/// </summary>
/// <param name="message">The message to update.</param>
/// <param name="visibilityTimeout">The visibility timeout interval.</param>
/// <param name="updateFields">The message update fields.</param>
/// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param>
/// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns>
private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields, QueueRequestOptions options)
{
CommonUtility.AssertNotNull("message", message);
CommonUtility.AssertNotNullOrEmpty("messageId", message.Id);
CommonUtility.AssertNotNullOrEmpty("popReceipt", message.PopReceipt);
CommonUtility.AssertInBounds<TimeSpan>("visibilityTimeout", visibilityTimeout, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive);
if ((updateFields & MessageUpdateFields.Visibility) == 0)
{
throw new ArgumentException(SR.UpdateMessageVisibilityRequired, "updateFlags");
}
Uri messageUri = this.GetIndividualMessageAddress(message.Id);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri);
putCmd.ApplyRequestOptions(options);
putCmd.Handler = this.ServiceClient.AuthenticationHandler;
putCmd.BuildClient = HttpClientFactory.BuildHttpClient;
putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.UpdateMessage(cmd.Uri, cmd.ServerTimeoutInSeconds, message.PopReceipt, visibilityTimeout, cnt, ctx);
if ((updateFields & MessageUpdateFields.Content) != 0)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx);
}
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex);
GetPopReceiptAndNextVisibleTimeFromResponse(message, resp);
return NullType.Value;
};
return putCmd;
}
示例5: AddMessageImpl
/// <summary>
/// Implementation for the AddMessage method.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="timeToLive">The maximum time to allow the message to be in the queue, or null.</param>
/// <param name="initialVisibilityDelay">The length of time from now during which the message will be invisible.
/// If <c>null</c> then the message will be visible immediately.</param>
/// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies any additional options for the request.</param>
/// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns>
private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress());
putCmd.ApplyRequestOptions(options);
putCmd.Handler = this.ServiceClient.AuthenticationHandler;
putCmd.BuildClient = HttpClientFactory.BuildHttpClient;
putCmd.BuildRequest = (cmd, cnt, ctx) => QueueHttpRequestMessageFactory.AddMessage(cmd.Uri, cmd.ServerTimeoutInSeconds, timeToLive, initialVisibilityDelay, cnt, ctx);
putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx);
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex);
GetMessageCountAndMetadataFromResponse(resp);
return NullType.Value;
};
return putCmd;
}
示例6: PutBlockListImpl
/// <summary>
/// Uploads the block list.
/// </summary>
/// <param name="blocks">The blocks to upload.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param>
/// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param>
/// <returns>A <see cref="RESTCommand"/> that uploads the block list.</returns>
internal RESTCommand<NullType> PutBlockListImpl(IEnumerable<PutBlockListItem> blocks, AccessCondition accessCondition, BlobRequestOptions options)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
BlobRequest.WriteBlockListBody(blocks, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
string contentMD5 = memoryStream.ComputeMD5Hash();
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.Uri);
putCmd.ApplyRequestOptions(options);
putCmd.Handler = this.ServiceClient.AuthenticationHandler;
putCmd.BuildClient = HttpClientFactory.BuildHttpClient;
putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, contentMD5, cmd, ctx);
putCmd.BuildRequest = (cmd, cnt, ctx) =>
{
HttpRequestMessage msg = BlobHttpRequestMessageFactory.PutBlockList(cmd.Uri, cmd.ServerTimeoutInSeconds, this.Properties, accessCondition, cnt, ctx);
BlobHttpRequestMessageFactory.AddMetadata(msg, this.Metadata);
return msg;
};
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex);
CloudBlobSharedImpl.UpdateETagLMTAndSequenceNumber(this.attributes, resp);
this.Properties.Length = -1;
return NullType.Value;
};
return putCmd;
}
示例7: AddMessageImpl
/// <summary>
/// Implementation for the AddMessageImpl method.
/// </summary>
/// <param name="message">A queue message.</param>
/// <param name="timeToLive">A value indicating the message time-to-live.</param>
/// <param name="initialVisibilityDelay">The visibility delay for the message.</param>
/// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
/// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns>
private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options)
{
int? timeToLiveInSeconds = null;
int? initialVisibilityDelayInSeconds = null;
if (timeToLive.HasValue)
{
CommonUtility.AssertInBounds("timeToLive", timeToLive.Value, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive);
timeToLiveInSeconds = (int)timeToLive.Value.TotalSeconds;
}
if (initialVisibilityDelay.HasValue)
{
CommonUtility.AssertInBounds("initialVisibilityDelay", initialVisibilityDelay.Value, TimeSpan.Zero, timeToLive ?? CloudQueueMessage.MaxTimeToLive);
initialVisibilityDelayInSeconds = (int)initialVisibilityDelay.Value.TotalSeconds;
}
CommonUtility.AssertNotNull("message", message);
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage, options), memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress());
options.ApplyToStorageCommand(putCmd);
putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => QueueHttpWebRequestFactory.AddMessage(uri, serverTimeout, timeToLiveInSeconds, initialVisibilityDelayInSeconds, useVersionHeader, ctx);
putCmd.SendStream = memoryStream;
putCmd.StreamToDispose = memoryStream;
putCmd.RecoveryAction = RecoveryActions.RewindStream;
putCmd.SetHeaders = (r, ctx) =>
{
if (timeToLive != null)
{
#if WINDOWS_PHONE
r.Headers[Constants.QueryConstants.MessageTimeToLive] = timeToLive.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture);
#else
r.Headers.Set(Constants.QueryConstants.MessageTimeToLive, timeToLive.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
#endif
}
if (initialVisibilityDelay != null)
{
#if WINDOWS_PHONE
r.Headers[Constants.QueryConstants.VisibilityTimeout] = initialVisibilityDelay.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture);
#else
r.Headers.Set(Constants.QueryConstants.VisibilityTimeout, initialVisibilityDelay.Value.TotalSeconds.ToString(CultureInfo.InvariantCulture));
#endif
}
};
putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex);
return NullType.Value;
};
return putCmd;
}
示例8: SetServicePropertiesImpl
private RESTCommand<NullType> SetServicePropertiesImpl(ServiceProperties properties, TableRequestOptions requestOptions)
{
MultiBufferMemoryStream str = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
try
{
properties.WriteServiceProperties(str);
}
catch (InvalidOperationException invalidOpException)
{
str.Dispose();
throw new ArgumentException(invalidOpException.Message, "properties");
}
str.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> retCmd = new RESTCommand<NullType>(this.Credentials, this.StorageUri);
retCmd.SendStream = str;
retCmd.StreamToDispose = str;
retCmd.BuildRequestDelegate = TableHttpWebRequestFactory.SetServiceProperties;
retCmd.RecoveryAction = RecoveryActions.RewindStream;
retCmd.SignRequest = this.AuthenticationHandler.SignRequest;
retCmd.ParseError = StorageExtendedErrorInformation.ReadFromStreamUsingODataLib;
retCmd.PreProcessResponse =
(cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex);
requestOptions.ApplyToStorageCommand(retCmd);
return retCmd;
}
示例9: EnsureMultiBufferMemoryStreamIsNotClosedAPM
public void EnsureMultiBufferMemoryStreamIsNotClosedAPM()
{
byte[] buffer = GetRandomBuffer(1 * 1024 * 1024);
CloudBlobClient blobClient = GenerateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(Guid.NewGuid().ToString("N"));
try
{
container.Create();
CloudBlockBlob blob = container.GetBlockBlobReference("blob1");
using (MultiBufferMemoryStream originalBlob = new MultiBufferMemoryStream(null))
{
originalBlob.Write(buffer, 0, buffer.Length);
originalBlob.Seek(0, SeekOrigin.Begin);
using (AutoResetEvent waitHandle = new AutoResetEvent(false))
{
ICancellableAsyncResult result = blob.BeginPutBlock(
Convert.ToBase64String(Guid.NewGuid().ToByteArray()),
originalBlob,
null,
ar => waitHandle.Set(),
null);
waitHandle.WaitOne();
blob.EndPutBlock(result);
}
Assert.IsTrue(originalBlob.CanSeek);
}
}
finally
{
container.DeleteIfExists();
}
}
示例10: WriteToMultiBufferMemoryStreamTestAPM
public void WriteToMultiBufferMemoryStreamTestAPM()
{
using (AutoResetEvent waitHandle = new AutoResetEvent(false))
{
byte[] buffer = GetRandomBuffer(1 * 1024 * 1024);
MemoryStream stream1 = new MemoryStream(buffer);
RESTCommand<NullType> cmd = new RESTCommand<NullType>(TestBase.StorageCredentials, null);
ExecutionState<NullType> state = new ExecutionState<NullType>(cmd, new NoRetry(), new OperationContext());
StreamDescriptor copyState = new StreamDescriptor();
MultiBufferMemoryStream stream2 = new MultiBufferMemoryStream(null /* bufferManager */);
stream1.WriteToAsync(stream2, null, null, false, state, copyState, _ => waitHandle.Set());
waitHandle.WaitOne();
if (state.ExceptionRef != null)
{
throw state.ExceptionRef;
}
stream1.Seek(0, SeekOrigin.Begin);
stream2.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream1, stream2);
MultiBufferMemoryStream stream3 = new MultiBufferMemoryStream(null /* bufferManager */);
IAsyncResult ar = stream2.BeginFastCopyTo(stream3, DateTime.Now.AddMinutes(-1), _ => waitHandle.Set(), null);
waitHandle.WaitOne();
TestHelper.ExpectedException<TimeoutException>(
() => stream3.EndFastCopyTo(ar),
"Past expiration time should immediately fail");
stream2.Seek(0, SeekOrigin.Begin);
stream3.Seek(0, SeekOrigin.Begin);
ar = stream2.BeginFastCopyTo(stream3, DateTime.Now.AddHours(1), _ => waitHandle.Set(), null);
waitHandle.WaitOne();
stream2.EndFastCopyTo(ar);
stream2.Seek(0, SeekOrigin.Begin);
stream3.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream2, stream3);
MultiBufferMemoryStream stream4 = new MultiBufferMemoryStream(null, 12345);
ar = stream3.BeginFastCopyTo(stream4, null, _ => waitHandle.Set(), null);
waitHandle.WaitOne();
stream3.EndFastCopyTo(ar);
stream3.Seek(0, SeekOrigin.Begin);
stream4.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream3, stream4);
state = new ExecutionState<NullType>(cmd, new NoRetry(), new OperationContext());
copyState = new StreamDescriptor();
MemoryStream stream5 = new MemoryStream();
stream4.WriteToAsync(stream5, null, null, false, state, copyState, _ => waitHandle.Set());
waitHandle.WaitOne();
if (state.ExceptionRef != null)
{
throw state.ExceptionRef;
}
stream4.Seek(0, SeekOrigin.Begin);
stream5.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(stream4, stream5);
TestHelper.AssertStreamsAreEqual(stream1, stream5);
}
}
示例11: MultiBufferMemoryStreamReadSeekSetLengthTestAPM
public void MultiBufferMemoryStreamReadSeekSetLengthTestAPM()
{
byte[] outBuffer = new byte[2 * 1024 * 1024];
byte[] buffer = GetRandomBuffer(outBuffer.Length);
using (MemoryStream memStream = new MemoryStream())
{
memStream.Write(buffer, 0, buffer.Length);
using (MultiBufferMemoryStream multiBufferStream = new MultiBufferMemoryStream(null /* bufferManager */))
{
using (AutoResetEvent waitHandle = new AutoResetEvent(false))
{
IAsyncResult result = multiBufferStream.BeginWrite(buffer, 0, buffer.Length, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
multiBufferStream.EndWrite(result);
multiBufferStream.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(memStream, multiBufferStream);
result = multiBufferStream.BeginRead(outBuffer, 0, buffer.Length, ar => waitHandle.Set(), null);
waitHandle.WaitOne();
multiBufferStream.EndRead(result);
TestHelper.AssertBuffersAreEqual(buffer, outBuffer);
multiBufferStream.Seek(-1, SeekOrigin.End);
Assert.AreEqual(buffer.Length - 1, multiBufferStream.Position);
multiBufferStream.Seek(-1024, SeekOrigin.End);
memStream.Seek(-1024, SeekOrigin.End);
TestHelper.AssertStreamsAreEqual(multiBufferStream, memStream);
multiBufferStream.SetLength(3 * 1024 * 1024);
memStream.SetLength(3 * 1024 * 1024);
multiBufferStream.Seek(0, SeekOrigin.Begin);
memStream.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(memStream, multiBufferStream);
}
}
}
}
示例12: MultiBufferMemoryStreamReadSeekSetLengthTest
public void MultiBufferMemoryStreamReadSeekSetLengthTest()
{
byte[] outBuffer = new byte[2 * 1024 * 1024];
byte[] buffer = GetRandomBuffer(outBuffer.Length);
using (MemoryStream memStream = new MemoryStream())
{
memStream.Write(buffer, 0, buffer.Length);
using (MultiBufferMemoryStream multiBufferStream = new MultiBufferMemoryStream(null /* bufferManager */))
{
multiBufferStream.Write(buffer, 0, buffer.Length);
multiBufferStream.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(memStream, multiBufferStream);
multiBufferStream.Read(outBuffer, 0, buffer.Length);
TestHelper.AssertBuffersAreEqual(buffer, outBuffer);
multiBufferStream.Seek(-1, SeekOrigin.End);
Assert.AreEqual(buffer.Length - 1, multiBufferStream.Position);
multiBufferStream.Seek(-1024, SeekOrigin.End);
memStream.Seek(-1024, SeekOrigin.End);
TestHelper.AssertStreamsAreEqual(multiBufferStream, memStream);
multiBufferStream.SetLength(3 * 1024 * 1024);
memStream.SetLength(3 * 1024 * 1024);
multiBufferStream.Seek(0, SeekOrigin.Begin);
memStream.Seek(0, SeekOrigin.Begin);
TestHelper.AssertStreamsAreEqual(memStream, multiBufferStream);
}
}
}
示例13: UpdateMessageImpl
/// <summary>
/// Implementation for the UpdateMessage method.
/// </summary>
/// <param name="message">A queue message.</param>
/// <param name="visibilityTimeout">The visibility timeout for the message.</param>
/// <param name="updateFields">Indicates whether to update the visibility delay, message contents, or both.</param>
/// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
/// <returns>A <see cref="RESTCommand{T}"/> that sets the permissions.</returns>
private RESTCommand<NullType> UpdateMessageImpl(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields, QueueRequestOptions options)
{
CommonUtility.AssertNotNull("message", message);
CommonUtility.AssertNotNullOrEmpty("messageId", message.Id);
CommonUtility.AssertNotNullOrEmpty("popReceipt", message.PopReceipt);
CommonUtility.AssertInBounds("visibilityTimeout", visibilityTimeout, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive);
if ((updateFields & MessageUpdateFields.Visibility) == 0)
{
throw new ArgumentException(SR.UpdateMessageVisibilityRequired, "updateFields");
}
StorageUri messageUri = this.GetIndividualMessageAddress(message.Id);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, messageUri);
options.ApplyToStorageCommand(putCmd);
putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => QueueHttpWebRequestFactory.UpdateMessage(uri, serverTimeout, message.PopReceipt, visibilityTimeout.RoundUpToSeconds(), useVersionHeader, ctx);
if ((updateFields & MessageUpdateFields.Content) != 0)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(this.ServiceClient.BufferManager, (int)(1 * Constants.KB));
QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage, options), memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
putCmd.SendStream = memoryStream;
putCmd.StreamToDispose = memoryStream;
putCmd.RecoveryAction = RecoveryActions.RewindStream;
}
putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex);
GetPopReceiptAndNextVisibleTimeFromResponse(message, resp);
return NullType.Value;
};
return putCmd;
}
示例14: PutBlockListImpl
/// <summary>
/// Uploads the block list.
/// </summary>
/// <param name="blocks">The blocks to upload.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
/// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
/// <returns>A <see cref="RESTCommand{T}"/> that uploads the block list.</returns>
internal RESTCommand<NullType> PutBlockListImpl(IEnumerable<PutBlockListItem> blocks, AccessCondition accessCondition, BlobRequestOptions options)
{
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(this.ServiceClient.BufferManager);
BlobRequest.WriteBlockListBody(blocks, memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
#if !WINDOWS_PHONE
string contentMD5 = null;
if (options.UseTransactionalMD5.HasValue && options.UseTransactionalMD5.Value)
{
contentMD5 = memoryStream.ComputeMD5Hash();
memoryStream.Seek(0, SeekOrigin.Begin);
}
#endif
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.attributes.StorageUri);
options.ApplyToStorageCommand(putCmd);
putCmd.BuildRequestDelegate = (uri, builder, serverTimeout, useVersionHeader, ctx) => BlobHttpWebRequestFactory.PutBlockList(uri, serverTimeout, this.Properties, accessCondition, useVersionHeader, ctx);
putCmd.SetHeaders = (r, ctx) =>
{
#if !WINDOWS_PHONE
if (contentMD5 != null)
{
r.Headers[HttpRequestHeader.ContentMd5] = contentMD5;
}
#endif
BlobHttpWebRequestFactory.AddMetadata(r, this.Metadata);
};
putCmd.SendStream = memoryStream;
putCmd.StreamToDispose = memoryStream;
putCmd.RecoveryAction = RecoveryActions.RewindStream;
putCmd.SignRequest = this.ServiceClient.AuthenticationHandler.SignRequest;
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex);
CloudBlob.UpdateETagLMTLengthAndSequenceNumber(this.attributes, resp, false);
cmd.CurrentResult.IsRequestServerEncrypted = CloudBlob.ParseServerRequestEncrypted(resp);
this.Properties.Length = -1;
return NullType.Value;
};
return putCmd;
}
示例15: AddMessageImpl
/// <summary>
/// Implementation for the AddMessage method.
/// </summary>
/// <param name="message">The message.</param>
/// <param name="timeToLive">The maximum time to allow the message to be in the queue, or null.</param>
/// <param name="initialVisibilityDelay">The length of time from now during which the message will be invisible.
/// If <c>null</c> then the message will be visible immediately.</param>
/// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request.</param>
/// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns>
private RESTCommand<NullType> AddMessageImpl(CloudQueueMessage message, TimeSpan? timeToLive, TimeSpan? initialVisibilityDelay, QueueRequestOptions options)
{
int? timeToLiveInSeconds = null;
int? initialVisibilityDelayInSeconds = null;
if (timeToLive.HasValue)
{
CommonUtility.AssertInBounds("timeToLive", timeToLive.Value, TimeSpan.Zero, CloudQueueMessage.MaxTimeToLive);
timeToLiveInSeconds = (int)timeToLive.Value.TotalSeconds;
}
if (initialVisibilityDelay.HasValue)
{
CommonUtility.AssertInBounds("initialVisibilityDelay", initialVisibilityDelay.Value, TimeSpan.Zero, timeToLive ?? CloudQueueMessage.MaxTimeToLive);
initialVisibilityDelayInSeconds = (int)initialVisibilityDelay.Value.TotalSeconds;
}
MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB));
QueueRequest.WriteMessageContent(message.GetMessageContentForTransfer(this.EncodeMessage), memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
RESTCommand<NullType> putCmd = new RESTCommand<NullType>(this.ServiceClient.Credentials, this.GetMessageRequestAddress());
options.ApplyToStorageCommand(putCmd);
putCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => QueueHttpRequestMessageFactory.AddMessage(uri, serverTimeout, timeToLiveInSeconds, initialVisibilityDelayInSeconds, cnt, ctx, this.ServiceClient.GetCanonicalizer(), this.ServiceClient.Credentials);
putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null, cmd, ctx);
putCmd.StreamToDispose = memoryStream;
putCmd.PreProcessResponse = (cmd, resp, ex, ctx) =>
{
HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Created, resp, NullType.Value, cmd, ex);
GetMessageCountAndMetadataFromResponse(resp);
return NullType.Value;
};
return putCmd;
}