public static async Task <T> GetOrDefaultAsync <T>(
        this IKeyValueStore store, IValueKey <T> key, CancellationToken cancellation = default(CancellationToken))
    {
        Contracts.Requires.That(store != null);
        Contracts.Requires.That(key != null);

        var result = await store.TryGetAsync(key, cancellation).DontMarshallContext();

        return(result.HasValue ? result.Value : default(T));
    }
        /// <inheritdoc />
        public async Task <TryValue <T> > TryGetAsync <T>(
            IValueKey <T> key, CancellationToken cancellation = default(CancellationToken))
        {
            IKeyValueStoreContracts.TryGetAsync(key);

            cancellation.ThrowIfCancellationRequested();
            var result = await this.store.TryGetAsync(key.Key, cancellation).DontMarshallContext();

            return(result.HasValue ? key.TryDeserialize(result.Value.Value) : TryValue.None <T>());
        }
        /// <inheritdoc />
        public Task RemoveAsync <T>(IValueKey <T> key, CancellationToken cancellation = default(CancellationToken))
        {
            IKeyValueStoreContracts.RemoveAsync(key);

            cancellation.ThrowIfCancellationRequested();

            var entity = new TEntity()
            {
                Key = key.Key,
            };

            return(this.store.RemoveAsync(entity));
        }
        /// <inheritdoc />
        public Task UpdateAsync <T>(
            IValueKey <T> key, T value, CancellationToken cancellation = default(CancellationToken))
        {
            IKeyValueStoreContracts.UpdateAsync(key);

            cancellation.ThrowIfCancellationRequested();

            var entity = new TEntity()
            {
                Key   = key.Key,
                Value = key.Serialize(value),
            };

            return(this.store.UpdateAsync(entity, cancellation));
        }
    public static TryValue <T> TryDeserialize <T>(this IValueKey <T> key, string value)
    {
        Contracts.Requires.That(key != null);

        T result;

        if (key.TryDeserialize(value, out result))
        {
            return(TryValue.New(result));
        }
        else
        {
            return(TryValue.None <T>());
        }
    }
    public static async Task <T> GetAsync <T>(
        this IKeyValueStore store, IValueKey <T> key, CancellationToken cancellation = default(CancellationToken))
    {
        Contracts.Requires.That(store != null);
        Contracts.Requires.That(key != null);

        var result = await store.TryGetAsync(key, cancellation).DontMarshallContext();

        if (result.HasValue)
        {
            return(result.Value);
        }
        else
        {
            throw new InvalidOperationException();
        }
    }
Exemplo n.º 7
0
 public static void RemoveAsync <T>(IValueKey <T> key)
 {
     Contracts.Requires.That(key != null);
 }
Exemplo n.º 8
0
 public static void AddOrUpdateAsync <T>(IValueKey <T> key)
 {
     Contracts.Requires.That(key != null);
 }