Exemple #1
0
        private static RESTCommand <TableResult> RetrieveImpl(TableOperation operation, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions)
        {
            RESTCommand <TableResult> rESTCommand = new RESTCommand <TableResult>(client.Credentials, RESTCommandGeneratorUtils.GenerateRequestURI(operation, client.StorageUri, table.Name));

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient = client.HttpClient;
            TableResult result = new TableResult();

            if (operation.SelectColumns != null && operation.SelectColumns.Count > 0)
            {
                rESTCommand.Builder = RESTCommandGeneratorUtils.GenerateQueryBuilder(operation, requestOptions.ProjectSystemProperties);
            }
            rESTCommand.ParseErrorAsync          = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.BuildRequest             = ((RESTCommand <TableResult> cmd, Uri uri, UriQueryBuilder builder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableOperation((builder != null) ? builder.AddToUri(uri) : uri, operation, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.PreProcessResponse       = ((RESTCommand <TableResult> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => TableOperationHttpResponseParsers.TableOperationPreProcess(result, operation, resp, ex));
            rESTCommand.PostProcessResponseAsync = delegate(RESTCommand <TableResult> cmd, HttpResponseMessage resp, OperationContext ctx, CancellationToken token)
            {
                if (resp.StatusCode == HttpStatusCode.NotFound)
                {
                    return(Task.FromResult(result));
                }
                return(TableOperationHttpResponseParsers.TableOperationPostProcessAsync(result, operation, cmd, resp, ctx, requestOptions, client.Credentials.AccountName, token));
            };
            return(rESTCommand);
        }
        internal static RESTCommand <TableQuerySegment <TResult> > GenerateCMDForTableQuery <TResult>(TableQuery query, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver <TResult> resolver, TableRequestOptions requestOptions)
        {
            UriQueryBuilder builder2 = RESTCommandGeneratorUtils.GenerateQueryBuilder(query, requestOptions.ProjectSystemProperties);

            if (token != null)
            {
                RESTCommandGeneratorUtils.ApplyToUriQueryBuilder(token, builder2);
            }
            StorageUri storageUri = NavigationHelper.AppendPathToUri(client.StorageUri, table.Name);
            RESTCommand <TableQuerySegment <TResult> > rESTCommand = new RESTCommand <TableQuerySegment <TResult> >(client.Credentials, storageUri);

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient               = client.HttpClient;
            rESTCommand.CommandLocationMode      = RESTCommandGeneratorUtils.GetListingLocationMode(token);
            rESTCommand.Builder                  = builder2;
            rESTCommand.ParseErrorAsync          = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.BuildRequest             = ((RESTCommand <TableQuerySegment <TResult> > cmd, Uri uri, UriQueryBuilder builder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableQuery(uri, builder, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.PreProcessResponse       = ((RESTCommand <TableQuerySegment <TResult> > cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp?.StatusCode ?? HttpStatusCode.Unused, null, cmd, ex));
            rESTCommand.PostProcessResponseAsync = async delegate(RESTCommand <TableQuerySegment <TResult> > cmd, HttpResponseMessage resp, OperationContext ctx, CancellationToken cancellationToken)
            {
                ResultSegment <TResult> resultSegment = await TableOperationHttpResponseParsers.TableQueryPostProcessGenericAsync <TResult, DynamicTableEntity>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx, cancellationToken);

                if (resultSegment.ContinuationToken != null)
                {
                    resultSegment.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation;
                }
                return(new TableQuerySegment <TResult>(resultSegment));
            };
            return(rESTCommand);
        }
        internal static RESTCommand <NullType> SetServicePropertiesImpl(ServiceProperties properties, CloudTableClient client, TableRequestOptions requestOptions)
        {
            RESTCommand <NullType> rESTCommand = new RESTCommand <NullType>(client.Credentials, client.StorageUri);

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient         = client.HttpClient;
            rESTCommand.BuildRequest       = ((RESTCommand <NullType> cmd, Uri uri, UriQueryBuilder uriBuilder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableServiceProperties(uri, uriBuilder, timeout, HttpMethod.Put, properties, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.ParseErrorAsync    = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.PreProcessResponse = ((RESTCommand <NullType> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp, NullType.Value, cmd, ex));
            return(rESTCommand);
        }
        internal static RESTCommand <ServiceProperties> GetServicePropertiesImpl(CloudTableClient client, TableRequestOptions requestOptions)
        {
            RESTCommand <ServiceProperties> rESTCommand = new RESTCommand <ServiceProperties>(client.Credentials, client.StorageUri);

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient               = client.HttpClient;
            rESTCommand.CommandLocationMode      = CommandLocationMode.PrimaryOrSecondary;
            rESTCommand.BuildRequest             = ((RESTCommand <ServiceProperties> cmd, Uri uri, UriQueryBuilder uriBuilder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableServiceProperties(uri, uriBuilder, timeout, HttpMethod.Get, null, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.ParseErrorAsync          = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.PreProcessResponse       = ((RESTCommand <ServiceProperties> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex));
            rESTCommand.PostProcessResponseAsync = ((RESTCommand <ServiceProperties> cmd, HttpResponseMessage resp, OperationContext ctx, CancellationToken token) => TableOperationHttpResponseParsers.ReadServicePropertiesAsync(cmd.ResponseStream));
            return(rESTCommand);
        }
Exemple #5
0
        private static RESTCommand <TableResult> MergeImpl(TableOperation operation, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions)
        {
            RESTCommand <TableResult> rESTCommand = new RESTCommand <TableResult>(client.Credentials, RESTCommandGeneratorUtils.GenerateRequestURI(operation, client.StorageUri, table.Name));

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient = client.HttpClient;
            TableResult result = new TableResult
            {
                Result = operation.Entity
            };

            rESTCommand.ParseErrorAsync    = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.BuildRequest       = ((RESTCommand <TableResult> cmd, Uri uri, UriQueryBuilder builder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableOperation(uri, operation, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.PreProcessResponse = ((RESTCommand <TableResult> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => TableOperationHttpResponseParsers.TableOperationPreProcess(result, operation, resp, ex));
            return(rESTCommand);
        }
Exemple #6
0
        internal static RESTCommand <ServiceStats> GenerateCMDForGetServiceStats(CloudTableClient client, TableRequestOptions requestOptions)
        {
            RESTCommand <ServiceStats> rESTCommand = new RESTCommand <ServiceStats>(client.Credentials, client.StorageUri);

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient = client.HttpClient;
            LocationMode?locationMode = requestOptions.LocationMode;

            if (locationMode.GetValueOrDefault() == LocationMode.PrimaryOnly && (locationMode.HasValue ? true : false))
            {
                throw new InvalidOperationException("GetServiceStats cannot be run with a 'PrimaryOnly' location mode.");
            }
            rESTCommand.CommandLocationMode      = CommandLocationMode.PrimaryOrSecondary;
            rESTCommand.BuildRequest             = ((RESTCommand <ServiceStats> cmd, Uri uri, UriQueryBuilder uriBuilder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForGetServiceStats(uri, uriBuilder, timeout, SharedKeyCanonicalizer.Instance, client.Credentials, ctx, requestOptions));
            rESTCommand.ParseErrorAsync          = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.PreProcessResponse       = ((RESTCommand <ServiceStats> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null, cmd, ex));
            rESTCommand.PostProcessResponseAsync = ((RESTCommand <ServiceStats> cmd, HttpResponseMessage resp, OperationContext ctx, CancellationToken token) => TableOperationHttpResponseParsers.ReadServiceStatsAsync(cmd.ResponseStream));
            return(rESTCommand);
        }
Exemple #7
0
        internal static RESTCommand <TableBatchResult> GenerateCMDForTableBatchOperation(TableBatchOperation batch, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions)
        {
            RESTCommand <TableBatchResult> rESTCommand = new RESTCommand <TableBatchResult>(client.Credentials, client.StorageUri);

            RESTCommandGeneratorUtils.ApplyTableRequestOptionsToStorageCommand(requestOptions, rESTCommand);
            rESTCommand.HttpClient = client.HttpClient;
            TableBatchResult results = new TableBatchResult();

            rESTCommand.CommandLocationMode      = ((!batch.ContainsWrites) ? CommandLocationMode.PrimaryOrSecondary : CommandLocationMode.PrimaryOnly);
            rESTCommand.CommandLocationMode      = CommandLocationMode.PrimaryOnly;
            rESTCommand.ParseErrorAsync          = StorageExtendedErrorInformationRestHelper.ReadExtendedErrorInfoFromStreamAsync;
            rESTCommand.BuildRequest             = ((RESTCommand <TableBatchResult> cmd, Uri uri, UriQueryBuilder builder, HttpContent httpContent, int?timeout, OperationContext ctx) => TableRequestMessageFactory.BuildStorageRequestMessageForTableBatchOperation(uri, batch, SharedKeyCanonicalizer.Instance, table.Name, client.Credentials, ctx, requestOptions));
            rESTCommand.PreProcessResponse       = ((RESTCommand <TableBatchResult> cmd, HttpResponseMessage resp, Exception ex, OperationContext ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.Accepted, resp?.StatusCode ?? HttpStatusCode.Unused, results, cmd, ex));
            rESTCommand.PostProcessResponseAsync = ((RESTCommand <TableBatchResult> cmd, HttpResponseMessage resp, OperationContext ctx, CancellationToken token) => TableOperationHttpResponseParsers.TableBatchOperationPostProcessAsync(results, batch, cmd, resp, ctx, requestOptions, client.Credentials.AccountName, token));
            rESTCommand.RecoveryAction           = delegate
            {
                results.Clear();
            };
            return(rESTCommand);
        }