Exemplo n.º 1
0
        protected T Inflate <T>(BigRow.Sample r)
        {
            var cache = ReflectionCache.For <T>();
            var row   = DataClient.Value.GetRowsAsync(cache.TableName, r.Key, rowLimit: 1, encoding: cache.TableEncoding).Result.ToArray();

            return(row.Any() ? Inflate <T>(row.First()) : default(T));
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <T> > SampleAsync <T>(CancellationToken cancellationToken = default(CancellationToken))
        {
            var cache = ReflectionCache.For <T>();
            var table = LocateTable <T>(cache);
            var rows  = await DataClient.Value.SampleRowKeysAsync(table, cancellationToken);

            return(rows.AsParallel().Select(Inflate <T>).ToArray());
        }
Exemplo n.º 3
0
 public async Task UpdateAsync <T>(T instance, CancellationToken cancellationToken = default(CancellationToken))
 {
     var cache   = ReflectionCache.For <T>();
     var table   = LocateTable <T>(cache);
     var key     = ExtractKey(cache, instance);
     var changes = ExtractChanges(cache, instance);
     await DataClient.Value.WriteRowAsync(table, key, changes, cancellationToken);
 }
Exemplo n.º 4
0
        public async Task <T> GetAsync <T>(T prototype, CancellationToken cancellationToken = default(CancellationToken))
        {
            var cache = ReflectionCache.For <T>();
            var table = LocateTable <T>(cache);
            var key   = ExtractKey(cache, prototype);
            var row   = await DataClient.Value.GetRowAsync(table, key, cancellationToken);

            return(Inflate(row, prototype));
        }
Exemplo n.º 5
0
        public async Task <T> GetFirstRowAsync <T>(CancellationToken cancellationToken = default(CancellationToken))
        {
            var cache    = ReflectionCache.For <T>();
            var table    = LocateTable <T>(cache);
            var emptyKey = new byte[] { };
            var result   = await DataClient.Value.GetRowsAsync(table, emptyKey, emptyKey, 1, cancellationToken);

            return(result.Select(Inflate <T>).FirstOrDefault());
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <T> > ScanAsync <T>(T start = default(T), T end = default(T), int rowLimit = 0, CancellationToken cancellationToken = default(CancellationToken))
        {
            var cache    = ReflectionCache.For <T>();
            var table    = LocateTable <T>(cache);
            var startKey = ExtractKey(cache, start);
            var endKey   = ExtractKey(cache, end);
            var rows     = await DataClient.Value.GetRowsAsync(table, startKey, endKey, rowLimit, cancellationToken);

            return(rows.AsParallel().Select(Inflate <T>).ToArray());
        }
Exemplo n.º 7
0
        public async Task <IEnumerable <BigRow> > AppendFieldAsync <T, TParameter>(T instance, Expression <Func <T, TParameter> > field, byte[] value, CancellationToken cancellationToken = default(CancellationToken))
            where TParameter : IBigTableField
        {
            var cache = ReflectionCache.For <T>();
            var table = LocateTable <T>(cache);
            var key   = ExtractKey(cache, instance);
            var rule  = CreateAppendRule(cache, table, field, value);

            return(await DataClient.Value.WriteRowAsync(table, key, cancellationToken, new[] { rule }));
        }
Exemplo n.º 8
0
        public IObservable <T> ObservableUnsortedScan <T>(T start = default(T), T end = default(T))
            where T : class
        {
            var cache      = ReflectionCache.For <T>();
            var table      = LocateTable <T>(cache);
            var startKey   = ExtractKey(cache, start);
            var endKey     = ExtractKey(cache, end);
            var observable = DataClient.Value.ObserveUnsortedRows(table, startKey, endKey);

            return(observable.Select(Inflate <T>));
        }
Exemplo n.º 9
0
        public async Task <bool> TableExists <T>()
        {
            var cache = ReflectionCache.For <T>();
            var table = await AdminClient.Value.GetTableAsync(cache.TableName);

            if (table != null)
            {
                cache.Adjunct(() => table);
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public async Task <bool> UpdateWhenAsync <T>(T instance, Expression <Func <T, bool> > predicate, Expression <Func <T, object> > whenTrue = null, Expression <Func <T, object> > whenFalse = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (whenTrue == null && whenFalse == null)
            {
                throw new ArgumentNullException("whenTrue", "Must set whenTrue or whenFalse to perform and UpdateWhen");
            }
            var cache     = ReflectionCache.For <T>();
            var table     = LocateTable <T>(cache);
            var key       = ExtractKey(cache, instance);
            var filter    = ExtractFilter(predicate);
            var trueCase  = ExtractMutateWhen(whenTrue);
            var falseCase = ExtractMutateWhen(whenFalse);

            return(await DataClient.Value.WriteWhenAsync(table, key, filter, trueCase, falseCase, cancellationToken));
        }
Exemplo n.º 11
0
 protected T Inflate <T>(BigRow row)
 {
     return((T)ReflectionCache.For <T>().CreateInstance(row.Key, row.GetValues));
 }
Exemplo n.º 12
0
 protected T Inflate <T>(BigRow row, T prototype)
 {
     return((T)ReflectionCache.For <T>().PopulateInstance(row.Key, row.GetValues, prototype));
 }