public async Task AddOrUpdateAsync <TKey, TValue>(TKey key, TValue value) { await CreateTableIfNotExistsAsync().ConfigureAwait(false); var entity = DictionaryTableEntity.Create(DictionaryName, key, value, _settings.Serializer, _settings.KeySerializer); await Table.ExecuteAsync(TableOperation.InsertOrReplace(entity)).ConfigureAwait(false); }
private static IDictionaryTableEntity <TKey, TValue> Resolve_String(string partitionKey, string rowKey, DateTimeOffset timestamp, IDictionary <string, EntityProperty> properties, string etag) { var entity = DictionaryTableEntity.CreateEmpty <TKey, TValue>(KumoDictionaryValueSerialization.String); entity.PartitionKey = partitionKey; entity.RowKey = rowKey; entity.Timestamp = timestamp; entity.ETag = etag; entity.ReadEntity(properties, null); return(entity); }
public async Task AddAsync <TKey, TValue>(TKey key, TValue value) { await CreateTableIfNotExistsAsync().ConfigureAwait(false); try { var entity = DictionaryTableEntity.Create(DictionaryName, key, value, _settings.Serializer, _settings.KeySerializer); var result = await Table.ExecuteAsync(TableOperation.Insert(entity)).ConfigureAwait(false); } catch (StorageException ex) { if (ex.RequestInformation.ExtendedErrorInformation.ErrorCode == TableErrorCodeStrings.EntityAlreadyExists) { throw new ArgumentException("An item with the same key has already been added.", ex); } throw; } }
public async Task <bool> RemoveAsync <TKey>(TKey key) { await CreateTableIfNotExistsAsync().ConfigureAwait(false); try { var serializedKey = _settings.KeySerializer.SerializeAsKey(_settings.Serializer, key); var tempEntity = DictionaryTableEntity.Create(DictionaryName, key, 0, _settings.Serializer, _settings.KeySerializer); tempEntity.ETag = "*"; await Table.ExecuteAsync(TableOperation.Delete(tempEntity)).ConfigureAwait(false); } catch (StorageException ex) { if (ex.RequestInformation.HttpStatusCode == 404) { return(false); } throw; } return(true); }