public Task InsertOrReplaceAsync(IHistoryOperation historyOperation)
        {
            var entity = new HistoryOperationEntity(historyOperation);

            var tasks = new List <Task>();

            tasks.Add(_storage.InsertOrReplaceAsync(entity));

            AzureIndex indexById = IndexById.Create(entity);

            tasks.Add(_indexById.InsertOrReplaceAsync(indexById));

            if (!string.IsNullOrEmpty(historyOperation.InvoiceId))
            {
                AzureIndex indexByInvoice = IndexByInvoice.Create(entity);
                tasks.Add(_indexByInvoice.InsertOrReplaceAsync(indexByInvoice));
            }

            return(Task.WhenAll(tasks));
        }
        public async Task SetTxHashAsync(string id, string txHash)
        {
            AzureIndex index =
                await _indexById.GetDataAsync(IndexById.GeneratePartitionKey(id), IndexById.GenerateRowKey());

            if (index == null)
            {
                throw new HistoryOperationNotFoundException(id);
            }

            HistoryOperationEntity updated = await _storage.MergeAsync(
                index.PrimaryPartitionKey, index.PrimaryRowKey,
                o =>
            {
                o.TxHash = txHash;
                return(o);
            });

            if (updated == null)
            {
                throw new HistoryOperationNotFoundException(id);
            }
        }
Exemplo n.º 3
0
 internal static AzureIndex Create(HistoryOperationEntity entity)
 {
     return(AzureIndex.Create(GeneratePartitionKey(entity.InvoiceId),
                              GenerateRowKey(entity.CreatedOn, entity.Id), entity));
 }