コード例 #1
0
ファイル: Program.cs プロジェクト: guojianbin/elephant
        private static async Task RunSetMapSamplesAsync(ISetMap <Guid, Data> setMap)
        {
            var id   = Guid.NewGuid();
            var data = new Data()
            {
                Name = "A name", Value = 5
            };

            // A SetMap is a map of sets items with special extensions methods
            // Uses an extension method that adds an item to a set in the key
            await setMap.AddItemAsync(id, data);

            var set = await setMap.GetValueOrDefaultAsync(id);

            if (await set.ContainsAsync(data))
            {
                Console.WriteLine($"The value '{data}' is present in the set");
            }

            // Removes the item from the set map
            if (await setMap.TryRemoveItemAsync(id, data))
            {
                Console.WriteLine($"The item of the set in the key '{id}' was removed");
            }
        }
コード例 #2
0
        public virtual async Task ClearAsync(CancellationToken cancellationToken)
        {
            var keysSet = await KeysSetMap.GetValueOrDefaultAsync(Name).ConfigureAwait(false);

            if (keysSet != null)
            {
                var keysEnumerable = keysSet.AsEnumerableAsync();
                await keysEnumerable.ForEachAwaitAsync(async k =>
                {
                    IScopedMap scopedMap;
                    if (ScopedMapDictionary.TryGetValue(k.Identifier, out scopedMap))
                    {
                        await scopedMap.RemoveKeyAsync(k.Key).ConfigureAwait(false);
                    }
                },
                                                       cancellationToken);
            }

            await KeysSetMap.TryRemoveAsync(Name).ConfigureAwait(false);
        }
コード例 #3
0
 public Task <ISet <TValue> > GetValueOrDefaultAsync(TKey key, CancellationToken cancellationToken = default) =>
 _underlyingSetMap.GetValueOrDefaultAsync(key, cancellationToken);