Example #1
0
        public async Task WriteAsync(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            using (await _cc.WriteAsync().ConfigureAwait(false))
            {
                await CreateDatabase().ConfigureAwait(false);

                await _client.WriteAsync(_database, Convert( series )).ConfigureAwait(false);
            }
        }
Example #2
0
        private async Task ExecuteBatchOperation(TableBatchOperation operation)
        {
            using (await _cc.WriteAsync().ConfigureAwait(false))
            {
                var table = await GetTable();

                await table.ExecuteBatchAsync(operation).ConfigureAwait(false);
            }
        }
Example #3
0
        private async Task StoreForAll(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            await CreateTable().ConfigureAwait(false);

            using (await _cc.WriteAsync().ConfigureAwait(false))
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    await connection.OpenAsync().ConfigureAwait(false);

                    var keys = new HashSet <EntryKey <TKey> >();

                    List <SqlDataRecord> records = new List <SqlDataRecord>();
                    foreach (var serie in series)
                    {
                        var key = serie.GetKey();
                        SqlSerializer.Serialize <TKey, TEntry>(serie.GetEntries(), (entry, data) =>
                        {
                            var timestamp = entry.GetTimestamp();
                            var hashkey   = new EntryKey <TKey>(key, timestamp);

                            if (!keys.Contains(hashkey))
                            {
                                SqlDataRecord record = new SqlDataRecord(Sql.InsertParameterMetadata);
                                record.SetString(0, _keyConverter.Convert(key));
                                record.SetDateTime(1, timestamp);
                                record.SetSqlBinary(2, new SqlBinary(data));
                                records.Add(record);

                                keys.Add(hashkey);
                            }
                        });
                    }

                    if (records.Count > 0)
                    {
                        using (var tx = connection.BeginTransaction(IsolationLevel.ReadCommitted))
                        {
                            using (var command = connection.CreateCommand())
                            {
                                command.CommandText = Sql.GetInsertProcedureName(_tableName);
                                command.CommandType = CommandType.StoredProcedure;
                                command.Transaction = tx;
                                var parameter = command.Parameters.AddWithValue("@Inserts", records);
                                parameter.SqlDbType = SqlDbType.Structured;
                                parameter.TypeName  = Sql.GetInsertParameterType(_tableName);

                                await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                            }

                            tx.Commit();
                        }
                    }
                }
            }
        }
Example #4
0
        public async Task WriteAsync(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            using (await _cc.WriteAsync().ConfigureAwait(false))
            {
                series = series.ToList(); // ensure we only iterate once
                var keys = await _typeStorage.GetTaggedKeysOrThrowAsync(series.Select(x => x.GetKey())).ConfigureAwait(false);

                var keyDictionary = keys.ToDictionary(x => x.Key);

                await CreateDatabase().ConfigureAwait(false);

                await _client.WriteAsync(_database, Convert( series, keyDictionary )).ConfigureAwait(false);
            }
        }