/// <summary> /// Initializes a new instance of the <see cref="CloudQueueClient"/> class. /// </summary> /// <param name="usePathStyleUris">True to use path style Uris.</param> /// <param name="baseAddressUri">The base address Uri.</param> /// <param name="credentials">The credentials.</param> internal CloudQueueClient(bool?usePathStyleUris, Uri baseAddressUri, StorageCredentials credentials) { CommonUtils.AssertNotNull("baseAddress", baseAddressUri); CommonUtils.AssertNotNull("credentials", credentials); if (!credentials.CanSignRequest) { throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials"); } this.BaseUri = baseAddressUri; if (!this.BaseUri.IsAbsoluteUri) { CommonUtils.ArgumentOutOfRange("baseAddress", baseAddressUri); } this.Timeout = Constants.DefaultClientSideTimeout; this.RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff); this.Credentials = credentials; if (usePathStyleUris.HasValue) { this.UsePathStyleUris = usePathStyleUris.Value; } else { // Automatically decide whether to use host style uri or path style uri this.UsePathStyleUris = CommonUtils.UsePathStyleAddressing(this.BaseUri); } }
/// <summary> /// Initializes a new instance of the <see cref="TableServiceContext"/> class. /// </summary> /// <param name="baseAddress">The Table service endpoint to use create the service context.</param> /// <param name="credentials">The account credentials.</param> public TableServiceContext(string baseAddress, StorageCredentials credentials) : base(new Uri(baseAddress)) { if (string.IsNullOrEmpty(baseAddress)) { throw new ArgumentNullException("baseAddress"); } if (credentials == null) { throw new ArgumentNullException("credentials"); } if ((!credentials.CanSignRequest) || (!credentials.CanSignRequestLite)) { throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials"); } SendingRequest += new EventHandler <SendingRequestEventArgs>(this.DataContextSendingRequest); StorageCredentials = credentials; IgnoreMissingProperties = true; MergeOption = MergeOption.PreserveChanges; RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff); Timeout = (int)TimeSpan.FromSeconds(90).TotalSeconds; }
/// <summary> /// Uploads a single block. /// </summary> /// <param name="blockId">A base64-encoded block ID that identifies the block.</param> /// <param name="blockData">A stream that provides the data for the block.</param> /// <param name="contentMD5">An optional hash value that will be used to set the <see cref="BlobProperties.ContentMD5"/> property /// on the blob. May be <c>null</c> or an empty string.</param> /// <param name="options">An object that specifies any additional options for the request.</param> public void PutBlock(string blockId, Stream blockData, string contentMD5, BlobRequestOptions options) { var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options); var position = blockData.Position; var retryPolicy = blockData.CanSeek ? fullModifier.RetryPolicy : RetryPolicies.NoRetry(); TaskImplHelper.ExecuteImplWithRetry( () => { if (blockData.CanSeek) { blockData.Position = position; } return(this.UploadBlock(blockData, blockId, contentMD5, fullModifier)); }, retryPolicy); }
/// <summary> /// Begins an asynchronous operation to upload a single block. /// </summary> /// <param name="blockId">A base64-encoded block ID that identifies the block.</param> /// <param name="blockData">A stream that provides the data for the block.</param> /// <param name="contentMD5">An optional hash value that will be used to set the <see cref="BlobProperties.ContentMD5"/> property /// on the blob. May be <c>null</c> or an empty string.</param> /// <param name="options">An object that specifies any additional options for the request.</param> /// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param> /// <param name="state">A user-defined object that will be passed to the callback delegate.</param> /// <returns>An <see cref="IAsyncResult"/> that references the asynchronous operation.</returns> public IAsyncResult BeginPutBlock(string blockId, Stream blockData, string contentMD5, BlobRequestOptions options, AsyncCallback callback, object state) { var fullModifier = BlobRequestOptions.CreateFullModifier(this.ServiceClient, options); var position = blockData.Position; var retryPolicy = blockData.CanSeek ? fullModifier.RetryPolicy : RetryPolicies.NoRetry(); return(TaskImplHelper.BeginImplWithRetry( () => { if (blockData.CanSeek) { blockData.Position = position; } return this.UploadBlock(blockData, blockId, contentMD5, fullModifier); }, retryPolicy, callback, state)); }
/// <summary> /// Initializes a new instance of the <see cref="CloudTableClient"/> class using the specified Table service endpoint /// and account credentials. /// </summary> /// <param name="baseAddressUri">The Table service endpoint to use to create the client.</param> /// <param name="credentials">The account credentials.</param> public CloudTableClient(Uri baseAddressUri, StorageCredentials credentials) { if (baseAddressUri == null) { throw new ArgumentNullException("baseAddressUri"); } if (credentials == null) { throw new ArgumentNullException("credentials"); } if ((!credentials.CanSignRequest) || (!credentials.CanSignRequestLite)) { throw new ArgumentException(SR.CredentialsCantSignRequest, "credentials"); } this.BaseUri = baseAddressUri; this.Credentials = credentials; this.RetryPolicy = RetryPolicies.RetryExponential(RetryPolicies.DefaultClientRetryCount, RetryPolicies.DefaultClientBackoff); this.Timeout = TimeSpan.FromSeconds(90); }
/// <summary> /// Initializes a new instance of the <see cref="CloudTableQuery{TElement}"/> class with the specified query. /// </summary> /// <param name="query">The base query.</param> public CloudTableQuery(DataServiceQuery <TElement> query) : this(query, RetryPolicies.RetryExponential(3, TimeSpan.FromSeconds(2))) { }