public static IEnumerable <CategoryEntity> GetCategoryList(string category = null) { if (_categoryList == null) { lock (_syncLockCategoryList) { if (_categoryList == null) { _categoryList = TableStorageHelper.RetrieveAllAsync <CategoryEntity>(Constants.TABLE_CATEGORY).Result; if (category != null) { return(_categoryList.Where(c => c.PartitionKey == category)); //returning here itself b/c of UpdateCategoryListCache method } else { return(_categoryList); } } } } if (category != null) { return(_categoryList.Where(c => c.PartitionKey == category)); } else { return(_categoryList); } }
public static async Task <IList <T> > RetrieveByRangeAsync <T>(string tableName, string partitionKey, string operator1, string value1, string operator2 = null, string value2 = null) where T : ITableEntity, new() { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); string condition = TableQuery.CombineFilters( TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey), TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", operator1, value1) ); if (!string.IsNullOrEmpty(operator2) || !string.IsNullOrEmpty(value2)) { condition = TableQuery.CombineFilters( condition, TableOperators.And, TableQuery.GenerateFilterCondition("RowKey", operator2, value2) ); } TableQuery <T> query = new TableQuery <T>().Where(condition); return(await ExecuteRetrieveAsync <T>(table, query)); }
public static string GetNextSequence(string partitionKey, string rowKey, string padding) { lock (_syncLock) { int nextSequence = -1; SequenceEntity entity = TableStorageHelper.RetrieveAsync <SequenceEntity>(Constants.TABLE_SEQUENCE, partitionKey, rowKey).Result; if (entity == null) { nextSequence = 1; entity = new SequenceEntity(partitionKey, rowKey); } else { nextSequence = entity.NextSequence; } entity.NextSequence = nextSequence + 1; TableStorageHelper.InsertOrMergeAsync(Constants.TABLE_SEQUENCE, entity).Wait(); if (padding != null) { return(nextSequence.ToString(padding)); } else { return(nextSequence.ToString()); } } }
public static async Task <IList <T> > RetrieveByPartitionKeyAsync <T>(string tableName, string partitionKey) where T : ITableEntity, new() { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableQuery <T> query = new TableQuery <T>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey)); return(await ExecuteRetrieveAsync <T>(table, query)); }
public static async Task <IList <T> > RetrieveAllAsync <T>(string tableName) where T : ITableEntity, new() { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableQuery <T> query = new TableQuery <T>(); return(await ExecuteRetrieveAsync <T>(table, query)); }
public static async Task DeleteAsync <T>(string tableName, T entity) where T : ITableEntity, new() { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableOperation operation = TableOperation.Delete(entity); await table.ExecuteAsync(operation); }
public static async Task MergeAsync(string tableName, ITableEntity entity) { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableOperation operation = TableOperation.Merge(entity); await table.ExecuteAsync(operation); }
public static async Task <T> RetrieveAsync <T>(string tableName, string partitionKey, string rowKey) where T : ITableEntity, new() { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableOperation retrieveOperation = TableOperation.Retrieve <T>(partitionKey, rowKey); TableResult result = await table.ExecuteAsync(retrieveOperation); return((T)result.Result); }
public static IEnumerable <UserEntity> GetUsers() { if (_users == null) { lock (_syncLockUsers) { if (_users == null) { _users = TableStorageHelper.RetrieveAllAsync <UserEntity>(Constants.TABLE_USER).Result; return(_users); //returning here itself b/c of UpdateTagListCache method } } } return(_users); }
public static IEnumerable <TagEntity> GetTagList() { if (_tagList == null) { lock (_syncLockTagList) { if (_tagList == null) { _tagList = TableStorageHelper.RetrieveAllAsync <TagEntity>(Constants.TABLE_TAG).Result; return(_tagList); //returning here itself b/c of UpdateTagListCache method } } } return(_tagList); }
public static async Task BatchAsync(string tableName, ITableEntity[] deleteEntities, ITableEntity[] insertEntities, ITableEntity[] mergeEntities) { if (((mergeEntities?.Length ?? 0) > 0) || ((insertEntities?.Length ?? 0) > 0) || ((deleteEntities?.Length ?? 0) > 0)) { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableBatchOperation batchOperation = new TableBatchOperation(); if (deleteEntities != null) { for (int i = 0; i < deleteEntities.Length; i++) { if (deleteEntities[i] != null) { batchOperation.Delete(deleteEntities[i]); } } } if (insertEntities != null) { for (int i = 0; i < insertEntities.Length; i++) { if (insertEntities[i] != null) { batchOperation.Insert(insertEntities[i]); } } } if (mergeEntities != null) { for (int i = 0; i < mergeEntities.Length; i++) { if (mergeEntities[i] != null) { batchOperation.Merge(mergeEntities[i]); } } } await table.ExecuteBatchAsync(batchOperation); } }
public static async Task InsertBatchAsync(string tableName, params ITableEntity[] insertEntities) { if (((insertEntities?.Length ?? 0) > 0)) { CloudTable table = await TableStorageHelper.GetTableReferenceAsync(tableName); TableBatchOperation batchOperation = new TableBatchOperation(); for (int i = 0; i < insertEntities.Length; i++) { if (insertEntities[i] != null) { batchOperation.Insert(insertEntities[i]); } } await table.ExecuteBatchAsync(batchOperation); } }