public static Task <IEnumerable <ScopeSpec> > GetAllScopesAsync(this ICollectionManager manager, Action <GetAllScopesOptions> configureOptions) { var options = new GetAllScopesOptions(); configureOptions(options); return(manager.GetAllScopesAsync(options)); }
public async Task <IEnumerable <ScopeSpec> > GetAllScopesAsync(GetAllScopesOptions options = null) { options ??= GetAllScopesOptions.Default; var uri = GetUri(); Logger.LogInformation($"Attempting to get all scopes - {uri}"); try { // get manifest var result = await _client.GetAsync(uri, options.TokenValue).ConfigureAwait(false); result.EnsureSuccessStatusCode(); // check scope & collection exists in manifest var json = JObject.Parse(await result.Content.ReadAsStringAsync().ConfigureAwait(false)); var scopes = json.SelectToken("scopes"); if (scopes.Type != JTokenType.Array) // TODO: remove after SDK beta as per RFC { // older style - scopes is a map return(scopes.Select(scope => { var scopeName = scope.Path.Substring(scope.Path.LastIndexOf(".", StringComparison.InvariantCulture) + 1); var collections = scope.First()["collections"].Select(collection => { var collectionName = collection.Path.Substring(collection.Path.LastIndexOf(".", StringComparison.InvariantCulture) + 1); return new CollectionSpec(scopeName, collectionName); }).ToList(); return new ScopeSpec(scopeName) { Collections = collections }; }).ToList()); } // newer style - scopes is an array return(scopes.Select(scope => new ScopeSpec(scope["name"].Value <string>()) { Collections = scope["collections"].Select(collection => new CollectionSpec(collection["name"].Value <string>(), scope["name"].Value <string>()) ).ToList() }).ToList()); } catch (Exception exception) { Logger.LogError(exception, $"Failed to get all scopes - {uri}"); throw; } }