diff --git a/Contentstack.Management.Core.Unit.Tests/Utils/CSConstantsTest.cs b/Contentstack.Management.Core.Unit.Tests/Utils/CSConstantsTest.cs index 969e213..24bd5a5 100644 --- a/Contentstack.Management.Core.Unit.Tests/Utils/CSConstantsTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Utils/CSConstantsTest.cs @@ -30,9 +30,9 @@ public void Test_CSConstants_InternalConstants() public void Test_CSConstants_InternalMessages() { Assert.AreEqual("You are already logged in.", CSConstants.YouAreLoggedIn); - Assert.AreEqual("You are need to login.", CSConstants.YouAreNotLoggedIn); - Assert.AreEqual("Uid should not be empty.", CSConstants.MissingUID); - Assert.AreEqual("API Key should not be empty.", CSConstants.MissingAPIKey); + Assert.AreEqual("You are not logged in. Log in and try again.", CSConstants.YouAreNotLoggedIn); + Assert.AreEqual("UID is required. Provide a valid UID and try again.", CSConstants.MissingUID); + Assert.AreEqual("API Key is required. Provide a valid API Key and try again.", CSConstants.MissingAPIKey); Assert.AreEqual("API Key should be empty.", CSConstants.APIKey); Assert.AreEqual("Please enter email id to remove from org.", CSConstants.RemoveUserEmailError); Assert.AreEqual("Please enter share uid to resend invitation.", CSConstants.OrgShareUIDMissing); diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index a8929b4..0dd13d0 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -485,7 +485,7 @@ public Task LogoutAsync(string authtoken = null) public OAuthHandler OAuth(OAuthOptions options) { if (options == null) - throw new ArgumentNullException(nameof(options), "OAuth options cannot be null."); + throw new ArgumentNullException(nameof(options), CSConstants.OAuthOptionsRequired); return new OAuthHandler(this, options); } @@ -519,10 +519,10 @@ public OAuthHandler OAuth() internal void SetOAuthTokens(OAuthTokens tokens) { if (tokens == null) - throw new ArgumentNullException(nameof(tokens), "OAuth tokens cannot be null."); + throw new ArgumentNullException(nameof(tokens), CSConstants.OAuthTokensRequired); if (string.IsNullOrEmpty(tokens.AccessToken)) - throw new ArgumentException("Access token cannot be null or empty.", nameof(tokens)); + throw new ArgumentException(CSConstants.AccessTokenRequired, nameof(tokens)); // Store the access token in the client options for use in HTTP requests // This will be used by the HTTP pipeline to inject the Bearer token @@ -541,7 +541,7 @@ internal void SetOAuthTokens(OAuthTokens tokens) public OAuthTokens GetOAuthTokens(string clientId) { if (string.IsNullOrEmpty(clientId)) - throw new ArgumentException("Client ID cannot be null or empty.", nameof(clientId)); + throw new ArgumentException(CSConstants.ClientIDRequired, nameof(clientId)); return GetStoredOAuthTokens(clientId); } @@ -607,7 +607,7 @@ public void ClearOAuthTokens(string clientId = null) internal void StoreOAuthTokens(string clientId, OAuthTokens tokens) { if (string.IsNullOrEmpty(clientId)) - throw new ArgumentException("Client ID cannot be null or empty.", nameof(clientId)); + throw new ArgumentException(CSConstants.ClientIDRequired, nameof(clientId)); if (tokens == null) throw new ArgumentNullException(nameof(tokens)); diff --git a/Contentstack.Management.Core/Models/Asset.cs b/Contentstack.Management.Core/Models/Asset.cs index 738b842..ad7ac23 100644 --- a/Contentstack.Management.Core/Models/Asset.cs +++ b/Contentstack.Management.Core/Models/Asset.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -359,7 +360,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.AssetAlreadyExists); } } @@ -367,7 +368,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.AssetUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/AssetModel.cs b/Contentstack.Management.Core/Models/AssetModel.cs index 0bdc52d..bc96b09 100644 --- a/Contentstack.Management.Core/Models/AssetModel.cs +++ b/Contentstack.Management.Core/Models/AssetModel.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net.Http; using Contentstack.Management.Core.Abstractions; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -29,11 +30,11 @@ public AssetModel(string fileName, ByteArrayContent byteArray, string contentTyp { if (fileName == null) { - throw new ArgumentNullException("fileName", "File name can not be null."); + throw new ArgumentNullException("fileName", CSConstants.FileNameRequired); } if (byteArray == null) { - throw new ArgumentNullException("byteArray", "Uploading content can not be null."); + throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired); } FileName = fileName; Title = title; diff --git a/Contentstack.Management.Core/Models/AuditLog.cs b/Contentstack.Management.Core/Models/AuditLog.cs index 9d24b54..1e2d082 100644 --- a/Contentstack.Management.Core/Models/AuditLog.cs +++ b/Contentstack.Management.Core/Models/AuditLog.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -107,7 +108,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedOnAuditLogs); } } @@ -115,7 +116,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.AuditLogUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/BaseModel.cs b/Contentstack.Management.Core/Models/BaseModel.cs index 52d94e1..cf55da2 100644 --- a/Contentstack.Management.Core/Models/BaseModel.cs +++ b/Contentstack.Management.Core/Models/BaseModel.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -19,7 +20,7 @@ public BaseModel(Stack stack, string fieldName, string uid = null) stack.ThrowIfAPIKeyEmpty(); if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Field name mandatory for service"); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.stack = stack; this.fieldName = fieldName; @@ -105,7 +106,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedOnModel); } } @@ -113,7 +114,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.MissingUID); } } #endregion diff --git a/Contentstack.Management.Core/Models/CustomExtension/CustomFieldModel.cs b/Contentstack.Management.Core/Models/CustomExtension/CustomFieldModel.cs index ac269b4..e39c5fe 100644 --- a/Contentstack.Management.Core/Models/CustomExtension/CustomFieldModel.cs +++ b/Contentstack.Management.Core/Models/CustomExtension/CustomFieldModel.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net.Http; using Contentstack.Management.Core.Abstractions; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models.CustomExtension { @@ -32,11 +33,11 @@ public CustomFieldModel(ByteArrayContent byteArray, string contentType, string t if (byteArray == null) { - throw new ArgumentNullException("byteArray", "Uploading content can not be null."); + throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired); } if (title == null) { - throw new ArgumentNullException("title", "Title for widget is required."); + throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired); } Title = title; DataType = dataType; diff --git a/Contentstack.Management.Core/Models/CustomExtension/CustomWidgetModel.cs b/Contentstack.Management.Core/Models/CustomExtension/CustomWidgetModel.cs index ca9074a..6b6753f 100644 --- a/Contentstack.Management.Core/Models/CustomExtension/CustomWidgetModel.cs +++ b/Contentstack.Management.Core/Models/CustomExtension/CustomWidgetModel.cs @@ -4,6 +4,7 @@ using System.Net.Http; using System.Net.Http.Headers; using Contentstack.Management.Core.Abstractions; +using Contentstack.Management.Core.Utils; using Newtonsoft.Json; namespace Contentstack.Management.Core.Models.CustomExtension @@ -33,11 +34,11 @@ public CustomWidgetModel(ByteArrayContent byteArray, string contentType, string { if (byteArray == null) { - throw new ArgumentNullException("byteArray", "Uploading content can not be null."); + throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired); } if (title == null) { - throw new ArgumentNullException("title", "Title for widget is required."); + throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired); } Title = title; Tags = tags; diff --git a/Contentstack.Management.Core/Models/CustomExtension/DashboardWidgetModel.cs b/Contentstack.Management.Core/Models/CustomExtension/DashboardWidgetModel.cs index 57d5894..b75c43b 100644 --- a/Contentstack.Management.Core/Models/CustomExtension/DashboardWidgetModel.cs +++ b/Contentstack.Management.Core/Models/CustomExtension/DashboardWidgetModel.cs @@ -2,6 +2,7 @@ using System.IO; using System.Net.Http; using Contentstack.Management.Core.Abstractions; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models.CustomExtension { @@ -32,11 +33,11 @@ public DashboardWidgetModel(ByteArrayContent byteArray, string contentType, stri if (byteArray == null) { - throw new ArgumentNullException("byteArray", "Uploading content can not be null."); + throw new ArgumentNullException("byteArray", CSConstants.UploadContentRequired); } if (title == null) { - throw new ArgumentNullException("title", "Title for widget is required."); + throw new ArgumentNullException("title", CSConstants.WidgetTitleRequired); } Title = title; Tags = tags; diff --git a/Contentstack.Management.Core/Models/Extension.cs b/Contentstack.Management.Core/Models/Extension.cs index d9c51e3..7364ebf 100644 --- a/Contentstack.Management.Core/Models/Extension.cs +++ b/Contentstack.Management.Core/Models/Extension.cs @@ -3,6 +3,7 @@ using Contentstack.Management.Core.Abstractions; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -246,7 +247,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedOnExtension); } } @@ -254,7 +255,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.ExtensionUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/Folder.cs b/Contentstack.Management.Core/Models/Folder.cs index 08de139..81fce4b 100644 --- a/Contentstack.Management.Core/Models/Folder.cs +++ b/Contentstack.Management.Core/Models/Folder.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -190,7 +191,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedOnFolder); } } @@ -198,7 +199,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.FolderUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/Organization.cs b/Contentstack.Management.Core/Models/Organization.cs index a132db6..db5a540 100644 --- a/Contentstack.Management.Core/Models/Organization.cs +++ b/Contentstack.Management.Core/Models/Organization.cs @@ -215,7 +215,7 @@ public ContentstackResponse RemoveUser(List emails) this.ThrowIfOrganizationUidNull(); if (emails == null) { - throw new ArgumentNullException("emails"); + throw new ArgumentNullException("emails", CSConstants.EmailsRequired); } var userInviteService = new UserInvitationService(_client.serializer, this.Uid, "DELETE"); userInviteService.RemoveUsers(emails); @@ -240,7 +240,7 @@ public Task RemoveUserAsync(List emails) this.ThrowIfOrganizationUidNull(); if (emails == null) { - throw new ArgumentNullException("emails"); + throw new ArgumentNullException("emails", CSConstants.EmailsRequired); } var userInviteService = new UserInvitationService(_client.serializer, this.Uid, "DELETE"); userInviteService.RemoveUsers(emails); @@ -429,7 +429,7 @@ private void ThrowIfOrganizationUidNull() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException(CSConstants.MissingUID); + throw new InvalidOperationException(CSConstants.OrganizationUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/PublishQueue.cs b/Contentstack.Management.Core/Models/PublishQueue.cs index 984950c..19157be 100644 --- a/Contentstack.Management.Core/Models/PublishQueue.cs +++ b/Contentstack.Management.Core/Models/PublishQueue.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -151,7 +152,7 @@ internal void ThrowIfUidNotEmpty() { if (!string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedOnPublishQueue); } } @@ -159,7 +160,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.Uid)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.PublishQueueUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/Release.cs b/Contentstack.Management.Core/Models/Release.cs index 03b555f..0a3662f 100644 --- a/Contentstack.Management.Core/Models/Release.cs +++ b/Contentstack.Management.Core/Models/Release.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -236,7 +237,7 @@ public ContentstackResponse Clone(string name, string description) { if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException("name", "Invalide name."); + throw new ArgumentNullException("name", CSConstants.ReleaseNameInvalid); } stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -267,7 +268,7 @@ public Task CloneAsync(string name, string description) { if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException("name", "Invalide name."); + throw new ArgumentNullException("name", CSConstants.ReleaseNameInvalid); } stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); diff --git a/Contentstack.Management.Core/Models/ReleaseItem.cs b/Contentstack.Management.Core/Models/ReleaseItem.cs index eea1654..a5b1c81 100644 --- a/Contentstack.Management.Core/Models/ReleaseItem.cs +++ b/Contentstack.Management.Core/Models/ReleaseItem.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -258,7 +259,7 @@ internal void ThrowIfUidEmpty() { if (string.IsNullOrEmpty(this.releaseUID)) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.ReleaseItemUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/Stack.cs b/Contentstack.Management.Core/Models/Stack.cs index 3d259af..2fbad64 100644 --- a/Contentstack.Management.Core/Models/Stack.cs +++ b/Contentstack.Management.Core/Models/Stack.cs @@ -435,7 +435,7 @@ public ContentstackResponse AddSettings(StackSettings settings) ThrowIfAPIKeyEmpty(); if (settings == null) { - throw new ArgumentNullException("settings", "Settings can not be null."); + throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired); } var service = new StackSettingsService(client.serializer, this, "POST", settings); @@ -460,7 +460,7 @@ public Task AddSettingsAsync(StackSettings settings) ThrowIfAPIKeyEmpty(); if (settings == null) { - throw new ArgumentNullException("settings", "Settings can not be null."); + throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired); } var service = new StackSettingsService(client.serializer, this, "POST", settings); @@ -489,7 +489,7 @@ public ContentstackResponse Share(List invitations) ThrowIfAPIKeyEmpty(); if (invitations == null) { - throw new ArgumentNullException("invitations", "Invitations can not be null."); + throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired); } var service = new StackShareService(client.serializer, this); @@ -520,7 +520,7 @@ public Task ShareAsync(List invitations) ThrowIfAPIKeyEmpty(); if (invitations == null) { - throw new ArgumentNullException("invitations", "Invitations can not be null."); + throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired); } var service = new StackShareService(client.serializer, this); @@ -546,7 +546,7 @@ public ContentstackResponse UnShare(string email) ThrowIfAPIKeyEmpty(); if (email == null) { - throw new ArgumentNullException("email", "Email can not be null."); + throw new ArgumentNullException("email", CSConstants.EmailRequired); } var service = new StackShareService(client.serializer, this); @@ -573,7 +573,7 @@ public Task UnShareAsync(string email) ThrowIfAPIKeyEmpty(); if (email == null) { - throw new ArgumentNullException("email", "Email can not be null."); + throw new ArgumentNullException("email", CSConstants.EmailRequired); } var service = new StackShareService(client.serializer, this); @@ -941,7 +941,7 @@ internal void ThrowIfAPIKeyNotEmpty() { if (!string.IsNullOrEmpty(this.APIKey)) { - throw new InvalidOperationException(CSConstants.APIKey); + throw new InvalidOperationException(CSConstants.InvalidAPIKey); } } @@ -956,7 +956,7 @@ internal void ThrowInvalideName(string name) { if (string.IsNullOrEmpty(name)) { - throw new ArgumentNullException("name", "Invalide name for the Stack."); + throw new ArgumentNullException("name", CSConstants.StackNameInvalid); } } @@ -964,7 +964,7 @@ internal void ThrowInvalideLocale(string locale) { if (string.IsNullOrEmpty(locale)) { - throw new ArgumentNullException("locale", "Invalide name for the Stack."); + throw new ArgumentNullException("locale", CSConstants.LocaleInvalid); } } @@ -972,7 +972,7 @@ internal void ThrowInvalideOrganizationUid(string uid) { if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid", "Invalide Organization UID."); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDInvalid); } } diff --git a/Contentstack.Management.Core/Models/Version.cs b/Contentstack.Management.Core/Models/Version.cs index e899279..546a9a5 100644 --- a/Contentstack.Management.Core/Models/Version.cs +++ b/Contentstack.Management.Core/Models/Version.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models.Versioning; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -83,7 +84,7 @@ internal void ThrowIfVersionNumberNotEmpty() { if (Number != null) { - throw new InvalidOperationException("Operation not allowed."); + throw new InvalidOperationException(CSConstants.OperationNotAllowedForVersion); } } @@ -91,7 +92,7 @@ internal void ThrowIfVersionNumberEmpty() { if (Number == null) { - throw new InvalidOperationException("Uid can not be empty."); + throw new InvalidOperationException(CSConstants.VersionUIDRequired); } } #endregion diff --git a/Contentstack.Management.Core/Models/Workflow.cs b/Contentstack.Management.Core/Models/Workflow.cs index c9cd182..797869f 100644 --- a/Contentstack.Management.Core/Models/Workflow.cs +++ b/Contentstack.Management.Core/Models/Workflow.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Queryable; using Contentstack.Management.Core.Services.Models; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Models { @@ -288,7 +289,7 @@ public virtual ContentstackResponse GetPublishRule(string contentType, Parameter stack.ThrowIfNotLoggedIn(); if (string.IsNullOrEmpty(contentType)) { - throw new ArgumentNullException("Content Type can not be empty."); + throw new ArgumentNullException("contentType", CSConstants.ContentTypeRequired); } var service = new FetchDeleteService(stack.client.serializer, stack, $"/workflows/content_type/{contentType}", collection: collection); @@ -310,7 +311,7 @@ public virtual Task GetPublishRuleAsync(string contentType stack.ThrowIfNotLoggedIn(); if (string.IsNullOrEmpty(contentType)) { - throw new ArgumentNullException("Content Type can not be empty."); + throw new ArgumentNullException("contentType", CSConstants.ContentTypeRequired); } var service = new FetchDeleteService(stack.client.serializer, stack, $"/workflows/content_type/{contentType}", collection: collection); return stack.client.InvokeAsync(service); diff --git a/Contentstack.Management.Core/Queryable/ParameterCollection.cs b/Contentstack.Management.Core/Queryable/ParameterCollection.cs index f1f27b8..1d701d9 100644 --- a/Contentstack.Management.Core/Queryable/ParameterCollection.cs +++ b/Contentstack.Management.Core/Queryable/ParameterCollection.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using Contentstack.Management.Core.Exceptions; +using Contentstack.Management.Core.Utils; using Newtonsoft.Json.Linq; namespace Contentstack.Management.Core.Queryable @@ -113,7 +114,7 @@ private IEnumerable> GetParametersEnumerable() yield return new KeyValuePair($"{name}[]", listValue.ToString(CultureInfo.InvariantCulture)); break; default: - throw new ContentstackException("Unsupported parameter value type '" + value.GetType().FullName + "'"); + throw new ContentstackException(CSConstants.ParameterTypeNotSupported); } } } diff --git a/Contentstack.Management.Core/Queryable/Query.cs b/Contentstack.Management.Core/Queryable/Query.cs index eb8b6fe..6e9a14b 100644 --- a/Contentstack.Management.Core/Queryable/Query.cs +++ b/Contentstack.Management.Core/Queryable/Query.cs @@ -17,12 +17,12 @@ internal Query(Stack stack, string resourcePath, string apiVersion = null) { if(stack == null) { - throw new ArgumentNullException("stack", "Stack can not be null"); + throw new ArgumentNullException("stack", CSConstants.StackRequired); } if (resourcePath== null) { - throw new ArgumentNullException("resourcePath", "Respource path can not be null"); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } _stack = stack; _resourcePath = resourcePath; diff --git a/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs b/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs index 0feb573..e802586 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Contentstack.Management.Core.Internal; using Contentstack.Management.Core.Runtime.Contexts; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Runtime.Pipeline { @@ -17,7 +18,7 @@ public virtual Task InvokeAsync(IExecutionContext executionContext, bool a { return InnerHandler.InvokeAsync(executionContext, addAcceptMediaHeader, apiVersion); } - throw new InvalidOperationException("Cannot invoke InnerHandler. InnerHandler is not set."); + throw new InvalidOperationException(CSConstants.InnerHandlerNotSet); } public virtual void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) @@ -27,7 +28,7 @@ public virtual void InvokeSync(IExecutionContext executionContext, bool addAccep InnerHandler.InvokeSync(executionContext, addAcceptMediaHeader, apiVersion); return; } - throw new InvalidOperationException("Cannot invoke InnerHandler. InnerHandler is not set."); + throw new InvalidOperationException(CSConstants.InnerHandlerNotSet); } } } diff --git a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryDelayCalculator.cs b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryDelayCalculator.cs index 28e4c74..784a409 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryDelayCalculator.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryDelayCalculator.cs @@ -111,7 +111,7 @@ public bool ShouldRetryHttpStatusCode(HttpStatusCode statusCode, RetryConfigurat } // Default retry condition: 429, 500, 502, 503, 504 - return statusCode == HttpStatusCode.TooManyRequests || + return statusCode == HttpStatusCode.TooManyRequests || statusCode == HttpStatusCode.InternalServerError || statusCode == HttpStatusCode.BadGateway || statusCode == HttpStatusCode.ServiceUnavailable || diff --git a/Contentstack.Management.Core/Services/ContentstackService.cs b/Contentstack.Management.Core/Services/ContentstackService.cs index dcffbe4..fcf422f 100644 --- a/Contentstack.Management.Core/Services/ContentstackService.cs +++ b/Contentstack.Management.Core/Services/ContentstackService.cs @@ -32,7 +32,7 @@ internal ContentstackService(JsonSerializer serializer, Core.Models.Stack stack { if (serializer == null) { - throw new ArgumentNullException("serializer"); + throw new ArgumentNullException("serializer", CSConstants.JSONSerializerError); } if (stack != null) diff --git a/Contentstack.Management.Core/Services/DeleteReleaseItemService.cs b/Contentstack.Management.Core/Services/DeleteReleaseItemService.cs index 41d07bf..37a63c3 100644 --- a/Contentstack.Management.Core/Services/DeleteReleaseItemService.cs +++ b/Contentstack.Management.Core/Services/DeleteReleaseItemService.cs @@ -4,6 +4,7 @@ using System.IO; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services { internal class DeleteReleaseItemService : ContentstackService @@ -16,15 +17,15 @@ internal DeleteReleaseItemService(JsonSerializer serializer, Core.Models.Stack s { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (releaseUID == null) { - throw new ArgumentNullException("releaseUID", "Should have release UID for service."); + throw new ArgumentNullException("releaseUID", CSConstants.ReleaseUIDRequired); } if (items == null) { - throw new ArgumentNullException("items", "Should release items for service."); + throw new ArgumentNullException("items", CSConstants.ReleaseItemsRequired); } this.ResourcePath = $"/releases/{releaseUID}/item"; this.HttpMethod = "DELETE"; diff --git a/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs b/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs index 2eb042c..699cb5e 100644 --- a/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs +++ b/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -21,11 +22,11 @@ internal CreateUpdateFolderService( { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (name == null) { - throw new ArgumentNullException("name", "Should have folder name."); + throw new ArgumentNullException("name", CSConstants.FolderNameRequired); } this.ResourcePath = "/assets/folders"; diff --git a/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs b/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs index 75cb646..b4530e6 100644 --- a/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs +++ b/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -17,19 +18,19 @@ internal CreateUpdateService(JsonSerializer serializer, Core.Models.Stack stack, { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (dataModel == null) { - throw new ArgumentNullException("dataModel", "Data model is mandatory for service"); + throw new ArgumentNullException("dataModel", CSConstants.DataModelRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Name mandatory for service"); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.ResourcePath = resourcePath; this.HttpMethod = httpMethod; diff --git a/Contentstack.Management.Core/Services/Models/DeleteService.cs b/Contentstack.Management.Core/Services/Models/DeleteService.cs index 321e39c..c0c4bec 100644 --- a/Contentstack.Management.Core/Services/Models/DeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/DeleteService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -16,19 +17,19 @@ internal DeleteService(JsonSerializer serializer, Core.Models.Stack stack, strin { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should have resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Should have field name for service."); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } if (model == null) { - throw new ArgumentNullException("model", "Should have model for service."); + throw new ArgumentNullException("model", CSConstants.ModelRequired); } this.ResourcePath = resourcePath; this.HttpMethod = "DELETE"; diff --git a/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs b/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs index 3ba2c76..287a408 100644 --- a/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs @@ -1,6 +1,7 @@ using System; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -13,11 +14,11 @@ internal FetchDeleteService(JsonSerializer serializer, Core.Models.Stack stack, { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } this.ResourcePath = resourcePath; this.HttpMethod = httpMethod; diff --git a/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs b/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs index 9f53204..c012b33 100644 --- a/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs +++ b/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Contentstack.Management.Core.Queryable; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -11,11 +12,11 @@ internal FetchReferencesService(JsonSerializer serializer, Core.Models.Stack sta { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } this.ResourcePath = $"{resourcePath}/references"; this.HttpMethod = "GET"; diff --git a/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs b/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs index e04f868..9c526b6 100644 --- a/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs @@ -1,6 +1,7 @@ using System; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -19,11 +20,11 @@ internal GlobalFieldFetchDeleteService(JsonSerializer serializer, Core.Models.St { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } this.ResourcePath = resourcePath; diff --git a/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs b/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs index b4471c2..97e20d7 100644 --- a/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs +++ b/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs @@ -4,6 +4,7 @@ using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -24,19 +25,19 @@ internal GlobalFieldService(JsonSerializer serializer, Core.Models.Stack stack, { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (dataModel == null) { - throw new ArgumentNullException("dataModel", "Data model is mandatory for service"); + throw new ArgumentNullException("dataModel", CSConstants.DataModelRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Name mandatory for service"); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.ResourcePath = resourcePath; diff --git a/Contentstack.Management.Core/Services/Models/ImportExportService.cs b/Contentstack.Management.Core/Services/Models/ImportExportService.cs index 7df554c..3640bcf 100644 --- a/Contentstack.Management.Core/Services/Models/ImportExportService.cs +++ b/Contentstack.Management.Core/Services/Models/ImportExportService.cs @@ -1,6 +1,7 @@ using System; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -11,11 +12,11 @@ internal ImportExportService(JsonSerializer serializer, Core.Models.Stack stack, { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should have resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } ResourcePath = isImport ? $"{resourcePath}/import" : $"{resourcePath}/export"; diff --git a/Contentstack.Management.Core/Services/Models/LocaleService.cs b/Contentstack.Management.Core/Services/Models/LocaleService.cs index 728d3a8..75c007b 100644 --- a/Contentstack.Management.Core/Services/Models/LocaleService.cs +++ b/Contentstack.Management.Core/Services/Models/LocaleService.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -10,7 +11,7 @@ internal LocaleService(JsonSerializer serializer, Core.Models.Stack stack, strin { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } this.ResourcePath = resourcePath != null ? $"{resourcePath}/locales" : "locales"; diff --git a/Contentstack.Management.Core/Services/Models/LocalizationService.cs b/Contentstack.Management.Core/Services/Models/LocalizationService.cs index 0b7e21e..4dae67f 100644 --- a/Contentstack.Management.Core/Services/Models/LocalizationService.cs +++ b/Contentstack.Management.Core/Services/Models/LocalizationService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -18,19 +19,19 @@ internal LocalizationService(JsonSerializer serializer, Core.Models.Stack stack, { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (!shouldUnlocalize && dataModel == null) { - throw new ArgumentNullException("dataModel", "Data model is mandatory for service"); + throw new ArgumentNullException("dataModel", CSConstants.DataModelRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Name mandatory for service"); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.ResourcePath = shouldUnlocalize ? $"{resourcePath}/unlocalize" : resourcePath; this.HttpMethod = shouldUnlocalize ? "POST": "PUT"; diff --git a/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs b/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs index c768ea4..e8bb6fd 100644 --- a/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs +++ b/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Models; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -16,22 +17,22 @@ internal PublishUnpublishService(JsonSerializer serializer, Core.Models.Stack st { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (details == null) { - throw new ArgumentNullException("details", "Should publish details for service."); + throw new ArgumentNullException("details", CSConstants.PublishDetailsRequired); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Should field name for service."); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.ResourcePath = resourcePath; diff --git a/Contentstack.Management.Core/Services/Models/UploadService.cs b/Contentstack.Management.Core/Services/Models/UploadService.cs index 5657076..d62c948 100644 --- a/Contentstack.Management.Core/Services/Models/UploadService.cs +++ b/Contentstack.Management.Core/Services/Models/UploadService.cs @@ -3,6 +3,7 @@ using System.Net.Http; using Contentstack.Management.Core.Abstractions; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models { @@ -15,15 +16,15 @@ internal UploadService(JsonSerializer serializer, Core.Models.Stack stack, strin { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should have resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (uploadInterface == null) { - throw new ArgumentNullException("uploadInterface", "Should have multipart content for service."); + throw new ArgumentNullException("uploadInterface", CSConstants.UploadContentRequired); } this.ResourcePath = resourcePath; this.HttpMethod = httpMethod; diff --git a/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs b/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs index 6c4e3a7..1af2a60 100644 --- a/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs +++ b/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Models.Versioning { @@ -20,15 +21,15 @@ internal VersionService(JsonSerializer serializer, Core.Models.Stack stack, stri { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "Should have API Key to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (resourcePath == null) { - throw new ArgumentNullException("resourcePath", "Should resource path for service."); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } if (fieldName == null) { - throw new ArgumentNullException("fieldName", "Should resource path for service."); + throw new ArgumentNullException("fieldName", CSConstants.FieldNameRequired); } this.fieldName = fieldName; this.ResourcePath = resourcePath; diff --git a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs index be8952e..796c223 100644 --- a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs +++ b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs @@ -1,6 +1,7 @@ using System; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization { @@ -12,7 +13,7 @@ internal OrganizationRolesService(JsonSerializer serializer, string uid, Paramet { if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid"); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDRequired); } this.ResourcePath = "organizations/{organization_uid}/roles"; diff --git a/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs b/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs index 21489ff..ef44af3 100644 --- a/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs +++ b/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs @@ -1,6 +1,7 @@ using System; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization { @@ -13,7 +14,7 @@ internal OrganizationStackService(JsonSerializer serializer, string uid, Paramet if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid"); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDRequired); } this.ResourcePath = "/organizations/{organization_uid}/stacks"; this.AddPathResource("{organization_uid}", uid); diff --git a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs index 64fac47..cd19ac0 100644 --- a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization { @@ -11,11 +12,11 @@ internal ResendInvitationService(JsonSerializer serializer, string uid, string s { if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid"); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDRequired); } if (string.IsNullOrEmpty(shareUid)) { - throw new ArgumentNullException("shareUid"); + throw new ArgumentNullException("shareUid", CSConstants.ShareUIDRequired); } this.ResourcePath = "/organizations/{organization_uid}/share/{share_uid}/resend_invitation"; this.AddPathResource("{organization_uid}", uid); diff --git a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs index 217c721..be933ed 100644 --- a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization { @@ -14,12 +15,12 @@ internal TransferOwnershipService(JsonSerializer serializer, string uid, string { if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid"); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDRequired); } if (string.IsNullOrEmpty(email)) { - throw new ArgumentNullException("email"); + throw new ArgumentNullException("email", CSConstants.EmailRequired); } this._email = email; this.ResourcePath = "/organizations/{organization_uid}/transfer-ownership"; diff --git a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs index f81772c..7a5dcb5 100644 --- a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs @@ -5,6 +5,7 @@ using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization { @@ -19,12 +20,12 @@ internal UserInvitationService(JsonSerializer serializer, string uid, string htt { if (string.IsNullOrEmpty(uid)) { - throw new ArgumentNullException("uid"); + throw new ArgumentNullException("uid", CSConstants.OrganizationUIDRequired); } if (string.IsNullOrEmpty(httpMethod)) { - throw new ArgumentNullException("httpMethod"); + throw new ArgumentNullException("httpMethod", CSConstants.HTTPMethodRequired); } if (collection != null && collection.Count > 0) { diff --git a/Contentstack.Management.Core/Services/QueryService.cs b/Contentstack.Management.Core/Services/QueryService.cs index 029514a..751e7c4 100644 --- a/Contentstack.Management.Core/Services/QueryService.cs +++ b/Contentstack.Management.Core/Services/QueryService.cs @@ -1,6 +1,7 @@ using System; using Newtonsoft.Json; using Contentstack.Management.Core.Queryable; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services { @@ -13,13 +14,13 @@ internal QueryService(Core.Models.Stack stack, ParameterCollection collection, s { if (string.IsNullOrEmpty(resourcePath)) { - throw new ArgumentNullException("resourcePath"); + throw new ArgumentNullException("resourcePath", CSConstants.ResourcePathRequired); } this.ResourcePath = resourcePath; if (string.IsNullOrEmpty(stack.APIKey)) { - throw new ArgumentNullException("stack", "API Key should be present."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (collection != null && collection.Count > 0) { diff --git a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs index bf9cce8..724c0bd 100644 --- a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack { @@ -35,18 +36,18 @@ internal StackCreateUpdateService( { if (masterLocale == null) { - throw new ArgumentNullException("masterLocale", "Should have Master Locale while creating the Stack."); + throw new ArgumentNullException("masterLocale", CSConstants.MasterLocaleRequired); } if (_name == null) { - throw new ArgumentNullException("name", "Name for stack is mandatory while creating the Stack."); + throw new ArgumentNullException("name", CSConstants.StackNameRequired); } this.Headers.Add("organization_uid", organizationUid); this.HttpMethod = "POST"; } else { - throw new ArgumentNullException("stack", "Should have API Key or Organization UID to perform this operation."); + throw new ArgumentNullException("stack", CSConstants.APIKeyOrOrgUIDRequired); } } diff --git a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs index 206d390..4d4ca43 100644 --- a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack { @@ -15,12 +16,12 @@ internal StackOwnershipService(JsonSerializer serializer, Core.Models.Stack stac { if (string.IsNullOrEmpty(stack.APIKey)) { - throw new ArgumentNullException("stack", "API Key should be present."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } if (string.IsNullOrEmpty(email)) { - throw new ArgumentNullException("email"); + throw new ArgumentNullException("email", CSConstants.EmailRequired); } this._email = email; this.ResourcePath = "stacks/transfer_ownership"; diff --git a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs index 225f6b1..8855cc7 100644 --- a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs @@ -3,6 +3,7 @@ using System.IO; using Contentstack.Management.Core.Models; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack { @@ -16,7 +17,7 @@ internal StackSettingsService(JsonSerializer serializer, Core.Models.Stack stack { if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "API Key should be present."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } ResourcePath = "stacks/settings"; HttpMethod = method; diff --git a/Contentstack.Management.Core/Services/Stack/StackShareService.cs b/Contentstack.Management.Core/Services/Stack/StackShareService.cs index 3b65cfd..be81a5a 100644 --- a/Contentstack.Management.Core/Services/Stack/StackShareService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackShareService.cs @@ -4,6 +4,7 @@ using System.IO; using Contentstack.Management.Core.Models; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack { @@ -17,7 +18,7 @@ internal StackShareService(JsonSerializer serializer, Core.Models.Stack stack) : { if (string.IsNullOrEmpty(stack.APIKey)) { - throw new ArgumentNullException("stack", "API Key should be present."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } HttpMethod = "POST"; } diff --git a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs index cab8836..3d92b66 100644 --- a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs +++ b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs @@ -5,6 +5,7 @@ using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Queryable; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack { @@ -18,12 +19,12 @@ internal UpdateUserRoleService(JsonSerializer serializer, Core.Models.Stack stac { if (userInvitation == null) { - throw new ArgumentNullException("userInvitation", "Uid and roles should be present."); + throw new ArgumentNullException("userInvitation", CSConstants.UserInvitationDetailsRequired); } if (stack.APIKey == null) { - throw new ArgumentNullException("stack", "API Key should be present."); + throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } this.ResourcePath = "stacks/users/roles"; this.HttpMethod = "POST"; diff --git a/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs b/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs index 356914a..e16f9f0 100644 --- a/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs +++ b/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.User { @@ -13,7 +14,7 @@ internal ForgotPasswordService(JsonSerializer serializer, string email): base (s { if (string.IsNullOrEmpty(email)) { - throw new ArgumentNullException("email"); + throw new ArgumentNullException("email", CSConstants.EmailRequired); } _email = email; diff --git a/Contentstack.Management.Core/Services/User/LoginService.cs b/Contentstack.Management.Core/Services/User/LoginService.cs index 9dbaf05..977926e 100644 --- a/Contentstack.Management.Core/Services/User/LoginService.cs +++ b/Contentstack.Management.Core/Services/User/LoginService.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using OtpNet; using Contentstack.Management.Core.Http; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.User { @@ -24,7 +25,7 @@ internal LoginService(JsonSerializer serializer, ICredentials credentials, strin if (credentials == null) { - throw new ArgumentNullException("credentials"); + throw new ArgumentNullException("credentials", CSConstants.LoginCredentialsRequired); } _credentials = credentials; diff --git a/Contentstack.Management.Core/Services/User/LogoutService.cs b/Contentstack.Management.Core/Services/User/LogoutService.cs index 9576198..b9856a7 100644 --- a/Contentstack.Management.Core/Services/User/LogoutService.cs +++ b/Contentstack.Management.Core/Services/User/LogoutService.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.User { @@ -15,7 +16,7 @@ public LogoutService(JsonSerializer serializer, string authtoken): base(serializ if (string.IsNullOrEmpty(authtoken)) { - throw new ArgumentNullException("authtoken"); + throw new ArgumentNullException("authtoken", CSConstants.AuthenticationTokenRequired); } _authtoken = authtoken; diff --git a/Contentstack.Management.Core/Services/User/ResetPasswordService.cs b/Contentstack.Management.Core/Services/User/ResetPasswordService.cs index dc900e4..799732a 100644 --- a/Contentstack.Management.Core/Services/User/ResetPasswordService.cs +++ b/Contentstack.Management.Core/Services/User/ResetPasswordService.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.IO; using Newtonsoft.Json; +using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.User { @@ -15,15 +16,15 @@ internal ResetPasswordService(JsonSerializer serializer, string resetPasswordTok { if (string.IsNullOrEmpty(resetPasswordToken)) { - throw new ArgumentNullException("resetPasswordToken"); + throw new ArgumentNullException("resetPasswordToken", CSConstants.ResetPasswordTokenRequired); } if (string.IsNullOrEmpty(password)) { - throw new ArgumentNullException("password"); + throw new ArgumentNullException("password", CSConstants.NewPasswordRequired); } if (string.IsNullOrEmpty(confirmPassword)) { - throw new ArgumentNullException("confirmPassword"); + throw new ArgumentNullException("confirmPassword", CSConstants.PasswordMismatch); } _resetPasswordToken = resetPasswordToken; _password = password; diff --git a/Contentstack.Management.Core/Utils/CSConstants.cs b/Contentstack.Management.Core/Utils/CSConstants.cs index e7c2214..d967b74 100644 --- a/Contentstack.Management.Core/Utils/CSConstants.cs +++ b/Contentstack.Management.Core/Utils/CSConstants.cs @@ -13,15 +13,133 @@ public static class CSConstants #endregion #region Internal Message + + #region Authentication Messages internal const string YouAreLoggedIn = "You are already logged in."; - internal const string YouAreNotLoggedIn = "You are need to login."; + internal const string YouAreNotLoggedIn = "You are not logged in. Log in and try again."; + internal const string LoginCredentialsRequired = "Login credentials are required. Provide a valid email and password and try again."; + internal const string AuthenticationTokenRequired = "Authentication token is required to log out. Provide a valid token and try again."; + internal const string ResetPasswordTokenRequired = "Reset password token is required. Provide a valid token and try again."; + internal const string NewPasswordRequired = "New password is required. Provide a valid password and try again."; + internal const string PasswordMismatch = "New password and confirm password do not match. Enter the same password in both fields and try again."; + #endregion - internal const string MissingUID = "Uid should not be empty."; - internal const string MissingAPIKey = "API Key should not be empty."; - internal const string APIKey = "API Key should be empty."; + #region OAuth Messages + internal const string OAuthOptionsRequired = "OAuth options cannot be null."; + internal const string OAuthTokensRequired = "OAuth tokens cannot be null."; + internal const string AccessTokenRequired = "Access token cannot be null or empty."; + internal const string ClientIDRequired = "Client ID cannot be null or empty."; + #endregion + + #region HTTP Client Messages + internal const string HttpClientRequired = "HTTP client is required. Initialize the HTTP client and try again."; + #endregion + + #region API Key Messages + internal const string MissingAPIKey = "API Key is required. Provide a valid API Key and try again."; + internal const string InvalidAPIKey = "API Key is invalid. Provide a valid API Key and try again."; + internal const string APIKeyOrOrgUIDRequired = "API Key or Organization UID is required to perform this operation. Provide a valid value and try again."; + #endregion + + #region UID Messages + internal const string MissingUID = "UID is required. Provide a valid UID and try again."; + internal const string AssetUIDRequired = "Asset UID is required. Provide a valid Asset UID and try again."; + internal const string AuditLogUIDRequired = "Audit Log UID is required. Provide a valid Audit Log UID and try again."; + internal const string ExtensionUIDRequired = "Extension UID is required. Provide a valid Extension UID and try again."; + internal const string FolderUIDRequired = "Folder UID is required. Provide a valid Folder UID and try again."; + internal const string OrganizationUIDRequired = "Organization UID is required. Provide a valid Organization UID and try again."; + internal const string PublishQueueUIDRequired = "Publish Queue UID is required. Provide a valid Publish Queue UID and try again."; + internal const string ReleaseItemUIDRequired = "Release Item UID is required. Provide a valid Release Item UID and try again."; + internal const string VersionUIDRequired = "Version UID is required. Provide a valid Version UID and try again."; + internal const string ShareUIDRequired = "Share UID is required. Provide a valid Share UID and try again."; + internal const string ReleaseUIDRequired = "Release UID is required. Provide a valid Release UID and try again."; + internal const string JobIDRequired = "Job ID is required to fetch the bulk job status. Provide a valid Job ID and try again."; + #endregion + #region Operation Not Allowed Messages + internal const string AssetAlreadyExists = "An asset with this unique ID already exists. Use a different ID and try again."; + internal const string OperationNotAllowedOnModel = "Operation not allowed on this model. Update your request and try again."; + internal const string OperationNotAllowedOnAuditLogs = "Operation not allowed on audit logs. Update your request and try again."; + internal const string OperationNotAllowedOnExtension = "Operation not allowed on extension. Update your request and try again."; + internal const string OperationNotAllowedOnFolder = "Operation not allowed on folder. Update your request and try again."; + internal const string OperationNotAllowedOnPublishQueue = "Operation not allowed on publish queue. Update your request and try again."; + internal const string OperationNotAllowedForVersion = "Operation not allowed for this Version."; + #endregion + + #region File and Upload Messages + internal const string FileNameRequired = "File Name is required. Provide a valid File Name and try again."; + internal const string UploadContentRequired = "Upload content is required. Provide valid upload content and try again."; + internal const string WidgetTitleRequired = "Widget Title is required. Provide a valid Widget Title and try again."; + #endregion + + #region Field and Model Messages + internal const string FieldNameRequired = "Field Name is required for this service. Provide a valid Field Name and try again."; + internal const string DataModelRequired = "Data Model is required for this service. Provide a valid Data Model and try again."; + internal const string ModelRequired = "Model is required for this service. Provide a valid Model and try again."; + #endregion + + #region Stack Messages + internal const string StackRequired = "Stack is required. Initialize the Stack and try again."; + internal const string StackSettingsRequired = "Stack settings are required. Provide valid Stack settings and try again."; + internal const string InvitationsRequired = "Invitations are required. Provide valid Invitations and try again."; + internal const string EmailRequired = "Email is required. Provide a valid Email and try again."; + internal const string StackNameInvalid = "Stack Name is invalid. Provide a valid Stack Name and try again."; + internal const string LocaleInvalid = "Locale is invalid for this Stack. Provide a valid Locale and try again."; + internal const string OrganizationUIDInvalid = "Organization UID is invalid. Provide a valid Organization UID and try again."; + internal const string MasterLocaleRequired = "Master Locale is required when creating the Stack. Provide a valid Master Locale and try again."; + internal const string StackNameRequired = "Stack Name is required when creating the Stack. Provide a valid Stack Name and try again."; + #endregion + + #region Release Messages + internal const string ReleaseNameInvalid = "Release Name is invalid. Provide a valid Release Name and try again."; + #endregion + + #region Workflow Messages + internal const string ContentTypeRequired = "Content Type is required. Provide a valid Content Type and try again."; + #endregion + + #region Query Messages + internal const string ResourcePathRequired = "Resource Path is required. Provide a valid Resource Path and try again."; + internal const string ParameterTypeNotSupported = "Parameter value type is not supported. Provide a supported value type and try again."; + #endregion + + #region Pipeline Messages + internal const string InnerHandlerNotSet = "Inner Handler is not set. Configure an Inner Handler and try again."; + internal const string ResponseNotReturned = "Response was not returned and no exception was thrown. Try again. Retry the request and check your network."; + #endregion + + #region Serializer Messages + internal const string JSONSerializerError = "JSON serializer error. Check the serializer configuration and try again."; + #endregion + + #region Bulk Operation Messages + internal const string BulkOperationStackRequired = "Bulk operation failed. Initialize the stack before running this operation."; + internal const string BulkAddDataRequired = "Data payload is required for bulk addition. Provide a list of objects and try again."; + internal const string BulkDeleteDetailsRequired = "Delete details are required for bulk deletion. Provide a list of objects with the required fields and try again."; + internal const string BulkPublishDetailsRequired = "Publish details are required for bulk publish. Provide a list of item objects with the required fields and try again."; + internal const string BulkUnpublishDetailsRequired = "Unpublish details are required for bulk unpublish. Provide a list of item objects with the required fields and try again."; + internal const string BulkReleaseItemsDataRequired = "Data payload is required for bulk release items. Provide a valid list of item objects and try again."; + internal const string BulkWorkflowUpdateBodyRequired = "Request body is required for bulk workflow update. Provide a valid payload with the required workflow fields and try again."; + internal const string BulkUpdateDataRequired = "Data payload is required for bulk update. Provide a valid list of item objects with the required fields and try again."; + #endregion + + #region Organization Messages + internal const string EmailsRequired = "Emails are required. Provide a list of valid email addresses and try again."; + internal const string UserInvitationDetailsRequired = "User invitation details are required. Provide a valid UID and Roles to update the user role and try again."; + #endregion + + #region Service Messages + internal const string FolderNameRequired = "Folder Name is required. Provide a valid Folder Name and try again."; + internal const string PublishDetailsRequired = "Publish details are required. Provide valid publish details and try again."; + internal const string HTTPMethodRequired = "HTTP method is required. Provide a valid HTTP method and try again."; + internal const string ReleaseItemsRequired = "Release Items are required. Provide valid Release Items and try again."; + #endregion + + #region Legacy Messages (for backward compatibility) internal const string RemoveUserEmailError = "Please enter email id to remove from org."; internal const string OrgShareUIDMissing = "Please enter share uid to resend invitation."; + internal const string APIKey = "API Key should be empty."; + #endregion #endregion } } diff --git a/LICENSE b/LICENSE index 3851325..4ea4612 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012-2025 Contentstack +Copyright (c) 2012-2026 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal