public static async Task <T> InsertOrModifyAsync <T>(this IAzureTableStorage <T> tableStorage, string partitionKey, string rowKey, Func <T> createNew, Func <T, T> modify) where T : class, ITableEntity, new() { for (var i = 0; i < 100; i++) { try { var result = await tableStorage.ReplaceAsync(partitionKey, rowKey, modify); if (result != null) { return(result); } result = createNew(); await tableStorage.InsertAsync(result); return(result); } catch (Exception) { } } throw new Exception("Can not insert or modify entity"); }
public static async Task <T> ModifyOrCreateAsync <T>(this IAzureTableStorage <T> tableStorage, string partitionKey, string rowKey, Func <T> create, Action <T> update) where T : ITableEntity, new() { for (var i = 0; i < 15; i++) { try { var entity = await tableStorage.ReplaceAsync(partitionKey, rowKey, itm => { update(itm); return(itm); }); if (entity != null) { return(entity); } entity = create(); await tableStorage.InsertAsync(entity); return(entity); } catch (Exception) { } } throw new Exception("Can not modify or update entity: " + PrintItem(create())); }
public async Task <string> SaveAsync(IProjectData projectData) { var newEntity = ProjectEntity.Create(projectData); await _projectsTableStorage.InsertAsync(newEntity); return(newEntity.Id); }
public static async Task <T> InsertAndGenerateRowKeyAsDateTimeAsync <T>(this IAzureTableStorage <T> table, T entity, DateTime dateTime, RowKeyDateTimeFormat rowKeyDateTimeFormat = RowKeyDateTimeFormat.Iso) where T : ITableEntity, new() { var dt = dateTime.ToString(rowKeyDateTimeFormat.ToDateTimeMask()); var no = 0; while (true) { entity.RowKey = dt + no.ToDateTimeSuffix(rowKeyDateTimeFormat); try { await table.InsertAsync(entity, Conflict); return(entity); } catch (AggregateException e) { if (e.InnerExceptions[0] is StorageException) { var se = e.InnerExceptions[0] as StorageException; if (se.RequestInformation.HttpStatusCode != Conflict) { throw; } } else { throw; } } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode != Conflict) { throw; } } if (no == 999) { throw new Exception("Can not insert record: " + PrintItem(entity)); } no++; } }
public static async Task <string> GenerateIdAsync(this IAzureTableStorage <SetupEntity> tableStorage, string partitionKey, string rowKey, int fromId) { while (true) { try { var result = await tableStorage.ReplaceAsync(partitionKey, rowKey, itm => { int i; try { i = int.Parse(itm.Value); } catch (System.Exception) { i = fromId; } itm.Value = (i + 1).ToString(CultureInfo.InvariantCulture); return(itm); }); if (result != null) { return(result.Value); } var idEntity = SetupEntity.Create(partitionKey, rowKey, fromId.ToString(CultureInfo.InvariantCulture)); await tableStorage.InsertAsync(idEntity); } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode != TableStorageUtils.Conflict) { throw; } } } }
public static async Task <T> InsertAndCheckRowKeyAsync <T>(this IAzureTableStorage <T> table, T entity, Func <string> generateRowKey) where T : ITableEntity, new() { var no = 0; while (true) { entity.RowKey = generateRowKey(); try { await table.InsertAsync(entity); return(entity); } catch (AggregateException e) { if (e.InnerExceptions[0] is StorageException) { var se = e.InnerExceptions[0] as StorageException; if (se.RequestInformation.HttpStatusCode != Conflict) { throw; } } else { throw; } } catch (StorageException e) { if (e.RequestInformation.HttpStatusCode != Conflict) { throw; } } if (no == 999) { throw new Exception("Can not insert record InsertAndCheckRowKey: " + PrintItem(entity)); } no++; } }
public async Task SaveAsync(IProjectVoteData projectVoteData) { var newEntity = ProjectVoteEntity.Create(projectVoteData); await _projectVoteTableStorage.InsertAsync(newEntity); }
public async Task SaveAsync(IWinnerData winnerData) { var newEntity = WinnerEntity.Create(winnerData); await _winnersStorage.InsertAsync(newEntity); }
public async Task SaveAsync(IProjectResultData resultData) { var newEntity = ProjectResultEntity.Create(resultData); await _projectResultInfoTableStorage.InsertAsync(newEntity); }
public async Task SaveRegisterAsync(string userId, string projectId) { var newEntity = MailSentEntity.Create("Register", userId, projectId); await _mailSentStorage.InsertAsync(newEntity); }
public async Task SaveAsync(ICommentData projectCommentData) { var newEntity = CommentEntity.Create(projectCommentData); await _projectCommentsTableStorage.InsertAsync(newEntity); }
public async Task SaveAsync(string userId, string fullName, string projectId) { var newEntity = ProjectFollowEntity.Create(userId, fullName, projectId); await _projectFollowTableStorage.InsertAsync(newEntity); }