Example #1
0
        public async Task <IEnumerable <ApiResource> > FindApiResourcesByScopeAsync(IEnumerable <string> scopeNames)
        {
            var getTasks = new List <Task <ApiResource> >();

            foreach (var scopeName in scopeNames)
            {
                getTasks.Add(_apiStore.GetAsync(scopeName));
            }

            var fetched = await Task.WhenAll(getTasks.ToArray());

            return(fetched.Where(f => f != null));
        }
Example #2
0
        public async Task <IEnumerable <Scope> > FindScopesAsync(IEnumerable <string> scopeNames)
        {
            var getTasks = new List <Task <Scope> >();

            foreach (var scopeName in scopeNames)
            {
                getTasks.Add(_store.GetAsync(scopeName));
            }

            return(await Task.WhenAll(getTasks.ToArray()));
        }
Example #3
0
        public async Task <IEnumerable <Event> > ProcessAsync(Event evnt)
        {
            var events = new List <Event>();
            var blob   = await _keyValueStore.GetAsync("newsFeeds.txt");

            var reader = new StreamReader(blob.Body);

            string line = string.Empty;

            while ((line = reader.ReadLine()) != null)
            {
                if (!string.IsNullOrEmpty(line))
                {
                    events.Add(new Event(new NewsFeedPulsed()
                    {
                        Url = line
                    }));
                }
            }
            return(events);
        }
 public Task <Client> FindClientByIdAsync(string clientId)
 {
     return(_store.GetAsync(clientId));
 }
Example #5
0
        public async Task WriteAsync <T>(string key, T value, bool forceOverride = false, CancellationToken cancellationToken = default)
        {
            var(keyType, _, _, _, _) = ExtractKey(key);
            var(underlyingKey, jsonPath, subPath) = ExtractKeyPath(key);
            var isFullOverride = false;

            switch (keyType)
            {
            case KeyType.Common:
                isFullOverride = true;
                break;

            case KeyType.City:
            case KeyType.Company:
                isFullOverride = string.IsNullOrWhiteSpace(jsonPath);
                break;
            }
            var rootValueString = "{}";

            try
            {
                rootValueString = await _keyValueStore.GetAsync(underlyingKey, cancellationToken);
            }
            catch (KeyNotExistException)
            {
                if (!isFullOverride)
                {
                    //TODO 直接覆盖
                    if (!forceOverride)
                    {
                        throw;
                    }
                }
            }
            if (string.IsNullOrWhiteSpace(rootValueString))
            {
                rootValueString = "{}";
            }

            JToken rootValue = default;

            try
            {
                rootValue = JToken.Parse(rootValueString);
            }
            catch (System.Exception e)
            {
                if (!isFullOverride)
                {
                    throw new KeyValueException($"无法读取json, key: {key}", e);
                }
            }

            var newValue = JToken.FromObject(value);

            if (isFullOverride)
            {
                rootValue = newValue;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(subPath))
                {
                    rootValue[jsonPath] = newValue;
                }
                else
                {
                    var subToken = rootValue[jsonPath];
                    if (subToken != null)
                    {
                        rootValue[jsonPath][subPath] = newValue;
                    }
                    else
                    {
                        rootValue[jsonPath] = JToken.FromObject(new Dictionary <string, object>
                        {
                            { subPath, newValue },
                        });
                    }
                }
            }
            var sb = new System.Text.StringBuilder();

            using var sWriter = new System.IO.StringWriter(sb);
            using var jWriter = new JsonTextWriter(sWriter);
            await rootValue.WriteToAsync(jWriter);

            var newValueString = sb.ToString();
            await _keyValueStore.SetAsync(underlyingKey, newValueString, cancellationToken);
        }
Example #6
0
 public Task <PersistedGrant> GetAsync(string key)
 {
     return(_store.GetAsync(key));
 }