internal static DataAccessResponseType StoreTag(TagTableEntity tagEntity, string storagePartition) { var response = new DataAccessResponseType(); //CloudTableClient cloudTableClient = Settings.Azure.Storage.StorageConnections.AccountsStorage.CreateCloudTableClient(); CloudTableClient cloudTableClient = Settings.Azure.Storage.GetStoragePartitionAccount(storagePartition).CreateCloudTableClient(); //Create and set retry policy //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4); cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy; TableOperation operation = TableOperation.Insert((tagEntity as TableEntity)); try { var tableResult = tagEntity.cloudTable.Execute(operation); response.isSuccess = true; //tableResult.; } catch { response.isSuccess = false; //tableResult.; response.ErrorMessage = "Tag exists"; } return(response); }
public void Read_NotThrowsException_StateIsValid() { var tagKey = new TagTableEntity { TagId = Guid.Parse("00000000-5001-0000-0000-000000000000"), }; var tagRepository = new TagRepository(TestEnvironment.DBSettings); var tag = tagRepository.Read(tagKey); Assert.IsNotNull(tag); }
public void Update_NotThrowsException_StateIsValid() { var tagKey = new TagTableEntity { TagId = Guid.Parse("00000000-5001-0000-0000-000000000000"), }; var tagRepository = new TagRepository(TestEnvironment.DBSettings); var tag = tagRepository.Read(tagKey); tag.CreateTime = DateUtil.Now; Assert.IsTrue(tagRepository.Update(tag)); }
public void Delete_NotThrowsException_StateIsValid() { var tag = new TagTableEntity { TagId = Guid.NewGuid(), TargetId = Guid.NewGuid(), TargetTable = new string('X', 100), Value = new string('X', 100), CreateTime = DateTimeOffset.MaxValue, }; var tagRepository = new TagRepository(TestEnvironment.DBSettings); tagRepository.Create(tag); Assert.IsTrue(tagRepository.Delete(tag)); }
public static DataAccessResponseType CreateTag(Account account, string tagName) { #region Convert multiple spaces with single tagName = Regex.Replace(tagName, @"\s+", " "); #endregion #region Validate Tag Name: ValidationResponseType ojectNameValidationResponse = ValidationManager.IsValidTagName(tagName); if (!ojectNameValidationResponse.isValid) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = ojectNameValidationResponse.validationMessage }); } #endregion #region validate tag does not exist var tags = GetTags(account.AccountNameKey); foreach (string tag in tags) { if (tag.ToLower() == tagName.ToLower()) { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "A tag with that name already exists." }); } } #endregion var tagEntity = new TagTableEntity(account.AccountID.ToString(), account.StoragePartition, tagName); var response = Internal.StoreTag(tagEntity, account.StoragePartition); if (response.isSuccess) { Caching.InvalidateTagsCache(account.AccountNameKey); } return(response); }
internal static DataAccessResponseType DeleteTag(Account account, string tagName) { var response = new DataAccessResponseType(); //CloudTableClient cloudTableClient = Sahara.Core.Settings.Azure.Storage.StorageConnections.AccountsStorage.CreateCloudTableClient(); CloudTableClient cloudTableClient = Settings.Azure.Storage.GetStoragePartitionAccount(account.StoragePartition).CreateCloudTableClient(); //Create and set retry policy //IRetryPolicy exponentialRetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(1), 4); IRetryPolicy linearRetryPolicy = new LinearRetry(TimeSpan.FromSeconds(1), 4); cloudTableClient.DefaultRequestOptions.RetryPolicy = linearRetryPolicy; CloudTable cloudTable = cloudTableClient.GetTableReference(Sahara.Core.Common.Methods.SchemaNames.AccountIdToTableStorageName(account.AccountID.ToString()) + TagsTableName); cloudTable.CreateIfNotExists(); try { TagTableEntity tagEntity = cloudTable.CreateQuery <TagTableEntity>().Where(t => t.PartitionKey == tagName).FirstOrDefault(); TableResult deleteResult = cloudTable.Execute(TableOperation.Delete(tagEntity)); response.isSuccess = true; } catch (Exception e) { PlatformLogManager.LogActivity( CategoryType.Error, ActivityType.Error_Exception, e.Message, "Exception while attempting to delete tag '" + tagName + "'", account.AccountID.ToString(), account.AccountName, null, null, null, null, System.Reflection.MethodBase.GetCurrentMethod().ToString(), null ); } return(response); }