public DataAccessResponseType CreateImageFormat(string accountNameKey, string imageGroupTypeNameKey, string imageGroupNameKey, string imageFormatName, int width, int height, bool listing, bool gallery, string requesterId, RequesterType requesterType, string sharedClientKey) { // Ensure the clients are certified. if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey) { return(null); } //Get ACCOUNT var account = AccountManager.GetAccount(accountNameKey, true, AccountManager.AccountIdentificationType.AccountName); #region Validate Request var requesterName = string.Empty; var requesterEmail = string.Empty; var requestResponseType = RequestManager.ValidateRequest(requesterId, requesterType, out requesterName, out requesterEmail, Sahara.Core.Settings.Platform.Users.Authorization.Roles.Admin, Sahara.Core.Settings.Accounts.Users.Authorization.Roles.Admin); if (!requestResponseType.isApproved) { //Request is not approved, send results: return(new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage }); } #endregion if (imageGroupNameKey == "default") { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot append new formats to the default group" }); } if (imageGroupNameKey == "main") { return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "You cannot append new formats to the main group" }); } var result = ImageFormatsManager.CreateImageFormat(account, imageGroupTypeNameKey, imageGroupNameKey, imageFormatName, width, height, listing, gallery); if (result.isSuccess) { #region Invalidate Account Capacity Cache AccountCapacityManager.InvalidateAccountCapacitiesCache(account.AccountID.ToString()); #endregion } return(result); }
public DataAccessResponseType DeleteImageFormat(string accountNameKey, string imageGroupTypeNameKey, string imageGroupNameKey, string imageFormatNameKey, string requesterId, RequesterType requesterType, string sharedClientKey) { // Ensure the clients are certified. if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey) { return(null); } //Get ACCOUNT var account = AccountManager.GetAccount(accountNameKey, true, AccountManager.AccountIdentificationType.AccountName); #region Validate Request var requesterName = string.Empty; var requesterEmail = string.Empty; var requestResponseType = RequestManager.ValidateRequest(requesterId, requesterType, out requesterName, out requesterEmail, Sahara.Core.Settings.Platform.Users.Authorization.Roles.Manager, Sahara.Core.Settings.Accounts.Users.Authorization.Roles.Manager); if (!requestResponseType.isApproved) { //Request is not approved, send results: return(new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage }); } #endregion #region Validate that no image records exist exist that use this format if (ImageRecordsManager.ImageRecordExistsForImageKey(account.AccountID.ToString(), account.StoragePartition, account.AccountNameKey, imageGroupTypeNameKey, imageGroupNameKey + "-" + imageFormatNameKey)) { //Request is not approved, send results: return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Cannot delete an image format that has any image records associated with it." }); } #endregion var result = ImageFormatsManager.DeleteImageFormat(account, imageGroupTypeNameKey, imageGroupNameKey, imageFormatNameKey); if (result.isSuccess) { #region Invalidate Account Capacity Cache AccountCapacityManager.InvalidateAccountCapacitiesCache(account.AccountID.ToString()); #endregion } return(result); }
public static DataAccessResponseType ProcessSendApplicationDataInjectionImageDocuments(string accountId, int documentInjectionCount) { var result = new DataAccessResponseType { isSuccess = false }; //Get the account var account = AccountManager.GetAccount(accountId); //Create base document var imageDocument = new ApplicationImageDocumentModel { AccountID = accountId, DocumentType = "ApplicationImage", Title = "Generic Application Image Document", Description = "Generic description for batch injected document. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." }; //Get the DocumentDB Client //var client = Sahara.Core.Settings.Azure.DocumentDB.DocumentClients.AccountDocumentClient; //var dbSelfLink = Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseSelfLink; //Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.OpenAsync(); //Build a collection Uri out of the known IDs //(These helpers allow you to properly generate the following URI format for Document DB: //"dbs/{xxx}/colls/{xxx}/docs/{xxx}" Uri collectionUri = UriFactory.CreateDocumentCollectionUri(Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId, account.DocumentPartition); string triggerId = "IncrementApplicationImageCount"; var requestOptions = new RequestOptions { PostTriggerInclude = new List <string> { triggerId } }; int documentsInjected = 0; //int retryAttempts = 0; //int maxAttemptsPerRetry = 0; //<-- Used to track max retries per attempt // Create new stopwatch Stopwatch stopwatch = new Stopwatch(); // Begin timing tasks stopwatch.Start(); //var retryStrategy = new DocumentDbRetryStrategy{ FastFirstRetry = true }; //DocumentDbRetryStrategy.F do { imageDocument.Id = Guid.NewGuid().ToString(); var createDocumentResponse = Sahara.Core.Settings.Azure.DocumentDbClients.AccountDocumentClient.CreateDocumentAsync(collectionUri.ToString(), imageDocument, requestOptions).Result; documentsInjected++; //<--Increment amount of documents that have been injected try { AccountCapacityManager.InvalidateAccountCapacitiesCache(accountId); //<--Invalidate Account Capacities Cache } catch { } }while (documentsInjected != documentInjectionCount); if (documentsInjected == documentInjectionCount) { result.isSuccess = true; } stopwatch.Stop(); //Output timing into data injection log PlatformLogManager.LogActivity( CategoryType.DataInjection, ActivityType.DataInjection_ImageDocuments, "Batch Injection complete! " + documentsInjected + " of " + documentInjectionCount + " documents injected", "Time: " + stopwatch.ElapsedMilliseconds + " Milliseconds( " + String.Format("{0:0,0.00}", TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds).TotalMinutes) + " Minutes)", // | Retries: " + retryAttempts + " | Max Attempts Per Retry: " + maxAttemptsPerRetry, accountId ); return(result); }
public DataAccessResponseType CreateTag(string accountId, string tagName, string requesterId, RequesterType requesterType, string sharedClientKey) { // Ensure the clients are certified. if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey) { return(null); } //Get ACCOUNT var account = AccountManager.GetAccount(accountId, true, AccountManager.AccountIdentificationType.AccountID); #region Validate Request var requesterName = string.Empty; var requesterEmail = string.Empty; var requestResponseType = RequestManager.ValidateRequest(requesterId, requesterType, out requesterName, out requesterEmail, Sahara.Core.Settings.Platform.Users.Authorization.Roles.Manager, Sahara.Core.Settings.Accounts.Users.Authorization.Roles.Manager); if (!requestResponseType.isApproved) { //Request is not approved, send results: return(new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage }); } #endregion #region Validate Plan Capabilities //Verify that current tag count is below maximum allowed by this plan if (TagManager.GetTagCount(account.AccountNameKey) >= account.PaymentPlan.MaxTags) { //Log Limitation Issues (or send email) so that Platform Admins can immediatly contact Accounts that have hit their limits an upsell themm Sahara.Core.Logging.PlatformLogs.Helpers.PlatformLimitationsHelper.LogLimitationAndAlertAdmins("tags", account.AccountID.ToString(), account.AccountName); return(new DataAccessResponseType { isSuccess = false, ErrorMessage = "Your account plan does not allow for more than " + account.PaymentPlan.MaxTags + " tags, please update your plan to add more." }); } #endregion var result = TagManager.CreateTag(account, tagName); #region Log Account Activity if (result.isSuccess) { try { //Object Log --------------------------- AccountLogManager.LogActivity( accountId, account.StoragePartition, CategoryType.Inventory, ActivityType.Inventory_TagCreated, "Tag '" + tagName + "' created", requesterName + " created '" + tagName + "' tag", requesterId, requesterName, requesterEmail, null, null, result.SuccessMessage); } catch { } } #endregion #region Invalidate Account Capacity Cache AccountCapacityManager.InvalidateAccountCapacitiesCache(accountId); #endregion #region Invalidate Account API Caching Layer Sahara.Core.Common.Redis.ApiRedisLayer.InvalidateAccountApiCacheLayer(account.AccountNameKey); #endregion return(result); }
public DataAccessResponseType DeleteTag(string accountId, string tagName, string requesterId, RequesterType requesterType, string sharedClientKey) { // Ensure the clients are certified. if (sharedClientKey != Sahara.Core.Platform.Requests.RequestManager.SharedClientKey) { return(null); } //Get ACCOUNT var account = AccountManager.GetAccount(accountId, true, AccountManager.AccountIdentificationType.AccountID); #region Validate Request var requesterName = string.Empty; var requesterEmail = string.Empty; var requestResponseType = RequestManager.ValidateRequest(requesterId, requesterType, out requesterName, out requesterEmail, Sahara.Core.Settings.Platform.Users.Authorization.Roles.Manager, Sahara.Core.Settings.Accounts.Users.Authorization.Roles.Manager); if (!requestResponseType.isApproved) { //Request is not approved, send results: return(new DataAccessResponseType { isSuccess = false, ErrorMessage = requestResponseType.requestMessage }); } #endregion var result = TagManager.DeleteTag(account, tagName); #region Log Account Activity if (result.isSuccess) { try { //Object Log --------------------------- AccountLogManager.LogActivity( accountId, account.StoragePartition, CategoryType.Inventory, ActivityType.Inventory_TagDeleted, "Tag '" + tagName + "' deleted", requesterName + " deleted the '" + tagName + "' tag", requesterId, requesterName, requesterEmail, null, null, result.SuccessMessage); } catch { } } #endregion #region Invalidate Account Capacity Cache AccountCapacityManager.InvalidateAccountCapacitiesCache(accountId); #endregion #region Invalidate Account API Caching Layer Sahara.Core.Common.Redis.ApiRedisLayer.InvalidateAccountApiCacheLayer(account.AccountNameKey); #endregion return(result); }