/// <summary> /// Returns a result segment containing a collection of queues. /// </summary> /// <param name="prefix">A string containing the queue name prefix.</param> /// <param name="queueListingDetails">A <see cref="QueueListingDetails"/> enumeration describing which items to include in the listing.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned at a time, up to the /// per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="currentToken">A <see cref="QueueContinuationToken"/> returned by a previous listing operation.</param> /// <param name="options">A <see cref="QueueRequestOptions"/> object that specifies additional options for the request. If <c>null</c>, default options are applied to the request.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A <see cref="QueueResultSegment"/> object.</returns> public virtual QueueResultSegment ListQueuesSegmented(string prefix, QueueListingDetails queueListingDetails, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options = null, OperationContext operationContext = null) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); ResultSegment <CloudQueue> resultSegment = this.ListQueuesSegmentedCore(prefix, queueListingDetails, maxResults, currentToken, modifiedOptions, operationContext); return(new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken)); }
internal static ResultSegment <TElement> TableQueryPostProcessGeneric <TElement, TQueryType>(Stream responseStream, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, HttpWebResponse resp, TableRequestOptions options, OperationContext ctx, string accountName) { ResultSegment <TElement> retSeg = new ResultSegment <TElement>(new List <TElement>()); retSeg.ContinuationToken = ContinuationFromResponse(resp); if (resp.ContentType.Contains(Constants.JsonNoMetadataAcceptHeaderValue)) { ReadQueryResponseUsingJsonParser(retSeg, responseStream, resp.Headers[Constants.HeaderConstants.EtagHeader], resolver, options.PropertyResolver, typeof(TQueryType), null, options); } else { ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings(); readerSettings.MessageQuotas = new ODataMessageQuotas() { MaxPartsPerBatch = TableConstants.TableServiceMaxResults, MaxReceivedMessageSize = TableConstants.TableServiceMaxPayload }; using (ODataMessageReader responseReader = new ODataMessageReader(new HttpResponseAdapterMessage(resp, responseStream), readerSettings, new TableStorageModel(accountName))) { // create a reader ODataReader reader = responseReader.CreateODataFeedReader(); // Start => FeedStart if (reader.State == ODataReaderState.Start) { reader.Read(); } // Feedstart if (reader.State == ODataReaderState.FeedStart) { reader.Read(); } while (reader.State == ODataReaderState.EntryStart) { // EntryStart => EntryEnd reader.Read(); ODataEntry entry = (ODataEntry)reader.Item; retSeg.Results.Add(ReadAndResolve(entry, resolver, options)); // Entry End => ? reader.Read(); } DrainODataReader(reader); } } Logger.LogInformational(ctx, SR.RetrieveWithContinuationToken, retSeg.Results.Count, retSeg.ContinuationToken); return(retSeg); }
private static RESTCommand <TableQuerySegment <RESULT_TYPE> > QueryImpl <T, RESULT_TYPE>(TableQuery <T> query, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver <RESULT_TYPE> resolver, TableRequestOptions requestOptions) { requestOptions.AssertPolicyIfRequired(); // If encryption policy is set, then add the encryption metadata column to Select columns in order to be able to decrypt properties. if (requestOptions.EncryptionPolicy != null && query.SelectColumns != null && query.SelectColumns.Count() > 0) { query.SelectColumns.Add(Constants.EncryptionConstants.TableEncryptionKeyDetails); query.SelectColumns.Add(Constants.EncryptionConstants.TableEncryptionPropertyDetails); } UriQueryBuilder builder = query.GenerateQueryBuilder(requestOptions.ProjectSystemProperties); if (token != null) { token.ApplyToUriQueryBuilder(builder); } StorageUri tempUri = NavigationHelper.AppendPathToUri(client.StorageUri, table.Name); RESTCommand <TableQuerySegment <RESULT_TYPE> > queryCmd = new RESTCommand <TableQuerySegment <RESULT_TYPE> >(client.Credentials, tempUri); requestOptions.ApplyToStorageCommand(queryCmd); queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token); queryCmd.RetrieveResponseStream = true; queryCmd.SignRequest = client.AuthenticationHandler.SignRequest; queryCmd.Builder = builder; queryCmd.ParseError = ODataErrorHelper.ReadFromStreamUsingODataLib; queryCmd.BuildRequestDelegate = (uri, queryBuilder, timeout, useVersionHeader, ctx) => TableOperationHttpWebRequestFactory.BuildRequestForTableQuery(uri, queryBuilder, timeout, useVersionHeader, ctx, requestOptions.PayloadFormat.Value); queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp != null ? resp.StatusCode : HttpStatusCode.Unused, null /* retVal */, cmd, ex); queryCmd.PostProcessResponse = (cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = TableOperationHttpResponseParsers.TableQueryPostProcessGeneric <RESULT_TYPE, T>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; queryCmd.PostProcessResponseAsync = async(cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = await TableOperationHttpResponseParsers.TableQueryPostProcessGenericAsync <RESULT_TYPE, T>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; return(queryCmd); }
public virtual async Task <FileResultSegment> ListFilesAndDirectoriesSegmentedAsync(string prefix, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient); ResultSegment <IListFileItem> resultSegment = await Executor.ExecuteAsync( this.ListFilesAndDirectoriesImpl(maxResults, modifiedOptions, currentToken, prefix), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new FileResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }
public virtual async Task <ShareResultSegment> ListSharesSegmentedAsync(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this); ResultSegment <CloudFileShare> resultSegment = await Executor.ExecuteAsync( this.ListSharesImpl(prefix, detailsIncluded, currentToken, maxResults, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new ShareResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }
public virtual async Task <ContainerResultSegment> ListContainersSegmentedAsync(string prefix, ContainerListingDetails detailsIncluded, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.Unspecified, this); ResultSegment <CloudBlobContainer> resultSegment = await Executor.ExecuteAsync( this.ListContainersImpl(prefix, detailsIncluded, currentToken, maxResults, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return(new ContainerResultSegment(resultSegment.Results, (BlobContinuationToken)resultSegment.ContinuationToken)); }
/// <summary> /// Returns a result segment containing a collection of queues /// whose names begin with the specified prefix. /// </summary> /// <param name="prefix">The queue name prefix.</param> /// <param name="detailsIncluded">A value that indicates whether to return queue metadata with the listing.</param> /// <param name="maxResults">A non-negative integer value that indicates the maximum number of results to be returned /// in the result segment, up to the per-operation limit of 5000. If this value is <c>null</c>, the maximum possible number of results will be returned, up to 5000.</param> /// <param name="currentToken">A <see cref="QueueContinuationToken"/> token returned by a previous listing operation.</param> /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param> /// <returns>A result segment of queues.</returns> public IAsyncOperation <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails detailsIncluded, int?maxResults, QueueContinuationToken currentToken, OperationContext operationContext) { return(AsyncInfo.Run(async(token) => { ResultSegment <CloudQueue> resultSegment = await Executor.ExecuteAsync( this.ListQueuesImpl(prefix, detailsIncluded, currentToken, maxResults), this.RetryPolicy, operationContext, token); return new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken); })); }
public virtual async Task<QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails detailsIncluded, int? maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); ResultSegment<CloudQueue> resultSegment = await Executor.ExecuteAsync( this.ListQueuesImpl(prefix, maxResults, detailsIncluded, modifiedOptions, currentToken), modifiedOptions.RetryPolicy, operationContext, cancellationToken).ConfigureAwait(false); return new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken); }
public IAsyncOperation <ShareResultSegment> ListSharesSegmentedAsync(string prefix, ShareListingDetails detailsIncluded, int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext) { return(AsyncInfo.Run(async(token) => { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this); ResultSegment <CloudFileShare> resultSegment = await Executor.ExecuteAsync( this.ListSharesImpl(prefix, detailsIncluded, currentToken, maxResults, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, token); return new ShareResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken); })); }
public IAsyncOperation <ContainerResultSegment> ListContainersSegmentedAsync(string prefix, ContainerListingDetails detailsIncluded, int?maxResults, BlobContinuationToken currentToken, BlobRequestOptions options, OperationContext operationContext) { return(AsyncInfo.Run(async(token) => { BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.Unspecified, this); ResultSegment <CloudBlobContainer> resultSegment = await Executor.ExecuteAsync( this.ListContainersImpl(prefix, detailsIncluded, currentToken, maxResults, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, token); return new ContainerResultSegment(resultSegment.Results, (BlobContinuationToken)resultSegment.ContinuationToken); })); }
internal static Task <ResultSegment <TElement> > TableQueryPostProcessGeneric <TElement>(Stream responseStream, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, HttpResponseMessage resp, OperationContext ctx) { return(Task.Run(() => { ResultSegment <TElement> retSeg = new ResultSegment <TElement>(new List <TElement>()); retSeg.ContinuationToken = ContinuationFromResponse(resp); ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings(); readerSettings.MessageQuotas = new ODataMessageQuotas() { MaxPartsPerBatch = TableConstants.TableServiceMaxResults, MaxReceivedMessageSize = TableConstants.TableServiceMaxPayload }; using (ODataMessageReader responseReader = new ODataMessageReader(new HttpResponseAdapterMessage(resp, responseStream), readerSettings)) { // create a reader ODataReader reader = responseReader.CreateODataFeedReader(); // Start => FeedStart if (reader.State == ODataReaderState.Start) { reader.Read(); } // Feedstart if (reader.State == ODataReaderState.FeedStart) { reader.Read(); } while (reader.State == ODataReaderState.EntryStart) { // EntryStart => EntryEnd reader.Read(); ODataEntry entry = (ODataEntry)reader.Item; retSeg.Results.Add(ReadAndResolve(entry, resolver)); // Entry End => ? reader.Read(); } DrainODataReader(reader); } return retSeg; })); }
internal static async Task ReadQueryResponseUsingJsonParserAsync <TElement>(ResultSegment <TElement> retSeg, Stream responseStream, string etag, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, Func <string, string, string, string, EdmType> propertyResolver, Type type, OperationContext ctx, TableRequestOptions options, CancellationToken cancellationToken) { StreamReader reader2 = new StreamReader(responseStream); bool disablePropertyResolverCache = false; if (TableEntity.DisablePropertyResolverCache) { disablePropertyResolverCache = TableEntity.DisablePropertyResolverCache; Logger.LogVerbose(ctx, "Property resolver cache is disabled."); } using (JsonReader reader = new JsonTextReader(reader2)) { reader.DateParseHandling = DateParseHandling.None; foreach (JToken item in (IEnumerable <JToken>)(await JObject.LoadAsync(reader, cancellationToken).ConfigureAwait(continueOnCapturedContext: false))["value"]) { string etag2; Dictionary <string, object> dictionary = ReadSingleItem(item, out etag2); Dictionary <string, string> dictionary2 = new Dictionary <string, string>(); foreach (string key in dictionary.Keys) { if (dictionary[key] == null) { dictionary2.Add(key, null); } else if (dictionary[key] is string) { dictionary2.Add(key, (string)dictionary[key]); } else if (dictionary[key] is DateTime) { dictionary2.Add(key, ((DateTime)dictionary[key]).ToUniversalTime().ToString("o")); } else { if (!(dictionary[key] is bool) && !(dictionary[key] is double) && !(dictionary[key] is int)) { throw new StorageException(string.Format(CultureInfo.InvariantCulture, "Invalid type in JSON object. Detected type is {0}, which is not a valid JSON type.", dictionary[key].GetType().ToString())); } dictionary2.Add(key, dictionary[key].ToString()); } } retSeg.Results.Add(ReadAndResolveWithEdmTypeResolver(dictionary2, resolver, propertyResolver, etag, type, ctx, disablePropertyResolverCache, options)); } if (await reader.ReadAsync(cancellationToken).ConfigureAwait(continueOnCapturedContext: false)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The JSON reader has not yet reached the completed state.")); } } }
public virtual Task <FileResultSegment> ListFilesAndDirectoriesSegmentedAsync(int?maxResults, FileContinuationToken currentToken, FileRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient); return(Task.Run(async() => { ResultSegment <IListFileItem> resultSegment = await Executor.ExecuteAsync( this.ListFilesAndDirectoriesImpl(maxResults, modifiedOptions, currentToken), modifiedOptions.RetryPolicy, operationContext, cancellationToken); return new FileResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken); }, cancellationToken)); }
public TableResultSegment EndListTablesSegmented(IAsyncResult asyncResult) { ResultSegment <DynamicTableEntity> res = Executor.EndExecuteAsync <ResultSegment <DynamicTableEntity> >(asyncResult); List <CloudTable> tables = res.Results.Select(tbl => new CloudTable( NavigationHelper.AppendPathToUri(this.BaseUri, tbl.Properties[TableConstants.TableName].StringValue), this)).ToList(); TableResultSegment retSeg = new TableResultSegment(tables) { ContinuationToken = res.ContinuationToken as TableContinuationToken }; return(retSeg); }
public List <IListBlobItem> ListPathContents(int depth, string containerName, string accountid, string campaignid) { CloudBlobClient blobClient = CloudStorageAccount.CreateCloudBlobClient();// storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(containerName); BlobRequestOptions options = new BlobRequestOptions(); options.UseFlatBlobListing = true; ResultSegment <IListBlobItem> resultSegment = container.ListBlobsSegmented(options); IEnumerable <IListBlobItem> mylist = resultSegment.Results; IEnumerable <IListBlobItem> mylist2 = (from o in mylist where o.Uri.Segments.Count() == depth && o.Uri.Segments[depth - 3] == accountid.ToString() + "/" && o.Uri.Segments[depth - 2] == campaignid.ToString() + "/" select o); return(mylist2.ToList()); }
public IAsyncOperation <QueueResultSegment> ListQueuesSegmentedAsync(string prefix, QueueListingDetails detailsIncluded, int?maxResults, QueueContinuationToken currentToken, QueueRequestOptions options, OperationContext operationContext) { QueueRequestOptions modifiedOptions = QueueRequestOptions.ApplyDefaults(options, this); operationContext = operationContext ?? new OperationContext(); return(AsyncInfo.Run(async(token) => { ResultSegment <CloudQueue> resultSegment = await Executor.ExecuteAsync( this.ListQueuesImpl(prefix, maxResults, detailsIncluded, modifiedOptions, currentToken), modifiedOptions.RetryPolicy, operationContext, token); return new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken); })); }
// Callback for the segmented file listing in order to continue listing segments private void ListFileTransferCallback(IAsyncResult result) { ResultSegment <IListBlobItem> list = ContainerFileTransfer.EndListBlobsSegmented(result); foreach (CloudBlob b in list.Results) { this.Invoke(new AddFileTransferDelegate(this.AddFileTransfer), new object[] { b }); } if (list.ContinuationToken != null) { BlobRequestOptions options = new BlobRequestOptions(); options.UseFlatBlobListing = true; ContainerFileTransfer.BeginListBlobsSegmented(5, list.ContinuationToken, options, new AsyncCallback(ListFileTransferCallback), null); } else { this.Invoke(new FinishedLoadingFileTransferDelegate(FinishedLoadingFileTransfer)); } }
/// <summary> /// 下一个页面 /// </summary> /// <returns>下一个页面.如果当前页面是最后一页,返回最后一页.</returns> public IEnumerable <T> GetNextPage() { // 获取缓存数据 var cachedData = this._provider.GetCachedData(); int pageCount = 0; if (cachedData != null) { pageCount = Convert.ToInt32(Math.Ceiling((double)cachedData.Count() / (double)this.PageSize)); } // 如果存储表中仍然有实体可读并且当前页是最后一个页面, // 请求表存储获取新数据. if (!this._provider.HasReachedEnd && CurrentPageIndex == pageCount - 1) { var q = this._tableServiceContext.CreateQuery <T>(this._entitySetName).Take(PageSize).AsTableServiceQuery(); IAsyncResult r; r = q.BeginExecuteSegmented(RC, (ar) => { }, q); r.AsyncWaitHandle.WaitOne(); ResultSegment <T> result = q.EndExecuteSegmented(r); var results = result.Results; this._provider.AddDataToCache(results); // 如果有实体返回我们需要增加页面数 if (results.Count() > 0) { pageCount++; } RC = result.ContinuationToken; // 如果返回记号为空意味着表中不再有实体了 if (result.ContinuationToken == null) { this._provider.HasReachedEnd = true; } } CurrentPageIndex = CurrentPageIndex + 1 < pageCount ? CurrentPageIndex + 1 : pageCount - 1; if (cachedData == null) { cachedData = this._provider.GetCachedData(); } return(cachedData.Skip((this.CurrentPageIndex) * this.PageSize).Take(this.PageSize)); }
/// <summary> /// Get the next page /// </summary> /// <returns>The next page. If current page is the last page it returns the last page.</returns> public IEnumerable <T> GetNextPage() { // Get cached data var cachedData = this._provider.GetCachedData(); int pageCount = 0; if (cachedData != null) { pageCount = Convert.ToInt32(Math.Ceiling((double)cachedData.Count() / (double)this.PageSize)); } // If there still has entities in table storage to read and the current page is the last page, // request table storage to get new data. if (!this._provider.HasReachedEnd && CurrentPageIndex == pageCount - 1) { var q = this._tableServiceContext.CreateQuery <T>(this._entitySetName).Take(PageSize).AsTableServiceQuery(); IAsyncResult r; r = q.BeginExecuteSegmented(RC, (ar) => { }, q); r.AsyncWaitHandle.WaitOne(); ResultSegment <T> result = q.EndExecuteSegmented(r); var results = result.Results; this._provider.AddDataToCache(results); // If there's any entity returns we need to increase pageCount if (results.Count() > 0) { pageCount++; } RC = result.ContinuationToken; // If the returned token is null it means there's no more entities in table if (result.ContinuationToken == null) { this._provider.HasReachedEnd = true; } } CurrentPageIndex = CurrentPageIndex + 1 < pageCount ? CurrentPageIndex + 1 : pageCount - 1; if (cachedData == null) { cachedData = this._provider.GetCachedData(); } return(cachedData.Skip((this.CurrentPageIndex) * this.PageSize).Take(this.PageSize)); }
internal static async Task <ResultSegment <TElement> > TableQueryPostProcessGenericAsync <TElement, TQueryType>(Stream responseStream, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, HttpResponseMessage resp, TableRequestOptions options, OperationContext ctx, CancellationToken cancellationToken) { ResultSegment <TElement> retSeg = new ResultSegment <TElement>(new List <TElement>()) { ContinuationToken = ContinuationFromResponse(resp) }; MediaTypeHeaderValue contentType = resp.Content.Headers.ContentType; if (contentType.MediaType.Equals("application/json") && contentType.Parameters.Contains(NameValueHeaderValue.Parse("odata=nometadata"))) { await ReadQueryResponseUsingJsonParserAsync(retSeg, responseStream, resp.Headers.ETag?.Tag, resolver, options.PropertyResolver, typeof(TQueryType), null, options, cancellationToken); } else { foreach (KeyValuePair <string, Dictionary <string, object> > item in await ReadQueryResponseUsingJsonParserMetadataAsync(responseStream, cancellationToken)) { retSeg.Results.Add(ReadAndResolve(item.Key, item.Value, resolver, options)); } } Logger.LogInformational(ctx, "Retrieved '{0}' results with continuation token '{1}'.", retSeg.Results.Count, retSeg.ContinuationToken); return(retSeg); }
private static void ReadQueryResponseUsingJsonParser <TElement>(ResultSegment <TElement> retSeg, Stream responseStream, string etag, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, Func <string, string, string, string, EdmType> propertyResolver, Type type, OperationContext ctx) { StreamReader streamReader = new StreamReader(responseStream); using (JsonReader reader = new JsonTextReader(streamReader)) { reader.DateParseHandling = DateParseHandling.None; JObject dataSet = JObject.Load(reader); JToken dataTable = dataSet["value"]; foreach (JToken token in dataTable) { Dictionary <string, string> properties = token.ToObject <Dictionary <string, string> >(); retSeg.Results.Add(ReadAndResolveWithEdmTypeResolver(properties, resolver, propertyResolver, etag, type, ctx)); } if (reader.Read()) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, SR.JsonReaderNotInCompletedState)); } } }
private ResultSegment <TElement> ParseTableQueryResponse(IEnumerable <TElement> dataServiceQueryResponse, RequestResult reqResult, TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd) { if (reqResult.Exception != null) { DataServiceClientException dsce = TableUtilities.FindInnerExceptionOfType <DataServiceClientException>(reqResult.Exception); if (this.IgnoreResourceNotFoundException && dsce != null && (HttpStatusCode)dsce.StatusCode == HttpStatusCode.NotFound) { return(new ResultSegment <TElement>(new List <TElement>())); } throw reqResult.Exception; } QueryOperationResponse response = dataServiceQueryResponse as QueryOperationResponse; ResultSegment <TElement> retSeg = new ResultSegment <TElement>(dataServiceQueryResponse.ToList()); // Get continuation token from response retSeg.ContinuationToken = TableUtilities.ContinuationFromResponse(response); return(retSeg); }
private RESTCommand <TableQuerySegment <RESULT_TYPE> > QueryImpl <RESULT_TYPE>(TableContinuationToken token, CloudTableClient client, string tableName, EntityResolver <RESULT_TYPE> resolver, TableRequestOptions requestOptions) { UriQueryBuilder builder = this.GenerateQueryBuilder(); if (token != null) { token.ApplyToUriQueryBuilder(builder); } StorageUri tempUri = NavigationHelper.AppendPathToUri(client.StorageUri, tableName); RESTCommand <TableQuerySegment <RESULT_TYPE> > queryCmd = new RESTCommand <TableQuerySegment <RESULT_TYPE> >(client.Credentials, tempUri); requestOptions.ApplyToStorageCommand(queryCmd); queryCmd.CommandLocationMode = CommonUtility.GetListingLocationMode(token); queryCmd.RetrieveResponseStream = true; queryCmd.Handler = client.AuthenticationHandler; queryCmd.BuildClient = HttpClientFactory.BuildHttpClient; queryCmd.ParseError = StorageExtendedErrorInformation.ReadFromStreamUsingODataLib; queryCmd.Builder = builder; queryCmd.BuildRequest = (cmd, uri, queryBuilder, cnt, serverTimeout, ctx) => TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(uri, builder, serverTimeout, cnt, ctx, requestOptions.PayloadFormat.Value); queryCmd.PreProcessResponse = (cmd, resp, ex, ctx) => HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp.StatusCode, null /* retVal */, cmd, ex); queryCmd.PostProcessResponse = async(cmd, resp, ctx) => { ResultSegment <RESULT_TYPE> resSeg = await TableOperationHttpResponseParsers.TableQueryPostProcessGeneric <RESULT_TYPE>(cmd.ResponseStream, resolver.Invoke, resp, requestOptions, ctx, client.AccountName); if (resSeg.ContinuationToken != null) { resSeg.ContinuationToken.TargetLocation = cmd.CurrentResult.TargetLocation; } return(new TableQuerySegment <RESULT_TYPE>(resSeg)); }; return(queryCmd); }
public static async Task ReadQueryResponseUsingJsonParserAsync <TElement>(ResultSegment <TElement> retSeg, Stream responseStream, string etag, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, Func <string, string, string, string, EdmType> propertyResolver, Type type, OperationContext ctx, TableRequestOptions options, System.Threading.CancellationToken cancellationToken) { StreamReader streamReader = new StreamReader(responseStream); #if WINDOWS_DESKTOP && !WINDOWS_PHONE if (TableEntity.DisablePropertyResolverCache) { disablePropertyResolverCache = TableEntity.DisablePropertyResolverCache; Logger.LogVerbose(ctx, SR.PropertyResolverCacheDisabled); } #endif using (JsonReader reader = new JsonTextReader(streamReader)) { reader.DateParseHandling = DateParseHandling.None; JObject dataSet = await JObject.LoadAsync(reader, cancellationToken).ConfigureAwait(false); JToken dataTable = dataSet["value"]; foreach (JToken token in dataTable) { string unused; Dictionary <string, object> results = ReadSingleItem(token, out unused); Dictionary <string, string> properties = new Dictionary <string, string>(); foreach (string key in results.Keys) { if (results[key] == null) { properties.Add(key, null); continue; } if (results[key] is string) { properties.Add(key, (string)results[key]); } else if (results[key] is DateTime) { properties.Add(key, ((DateTime)results[key]).ToUniversalTime().ToString("o")); } // This should never be a long; if requires a 64-bit number the service will send it as a string instead. else if (results[key] is bool || results[key] is double || results[key] is int) { properties.Add(key, (results[key]).ToString()); } else { throw new StorageException(string.Format(CultureInfo.InvariantCulture, SR.InvalidTypeInJsonDictionary, results[key].GetType().ToString())); } } retSeg.Results.Add(ReadAndResolveWithEdmTypeResolver(properties, resolver, propertyResolver, etag, type, ctx)); } if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, SR.JsonReaderNotInCompletedState)); } } }
internal TableQuerySegment(ResultSegment <TElement> resSeg) : this(resSeg.Results) { throw new System.NotImplementedException(); }
/// <summary> /// Ends an asynchronous operation to return a result segment containing a collection of queues. /// </summary> /// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the pending asynchronous operation.</param> /// <returns>A <see cref="QueueResultSegment"/> object.</returns> public QueueResultSegment EndListQueuesSegmented(IAsyncResult asyncResult) { ResultSegment <CloudQueue> resultSegment = Executor.EndExecuteAsync <ResultSegment <CloudQueue> >(asyncResult); return(new QueueResultSegment(resultSegment.Results, (QueueContinuationToken)resultSegment.ContinuationToken)); }
/// <summary> /// Ends an asynchronous operation to return a result segment containing a collection of shares. /// </summary> /// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the pending asynchronous operation.</param> /// <returns>A result segment of shares.</returns> public ShareResultSegment EndListSharesSegmented(IAsyncResult asyncResult) { ResultSegment <CloudFileShare> resultSegment = Executor.EndExecuteAsync <ResultSegment <CloudFileShare> >(asyncResult); return(new ShareResultSegment(resultSegment.Results, (FileContinuationToken)resultSegment.ContinuationToken)); }
internal static Task <ResultSegment <TElement> > TableQueryPostProcessGeneric <TElement>(Stream responseStream, Func <string, string, DateTimeOffset, IDictionary <string, EntityProperty>, string, TElement> resolver, HttpResponseMessage resp, TableRequestOptions options, OperationContext ctx, string accountName) { return(Task.Run(() => { ResultSegment <TElement> retSeg = new ResultSegment <TElement>(new List <TElement>()); retSeg.ContinuationToken = ContinuationFromResponse(resp); IEnumerable <string> contentType; IEnumerable <string> eTag; resp.Content.Headers.TryGetValues(Constants.ContentTypeElement, out contentType); resp.Headers.TryGetValues(Constants.EtagElement, out eTag); string ContentType = contentType != null ? contentType.FirstOrDefault() : null; string ETag = eTag != null ? eTag.FirstOrDefault() : null; if (ContentType.Contains(Constants.JsonContentTypeHeaderValue) && ContentType.Contains(Constants.NoMetadata)) { ReadQueryResponseUsingJsonParser(retSeg, responseStream, ETag, resolver, options.PropertyResolver, typeof(TElement), null); } else { ODataMessageReaderSettings readerSettings = new ODataMessageReaderSettings(); readerSettings.MessageQuotas = new ODataMessageQuotas() { MaxPartsPerBatch = TableConstants.TableServiceMaxResults, MaxReceivedMessageSize = TableConstants.TableServiceMaxPayload }; using (ODataMessageReader responseReader = new ODataMessageReader(new HttpResponseAdapterMessage(resp, responseStream), readerSettings, new TableStorageModel(accountName))) { // create a reader ODataReader reader = responseReader.CreateODataFeedReader(); // Start => FeedStart if (reader.State == ODataReaderState.Start) { reader.Read(); } // Feedstart if (reader.State == ODataReaderState.FeedStart) { reader.Read(); } while (reader.State == ODataReaderState.EntryStart) { // EntryStart => EntryEnd reader.Read(); ODataEntry entry = (ODataEntry)reader.Item; retSeg.Results.Add(ReadAndResolve(entry, resolver)); // Entry End => ? reader.Read(); } DrainODataReader(reader); } } return retSeg; })); }
/// <summary> /// Ends an asynchronous operation to return a result segment containing a collection of containers. /// </summary> /// <param name="asyncResult">An <see cref="IAsyncResult"/> that references the pending asynchronous operation.</param> /// <returns>A result segment of containers.</returns> public ContainerResultSegment EndListContainersSegmented(IAsyncResult asyncResult) { ResultSegment <CloudBlobContainer> resultSegment = Executor.EndExecuteAsync <ResultSegment <CloudBlobContainer> >(asyncResult); return(new ContainerResultSegment(resultSegment.Results, (BlobContinuationToken)resultSegment.ContinuationToken)); }
internal TableQuerySegment(ResultSegment <TElement> resSeg) : this(resSeg.Results) { this.continuationToken = (TableContinuationToken)resSeg.ContinuationToken; }