private RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, TableRequestOptions requestOptions) { MemoryStream memoryStream = new MemoryStream(); try { properties.WriteServiceProperties(memoryStream); } catch (InvalidOperationException invalidOpException) { throw new ArgumentException(invalidOpException.Message, "properties"); } RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.BaseUri); retCmd.ApplyRequestOptions(requestOptions); retCmd.BuildRequest = (cmd, cnt, ctx) => TableHttpRequestMessageFactory.SetServiceProperties(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx); retCmd.Handler = this.AuthenticationHandler; retCmd.BuildClient = HttpClientFactory.BuildHttpClient; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(System.Net.HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex, ctx); retCmd.ApplyRequestOptions(requestOptions); return(retCmd); }
/// <summary> /// Implementation for the SetPermissions method. /// </summary> /// <param name="acl">The permissions to set.</param> /// <param name="requestOptions">A <see cref="TableRequestOptions"/> object that specifies execution options, such as retry policy and timeout settings, for the operation.</param> /// <returns>A <see cref="RESTCommand"/> that sets the permissions.</returns> private RESTCommand <NullType> SetPermissionsImpl(TablePermissions acl, TableRequestOptions requestOptions) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); TableRequest.WriteSharedAccessIdentifiers(acl.SharedAccessPolicies, memoryStream); RESTCommand <NullType> putCmd = new RESTCommand <NullType>(this.ServiceClient.Credentials, this.Uri); putCmd.ApplyRequestOptions(requestOptions); putCmd.Handler = this.ServiceClient.AuthenticationHandler; putCmd.BuildClient = HttpClientFactory.BuildHttpClient; putCmd.BuildRequest = (cmd, cnt, ctx) => TableHttpRequestMessageFactory.SetAcl(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); putCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx); putCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.NoContent, resp, NullType.Value, cmd, ex); return(NullType.Value); }; return(putCmd); }
private RESTCommand <ServiceProperties> GetServicePropertiesImpl(TableRequestOptions requestOptions) { RESTCommand <ServiceProperties> retCmd = new RESTCommand <ServiceProperties>(this.Credentials, this.BaseUri); retCmd.BuildRequest = (cmd, cnt, ctx) => TableHttpRequestMessageFactory.GetServiceProperties(cmd.Uri, cmd.ServerTimeoutInSeconds, ctx); retCmd.RetrieveResponseStream = true; retCmd.Handler = this.AuthenticationHandler; retCmd.BuildClient = HttpClientFactory.BuildHttpClient; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(System.Net.HttpStatusCode.OK, resp, null /* retVal */, cmd, ex, ctx); retCmd.PostProcessResponse = (cmd, resp, ex, ctx) => { return(Task.Factory.StartNew(() => HttpResponseParsers.ReadServiceProperties(cmd.ResponseStream))); }; retCmd.ApplyRequestOptions(requestOptions); return(retCmd); }
/// <summary> /// Implementation for the GetPermissions method. /// </summary> /// <param name="requestOptions">An object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that gets the permissions.</returns> private RESTCommand <TablePermissions> GetPermissionsImpl(TableRequestOptions requestOptions) { RESTCommand <TablePermissions> getCmd = new RESTCommand <TablePermissions>(this.ServiceClient.Credentials, this.Uri); getCmd.ApplyRequestOptions(requestOptions); getCmd.Handler = this.ServiceClient.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.RetrieveResponseStream = true; getCmd.BuildRequest = (cmd, cnt, ctx) => TableHttpRequestMessageFactory.GetAcl(cmd.Uri, cmd.ServerTimeoutInSeconds, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); getCmd.PostProcessResponse = (cmd, resp, ctx) => { return(Task <TablePermissions> .Factory.StartNew(() => { TablePermissions TableAcl = new TablePermissions(); HttpResponseParsers.ReadSharedAccessIdentifiers(TableAcl.SharedAccessPolicies, new TableAccessPolicyResponse(cmd.ResponseStream)); return TableAcl; })); }; return(getCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(TableRequestOptions requestOptions) { RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => TableHttpRequestMessageFactory.GetServiceStats(uri, serverTimeout, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.RetrieveResponseStream = true; retCmd.ParseError = StorageExtendedErrorInformation.ReadFromStreamUsingODataLib; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => Task.Factory.StartNew(() => HttpResponseParsers.ReadServiceStats(cmd.ResponseStream)); return(retCmd); }
private RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, TableRequestOptions requestOptions) { MultiBufferMemoryStream memoryStream = new MultiBufferMemoryStream(null /* bufferManager */, (int)(1 * Constants.KB)); try { properties.WriteServiceProperties(memoryStream); } catch (InvalidOperationException invalidOpException) { throw new ArgumentException(invalidOpException.Message, "properties"); } RESTCommand <NullType> retCmd = new RESTCommand <NullType>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => TableHttpRequestMessageFactory.SetServiceProperties(uri, serverTimeout, cnt, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.BuildContent = (cmd, ctx) => HttpContentFactory.BuildContentFromStream(memoryStream, 0, memoryStream.Length, null /* md5 */, cmd, ctx); retCmd.StreamToDispose = memoryStream; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, null /* retVal */, cmd, ex); requestOptions.ApplyToStorageCommand(retCmd); return(retCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(TableRequestOptions requestOptions) { RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => TableHttpRequestMessageFactory.GetServiceStats(uri, serverTimeout, ctx); retCmd.RetrieveResponseStream = true; retCmd.Handler = this.AuthenticationHandler; retCmd.BuildClient = HttpClientFactory.BuildHttpClient; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => Task.Factory.StartNew(() => HttpResponseParsers.ReadServiceStats(cmd.ResponseStream)); return(retCmd); }
private RESTCommand <ServiceStats> GetServiceStatsImpl(TableRequestOptions requestOptions) { if (RetryPolicies.LocationMode.PrimaryOnly == requestOptions.LocationMode) { throw new InvalidOperationException(SR.GetServiceStatsInvalidOperation); } RESTCommand <ServiceStats> retCmd = new RESTCommand <ServiceStats>(this.Credentials, this.StorageUri); requestOptions.ApplyToStorageCommand(retCmd); retCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; retCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => TableHttpRequestMessageFactory.GetServiceStats(uri, serverTimeout, ctx, this.GetCanonicalizer(), this.Credentials); retCmd.RetrieveResponseStream = true; retCmd.ParseError = ODataErrorHelper.ReadFromStreamUsingODataLib; retCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); retCmd.PostProcessResponse = (cmd, resp, ctx) => Task.FromResult(HttpResponseParsers.ReadServiceStats(cmd.ResponseStream)); return(retCmd); }