public virtual async Task DeleteAsync(T item) { try { await GetTable().ExecuteAsync(TableOperation.Delete(item)); } catch (Exception ex) { _log?.WriteFatalError("Table storage: " + _tableName, "Delete item", TableStorageUtils.PrintItem(item), ex).Wait(); throw; } }
private void HandleException(T item, Exception ex, IEnumerable <int> notLogCodes) { var storageException = ex as StorageException; if (storageException != null) { if (!storageException.HandleStorageException(notLogCodes)) { // Если этот эксепшн не обработан, то логируем его _log?.WriteFatalError("Table storage: " + _tableName, "Insert item", TableStorageUtils.PrintItem(item), ex); } } else { _log?.WriteFatalError("Table storage: " + _tableName, "Insert item", TableStorageUtils.PrintItem(item), ex); } }
private async Task ExecuteQueryAsync(string processName, TableQuery <T> rangeQuery, Func <T, bool> filter, Func <IEnumerable <T>, Task> yieldData) { try { TableContinuationToken tableContinuationToken = null; var table = GetTable(); do { var queryResponse = await table.ExecuteQuerySegmentedAsync(rangeQuery, tableContinuationToken); tableContinuationToken = queryResponse.ContinuationToken; await yieldData(TableStorageUtils.ApplyFilter(queryResponse.Results, filter)); }while (tableContinuationToken != null); } catch (Exception ex) { _log?.WriteFatalError("Table storage: " + _tableName, processName, rangeQuery.FilterString ?? "[null]", ex).Wait(); throw; } }
public async Task <T> MergeAsync(string partitionKey, string rowKey, Func <T, T> mergeAction) { object itm = "Not read"; try { while (true) { try { var entity = await GetDataAsync(partitionKey, rowKey); if (entity != null) { var result = mergeAction(entity); itm = result; if (result != null) { await GetTable().ExecuteAsync(TableOperation.Merge(result)); } return(result); } return(null); } catch (StorageException e) { // Если поймали precondition fall = 412, значит в другом потоке данную сущность успели поменять // - нужно повторить операцию, пока не исполнится без ошибок if (e.RequestInformation.HttpStatusCode != 412) { throw; } } } } catch (Exception ex) { _log?.WriteFatalError("Table storage: " + _tableName, "Replace item", TableStorageUtils.PrintItem(itm), ex).Wait(); throw; } }
public async Task InsertOrMergeAsync(T item) { try { await GetTable().ExecuteAsync(TableOperation.InsertOrMerge(item)); } catch (Exception ex) { if (_log != null) { await _log.WriteFatalError("Table storage: " + _tableName, "InsertOrMerge item", TableStorageUtils.PrintItem(item), ex); } } }