diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b033e..b4baaa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Changelog -## [v1.0.0-beta.1](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.11.0-beta.1) +## [v1.0.0-beta.2](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.0.0-beta.2) + - **System.Text.Json Migration Complete (Beta)** + - **✅ Core Modules STJ-Only**: Client, User, Organization, and Stack modules fully migrated + - **✅ Service Layer**: All User, Organization, Stack services converted to System.Text.Json + - **✅ Model Updates**: Updated constructors and service calls to use JsonSerializerOptions + - **✅ Response Handling**: Implemented OpenJsonObjectResponse() for STJ-based JSON parsing + - **✅ Backward Compatibility**: Non-migrated modules continue using Newtonsoft.Json + - **✅ Testing Infrastructure**: Comprehensive web application for STJ validation + - **Performance**: Improved JSON serialization performance and reduced memory footprint + - **Architecture**: Clean separation between STJ and Newtonsoft implementations + +## [v1.0.0-beta.1](https://github.com/contentstack/contentstack-management-dotnet/tree/v1.0.0-beta.1) - **Breaking Change** - **System.Text.Json Migration (Beta)** - Migrated core serialization from Newtonsoft.Json to System.Text.Json diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index c345b97..3c5f94c 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -131,7 +131,7 @@ public ContentstackClient(ContentstackClientOptions contentstackOptions) : /// /// public ContentstackClient( - string authtoken = null, + string? authtoken = null, string host = "api.contentstack.io", int port = 443, string version = "v3", @@ -139,9 +139,9 @@ public ContentstackClient( long maxResponseContentBufferSize = CSConstants.ContentBufferSize, int timeout = 30, bool retryOnError = true, - string proxyHost = null, + string? proxyHost = null, int proxyPort = -1, - ICredentials proxyCredentials = null + ICredentials? proxyCredentials = null ) : this(new OptionsWrapper(new ContentstackClientOptions() { @@ -161,7 +161,7 @@ public ContentstackClient( { } #endregion - protected void Initialize(HttpClient httpClient = null) + protected void Initialize(HttpClient? httpClient = null) { if (httpClient != null) { @@ -229,7 +229,7 @@ protected void BuildPipeline() }, LogManager); } - internal ContentstackResponse InvokeSync(TRequest request, bool addAcceptMediaHeader = false, string apiVersion = null) where TRequest : IContentstackService + internal ContentstackResponse InvokeSync(TRequest request, bool addAcceptMediaHeader = false, string? apiVersion = null) where TRequest : IContentstackService { ThrowIfDisposed(); @@ -246,7 +246,7 @@ internal ContentstackResponse InvokeSync(TRequest request, bool addAcc return (ContentstackResponse)ContentstackPipeline.InvokeSync(context, addAcceptMediaHeader, apiVersion).httpResponse; } - internal async Task InvokeAsync(TRequest request, bool addAcceptMediaHeader = false, string apiVersion = null) + internal async Task InvokeAsync(TRequest request, bool addAcceptMediaHeader = false, string? apiVersion = null) where TRequest : IContentstackService where TResponse : ContentstackResponse { @@ -307,7 +307,6 @@ private void ThrowIfDisposed() } #endregion - /* /// /// session consists of calls that will help you to update user of your Contentstack account. /// @@ -322,9 +321,7 @@ public User User() { return new User(this); } - */ - /* /// /// the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users. /// allows easy management of projects as well as users within the Organization. @@ -337,13 +334,11 @@ public User User() /// /// /// The . - public Organization Organization(string uid = null) + public Organization Organization(string? uid = null) { return new Organization(this, uid); } - */ - /* /// /// is a space that stores the content of a project (a web or mobile property). /// Within a stack, you can create content structures, content entries, users, etc. related to the project. @@ -352,16 +347,15 @@ public Organization Organization(string uid = null) /// Stack Management token /// ///

-        /// ContentstackClient client = new ContentstackClient("", "");
+        /// ContentstackClient client = new ContentstackClient("", "");
         /// Stack Stack = client.Stack("");
         /// 
///
/// The . - public Stack Stack(string apiKey = null, string managementToken = null, string branchUid = null) + public Stack Stack(string? apiKey = null, string? managementToken = null, string? branchUid = null) { return new Stack(this, apiKey, managementToken, branchUid); } - */ #region LoginMethod /// @@ -378,7 +372,7 @@ public Stack Stack(string apiKey = null, string managementToken = null, string b /// /// /// The - public ContentstackResponse Login(ICredentials credentials, string token = null, string mfaSecret = null) + public ContentstackResponse Login(ICredentials credentials, string? token = null, string? mfaSecret = null) { ThrowIfAlreadyLoggedIn(); LoginService Login = new LoginService(SerializerOptions, credentials, token, mfaSecret); @@ -400,7 +394,7 @@ public ContentstackResponse Login(ICredentials credentials, string token = null, /// /// /// The Task. - public Task LoginAsync(ICredentials credentials, string token = null, string mfaSecret = null) + public Task LoginAsync(ICredentials credentials, string? token = null, string? mfaSecret = null) { ThrowIfAlreadyLoggedIn(); LoginService Login = new LoginService(SerializerOptions, credentials, token, mfaSecret); @@ -440,7 +434,7 @@ internal void ThrowIfNotLoggedIn() /// /// /// The - public ContentstackResponse Logout(string authtoken = null) + public ContentstackResponse Logout(string? authtoken = null) { string token = authtoken ?? contentstackOptions.Authtoken; LogoutService logout = new LogoutService(SerializerOptions, token); @@ -458,7 +452,7 @@ public ContentstackResponse Logout(string authtoken = null) /// /// /// The Task. - public Task LogoutAsync(string authtoken = null) + public Task LogoutAsync(string? authtoken = null) { string token = authtoken ?? contentstackOptions.Authtoken; LogoutService logout = new LogoutService(SerializerOptions, token); @@ -688,7 +682,7 @@ internal void ClearAllOAuthTokens() /// /// /// The - public ContentstackResponse GetUser(ParameterCollection collection = null) + public ContentstackResponse GetUser(ParameterCollection? collection = null) { ThrowIfNotLoggedIn(); @@ -707,7 +701,7 @@ public ContentstackResponse GetUser(ParameterCollection collection = null) /// /// /// The Task. - public Task GetUserAsync(ParameterCollection collection = null) + public Task GetUserAsync(ParameterCollection? collection = null) { ThrowIfNotLoggedIn(); diff --git a/Contentstack.Management.Core/ContentstackResponse.cs b/Contentstack.Management.Core/ContentstackResponse.cs index 5e93116..607a7a9 100644 --- a/Contentstack.Management.Core/ContentstackResponse.cs +++ b/Contentstack.Management.Core/ContentstackResponse.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; diff --git a/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs b/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs index 7ee1807..8a7950d 100644 --- a/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs +++ b/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Threading.Tasks; using System.Net.Http.Headers; diff --git a/Contentstack.Management.Core/IResponse.cs b/Contentstack.Management.Core/IResponse.cs index 61bfd8e..41ecff2 100644 --- a/Contentstack.Management.Core/IResponse.cs +++ b/Contentstack.Management.Core/IResponse.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net; using System.Text.Json.Nodes; using Newtonsoft.Json.Linq; diff --git a/Contentstack.Management.Core/Models/BulkOperation.cs b/Contentstack.Management.Core/Models/BulkOperation.cs index 928c081..0f67732 100644 --- a/Contentstack.Management.Core/Models/BulkOperation.cs +++ b/Contentstack.Management.Core/Models/BulkOperation.cs @@ -51,12 +51,12 @@ internal BulkOperation(Stack stack) /// ContentstackResponse response = stack.BulkOperation().Publish(publishDetails); /// /// - public ContentstackResponse Publish(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string apiVersion = null) + public ContentstackResponse Publish(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string? apiVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkPublishService(_stack.client.serializer, _stack, details, skipWorkflowStage, approvals, isNested); + var service = new BulkPublishService(_stack.client.SerializerOptions, _stack, details, skipWorkflowStage, approvals, isNested); return _stack.client.InvokeSync(service, false, apiVersion); } @@ -69,12 +69,12 @@ public ContentstackResponse Publish(BulkPublishDetails details, bool skipWorkflo /// Set to true for nested publish operations. /// The API version to use. /// The Task - public Task PublishAsync(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string apiVersion = null) + public Task PublishAsync(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string? apiVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkPublishService(_stack.client.serializer, _stack, details, skipWorkflowStage, approvals, isNested); + var service = new BulkPublishService(_stack.client.SerializerOptions, _stack, details, skipWorkflowStage, approvals, isNested); return _stack.client.InvokeAsync(service, false, apiVersion); } @@ -109,12 +109,12 @@ public Task PublishAsync(BulkPublishDetails details, bool /// ContentstackResponse response = stack.BulkOperation().Unpublish(unpublishDetails); /// /// - public ContentstackResponse Unpublish(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string apiVersion = null) + public ContentstackResponse Unpublish(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string? apiVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkUnpublishService(_stack.client.serializer, _stack, details, skipWorkflowStage, approvals, isNested); + var service = new BulkUnpublishService(_stack.client.SerializerOptions, _stack, details, skipWorkflowStage, approvals, isNested); return _stack.client.InvokeSync(service, false, apiVersion); } @@ -127,12 +127,12 @@ public ContentstackResponse Unpublish(BulkPublishDetails details, bool skipWorkf /// Set to true for nested unpublish operations. /// The API version to use. /// The Task - public Task UnpublishAsync(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string apiVersion = null) + public Task UnpublishAsync(BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false, string? apiVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkUnpublishService(_stack.client.serializer, _stack, details, skipWorkflowStage, approvals, isNested); + var service = new BulkUnpublishService(_stack.client.SerializerOptions, _stack, details, skipWorkflowStage, approvals, isNested); return _stack.client.InvokeAsync(service, false, apiVersion); } @@ -166,7 +166,7 @@ public ContentstackResponse Delete(BulkDeleteDetails details) _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkDeleteService(_stack.client.serializer, _stack, details); + var service = new BulkDeleteService(_stack.client.SerializerOptions, _stack, details); return _stack.client.InvokeSync(service); } @@ -180,7 +180,7 @@ public Task DeleteAsync(BulkDeleteDetails details) _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkDeleteService(_stack.client.serializer, _stack, details); + var service = new BulkDeleteService(_stack.client.SerializerOptions, _stack, details); return _stack.client.InvokeAsync(service); } @@ -219,7 +219,7 @@ public ContentstackResponse Update(BulkWorkflowUpdateBody updateBody) _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkWorkflowUpdateService(_stack.client.serializer, _stack, updateBody); + var service = new BulkWorkflowUpdateService(_stack.client.SerializerOptions, _stack, updateBody); return _stack.client.InvokeSync(service); } @@ -235,7 +235,7 @@ public Task UpdateAsync(BulkWorkflowUpdateBody updateBody) _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkWorkflowUpdateService(_stack.client.serializer, _stack, updateBody); + var service = new BulkWorkflowUpdateService(_stack.client.SerializerOptions, _stack, updateBody); return _stack.client.InvokeAsync(service); } @@ -289,7 +289,7 @@ public ContentstackResponse AddItems(BulkAddItemsData data, string bulkVersion = _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkAddItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkAddItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeSync(service); } @@ -327,7 +327,7 @@ public ContentstackResponse AddItems(BulkAddItemsData data, string bulkVersion = /// ContentstackResponse response = stack.BulkOperation().AddItemsWithDeployment(deployData, "release_uid", "publish", new List { "en-us" }, true, "2.0"); /// /// - public ContentstackResponse AddItemsWithDeployment(BulkAddItemsData data, string releaseUid, string action, List locales = null, bool? reference = null, string bulkVersion = null) + public ContentstackResponse AddItemsWithDeployment(BulkAddItemsData data, string releaseUid, string action, List? locales = null, bool? reference = null, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); @@ -338,7 +338,7 @@ public ContentstackResponse AddItemsWithDeployment(BulkAddItemsData data, string data.Locale = locales; data.Reference = reference; - var service = new BulkAddItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkAddItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeSync(service); } @@ -355,7 +355,7 @@ public Task AddItemsAsync(BulkAddItemsData data, string bu _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkAddItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkAddItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeAsync(service); } @@ -370,7 +370,7 @@ public Task AddItemsAsync(BulkAddItemsData data, string bu /// Whether to include references. Only used when releaseUid is specified. /// The bulk version. /// The Task - public Task AddItemsWithDeploymentAsync(BulkAddItemsData data, string releaseUid, string action, List locales = null, bool? reference = null, string bulkVersion = null) + public Task AddItemsWithDeploymentAsync(BulkAddItemsData data, string releaseUid, string action, List? locales = null, bool? reference = null, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); @@ -381,7 +381,7 @@ public Task AddItemsWithDeploymentAsync(BulkAddItemsData d data.Locale = locales; data.Reference = reference; - var service = new BulkAddItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkAddItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeAsync(service); } @@ -437,7 +437,7 @@ public ContentstackResponse UpdateItems(BulkAddItemsData data, string bulkVersio _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkUpdateItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkUpdateItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeSync(service); } @@ -475,7 +475,7 @@ public ContentstackResponse UpdateItems(BulkAddItemsData data, string bulkVersio /// ContentstackResponse response = stack.BulkOperation().UpdateItemsWithDeployment(deployData, "release_uid", "publish", new List { "en-us" }, true, "2.0"); /// /// - public ContentstackResponse UpdateItemsWithDeployment(BulkAddItemsData data, string releaseUid, string action, List locales = null, bool? reference = null, string bulkVersion = null) + public ContentstackResponse UpdateItemsWithDeployment(BulkAddItemsData data, string releaseUid, string action, List? locales = null, bool? reference = null, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); @@ -486,7 +486,7 @@ public ContentstackResponse UpdateItemsWithDeployment(BulkAddItemsData data, str data.Locale = locales; data.Reference = reference; - var service = new BulkUpdateItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkUpdateItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeSync(service); } @@ -503,7 +503,7 @@ public Task UpdateItemsAsync(BulkAddItemsData data, string _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkUpdateItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkUpdateItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeAsync(service); } @@ -518,7 +518,7 @@ public Task UpdateItemsAsync(BulkAddItemsData data, string /// Whether to include references. Only used when releaseUid is specified. /// The bulk version. /// The Task - public Task UpdateItemsWithDeploymentAsync(BulkAddItemsData data, string releaseUid, string action, List locales = null, bool? reference = null, string bulkVersion = null) + public Task UpdateItemsWithDeploymentAsync(BulkAddItemsData data, string releaseUid, string action, List? locales = null, bool? reference = null, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); @@ -529,7 +529,7 @@ public Task UpdateItemsWithDeploymentAsync(BulkAddItemsDat data.Locale = locales; data.Reference = reference; - var service = new BulkUpdateItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkUpdateItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeAsync(service); } @@ -547,14 +547,14 @@ public Task UpdateItemsWithDeploymentAsync(BulkAddItemsDat /// ContentstackResponse response = stack.BulkOperation().JobStatus("job_id", "1.0"); /// /// - public ContentstackResponse JobStatus(string jobId, string bulkVersion = null) + public ContentstackResponse JobStatus(string jobId, string? bulkVersion = null) { if (string.IsNullOrWhiteSpace(jobId)) throw new ArgumentNullException(nameof(jobId)); _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkJobStatusService(_stack.client.serializer, _stack, jobId, bulkVersion); + var service = new BulkJobStatusService(_stack.client.SerializerOptions, _stack, jobId, bulkVersion); return _stack.client.InvokeSync(service); } @@ -564,14 +564,14 @@ public ContentstackResponse JobStatus(string jobId, string bulkVersion = null) /// The ID of the job. /// The bulk version. /// The Task - public Task JobStatusAsync(string jobId, string bulkVersion = null) + public Task JobStatusAsync(string jobId, string? bulkVersion = null) { if (string.IsNullOrWhiteSpace(jobId)) throw new ArgumentNullException(nameof(jobId)); _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkJobStatusService(_stack.client.serializer, _stack, jobId, bulkVersion); + var service = new BulkJobStatusService(_stack.client.SerializerOptions, _stack, jobId, bulkVersion); return _stack.client.InvokeAsync(service); } @@ -608,12 +608,12 @@ public Task JobStatusAsync(string jobId, string bulkVersio /// ContentstackResponse response = stack.BulkOperation().ReleaseItems(releaseData); /// /// - public ContentstackResponse ReleaseItems(BulkReleaseItemsData data, string bulkVersion = null) + public ContentstackResponse ReleaseItems(BulkReleaseItemsData data, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkReleaseItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkReleaseItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeSync(service); } @@ -623,12 +623,12 @@ public ContentstackResponse ReleaseItems(BulkReleaseItemsData data, string bulkV /// The release items data containing release, action, locale, reference, and items. /// The bulk version. /// The Task - public Task ReleaseItemsAsync(BulkReleaseItemsData data, string bulkVersion = null) + public Task ReleaseItemsAsync(BulkReleaseItemsData data, string? bulkVersion = null) { _stack.ThrowIfNotLoggedIn(); _stack.ThrowIfAPIKeyEmpty(); - var service = new BulkReleaseItemsService(_stack.client.serializer, _stack, data, bulkVersion); + var service = new BulkReleaseItemsService(_stack.client.SerializerOptions, _stack, data, bulkVersion); return _stack.client.InvokeAsync(service); } } diff --git a/Contentstack.Management.Core/Models/Organization.cs b/Contentstack.Management.Core/Models/Organization.cs index db5a540..9fff482 100644 --- a/Contentstack.Management.Core/Models/Organization.cs +++ b/Contentstack.Management.Core/Models/Organization.cs @@ -12,7 +12,7 @@ public class Organization private readonly ContentstackClient _client; #region Constructor - public Organization(ContentstackClient contentstackClient, string uid = null) + public Organization(ContentstackClient contentstackClient, string? uid = null) { _client = contentstackClient; Uid = uid; @@ -34,11 +34,11 @@ public Organization(ContentstackClient contentstackClient, string uid = null) /// /// /// The - public ContentstackResponse GetOrganizations(ParameterCollection parameters = null) + public ContentstackResponse GetOrganizations(ParameterCollection? parameters = null) { _client.ThrowIfNotLoggedIn(); - var Organizations = new GetOrganizations(_client.serializer, parameters, this.Uid); + var Organizations = new GetOrganizations(_client.SerializerOptions, parameters, this.Uid); return _client.InvokeSync(Organizations); } @@ -55,11 +55,11 @@ public ContentstackResponse GetOrganizations(ParameterCollection parameters = nu /// /// /// The Task - public Task GetOrganizationsAsync(ParameterCollection parameters = null) + public Task GetOrganizationsAsync(ParameterCollection? parameters = null) { _client.ThrowIfNotLoggedIn(); - var Organizations = new GetOrganizations(_client.serializer, parameters, this.Uid); + var Organizations = new GetOrganizations(_client.SerializerOptions, parameters, this.Uid); return _client.InvokeAsync(Organizations); } @@ -76,12 +76,12 @@ public Task GetOrganizationsAsync(ParameterCollection para /// /// /// The - public ContentstackResponse Roles(ParameterCollection parameters = null) + public ContentstackResponse Roles(ParameterCollection? parameters = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); - var Roles = new OrganizationRolesService(_client.serializer, this.Uid, parameters); + var Roles = new OrganizationRolesService(this.Uid, parameters, _client.SerializerOptions); return _client.InvokeSync(Roles); } @@ -98,12 +98,12 @@ public ContentstackResponse Roles(ParameterCollection parameters = null) /// /// /// The Task - public Task RolesAsync(ParameterCollection parameters = null) + public Task RolesAsync(ParameterCollection? parameters = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); - var Roles = new OrganizationRolesService(_client.serializer, this.Uid, parameters); + var Roles = new OrganizationRolesService(this.Uid, parameters, _client.SerializerOptions); return _client.InvokeAsync(Roles); } @@ -303,7 +303,7 @@ public Task ResendInvitationAsync(string shareUid) /// /// /// The - public ContentstackResponse GetInvitations(ParameterCollection parameter = null) + public ContentstackResponse GetInvitations(ParameterCollection? parameter = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); @@ -325,7 +325,7 @@ public ContentstackResponse GetInvitations(ParameterCollection parameter = null) /// /// /// The Task - public Task GetInvitationsAsync(ParameterCollection parameter = null) + public Task GetInvitationsAsync(ParameterCollection? parameter = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); @@ -390,7 +390,7 @@ public Task TransferOwnershipAsync(string email) /// /// /// The - public ContentstackResponse GetStacks(ParameterCollection parameter = null) + public ContentstackResponse GetStacks(ParameterCollection? parameter = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); @@ -412,7 +412,7 @@ public ContentstackResponse GetStacks(ParameterCollection parameter = null) /// /// /// The Task - public Task GetStacksAsync(ParameterCollection parameter = null) + public Task GetStacksAsync(ParameterCollection? parameter = null) { _client.ThrowIfNotLoggedIn(); this.ThrowIfOrganizationUidNull(); diff --git a/Contentstack.Management.Core/Models/Stack.cs b/Contentstack.Management.Core/Models/Stack.cs index 7278b2e..e400c80 100644 --- a/Contentstack.Management.Core/Models/Stack.cs +++ b/Contentstack.Management.Core/Models/Stack.cs @@ -17,7 +17,7 @@ public class Stack public string BranchUid { get; private set; } #region Constructor - public Stack(ContentstackClient contentstackClient, string apiKey = null, string managementToken = null, string branchUid = null) + public Stack(ContentstackClient contentstackClient, string? apiKey = null, string? managementToken = null, string? branchUid = null) { client = contentstackClient; APIKey = apiKey; @@ -39,12 +39,12 @@ public Stack(ContentstackClient contentstackClient, string apiKey = null, string /// /// /// The - public ContentstackResponse GetAll(ParameterCollection parameters = null) + public ContentstackResponse GetAll(ParameterCollection? parameters = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyNotEmpty(); - var service = new FetchStackService(client.serializer, this, parameters); + var service = new FetchStackService(client.SerializerOptions, this, parameters); return client.InvokeSync(service); } @@ -61,12 +61,12 @@ public ContentstackResponse GetAll(ParameterCollection parameters = null) /// /// /// The Task - public Task GetAllAsync(ParameterCollection parameters = null) + public Task GetAllAsync(ParameterCollection? parameters = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyNotEmpty(); - var service = new FetchStackService(client.serializer, this, parameters); + var service = new FetchStackService(client.SerializerOptions, this, parameters); return client.InvokeAsync(service); } @@ -83,12 +83,12 @@ public Task GetAllAsync(ParameterCollection parameters = n /// /// /// The - public ContentstackResponse Fetch(ParameterCollection parameters = null) + public ContentstackResponse Fetch(ParameterCollection? parameters = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new FetchStackService(client.serializer, this, parameters); + var service = new FetchStackService(client.SerializerOptions, this, parameters); return client.InvokeSync(service); } @@ -104,12 +104,12 @@ public ContentstackResponse Fetch(ParameterCollection parameters = null) /// /// /// The Task - public Task FetchAsync(ParameterCollection parameters = null) + public Task FetchAsync(ParameterCollection? parameters = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new FetchStackService(client.serializer, this, parameters); + var service = new FetchStackService(client.SerializerOptions, this, parameters); return client.InvokeAsync(service); } @@ -131,7 +131,7 @@ public ContentstackResponse TransferOwnership(string email) ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackOwnershipService(client.serializer, this, email); + var service = new StackOwnershipService(this, email, client.SerializerOptions); return client.InvokeSync(service); } @@ -153,7 +153,7 @@ public Task TransferOwnershipAsync(string email) ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackOwnershipService(client.serializer, this, email); + var service = new StackOwnershipService(this, email, client.SerializerOptions); return client.InvokeAsync(service); } @@ -173,7 +173,7 @@ public Task TransferOwnershipAsync(string email) /// /// /// The - public ContentstackResponse Create(string name, string masterLocale, string organisationUid, string description = null) + public ContentstackResponse Create(string name, string masterLocale, string organisationUid, string? description = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyNotEmpty(); @@ -181,7 +181,7 @@ public ContentstackResponse Create(string name, string masterLocale, string orga ThrowInvalideLocale(masterLocale); ThrowInvalideOrganizationUid(organisationUid); - var service = new StackCreateUpdateService(client.serializer, this, name, masterLocale, description, organizationUid: organisationUid); + var service = new StackCreateUpdateService(client.SerializerOptions, this, name, masterLocale, description, organizationUid: organisationUid); return client.InvokeSync(service); } @@ -201,7 +201,7 @@ public ContentstackResponse Create(string name, string masterLocale, string orga /// /// /// The Task - public Task CreateAsync(string name, string masterLocale, string organisationUid, string description = null) + public Task CreateAsync(string name, string masterLocale, string organisationUid, string? description = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyNotEmpty(); @@ -209,7 +209,7 @@ public Task CreateAsync(string name, string masterLocale, ThrowInvalideLocale(masterLocale); ThrowInvalideOrganizationUid(organisationUid); - var service = new StackCreateUpdateService(client.serializer, this, name, masterLocale, description, organizationUid: organisationUid); + var service = new StackCreateUpdateService(client.SerializerOptions, this, name, masterLocale, description, organizationUid: organisationUid); return client.InvokeAsync(service); } @@ -229,13 +229,13 @@ public Task CreateAsync(string name, string masterLocale, /// /// /// The - public ContentstackResponse Update(string name, string description = null) + public ContentstackResponse Update(string name, string? description = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); ThrowInvalideName(name); - var service = new StackCreateUpdateService(client.serializer, this, name, description: description); + var service = new StackCreateUpdateService(client.SerializerOptions, this, name, description: description); return client.InvokeSync(service); } @@ -255,13 +255,13 @@ public ContentstackResponse Update(string name, string description = null) /// /// /// The Task - public Task UpdateAsync(string name, string description = null) + public Task UpdateAsync(string name, string? description = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); ThrowInvalideName(name); - var service = new StackCreateUpdateService(client.serializer, this, name, description: description); + var service = new StackCreateUpdateService(client.SerializerOptions, this, name, description: description); return client.InvokeAsync(service); } @@ -290,7 +290,7 @@ public ContentstackResponse UpdateUserRole(List usersRole) ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new UpdateUserRoleService(client.serializer, this, usersRole); + var service = new UpdateUserRoleService(this, usersRole, client.SerializerOptions); return client.InvokeSync(service); } @@ -319,7 +319,7 @@ public Task UpdateUserRoleAsync(List users ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new UpdateUserRoleService(client.serializer, this, usersRole); + var service = new UpdateUserRoleService(this, usersRole, client.SerializerOptions); return client.InvokeAsync(service); } @@ -340,7 +340,7 @@ public ContentstackResponse Settings() ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackSettingsService(client.serializer, this); + var service = new StackSettingsService(client.SerializerOptions, this); return client.InvokeSync(service); } @@ -361,7 +361,7 @@ public Task SettingsAsync() ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackSettingsService(client.serializer, this); + var service = new StackSettingsService(client.SerializerOptions, this); return client.InvokeAsync(service); } @@ -382,7 +382,7 @@ public ContentstackResponse ResetSettings() ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackSettingsService(client.serializer, this, "POST", new StackSettings() + var service = new StackSettingsService(client.SerializerOptions, this, "POST", new StackSettings() { StackVariables = new Dictionary(), DiscreteVariables = new Dictionary(), @@ -408,7 +408,7 @@ public Task ResetSettingsAsync() ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); - var service = new StackSettingsService(client.serializer, this, "POST", new StackSettings() + var service = new StackSettingsService(client.SerializerOptions, this, "POST", new StackSettings() { StackVariables = new Dictionary(), DiscreteVariables = new Dictionary(), @@ -438,7 +438,7 @@ public ContentstackResponse AddSettings(StackSettings settings) throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired); } - var service = new StackSettingsService(client.serializer, this, "POST", settings); + var service = new StackSettingsService(client.SerializerOptions, this, "POST", settings); return client.InvokeSync(service); } @@ -462,7 +462,7 @@ public Task AddSettingsAsync(StackSettings settings) { throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired); } - var service = new StackSettingsService(client.serializer, this, "POST", settings); + var service = new StackSettingsService(client.SerializerOptions, this, "POST", settings); return client.InvokeAsync(service); } @@ -492,7 +492,7 @@ public ContentstackResponse Share(List invitations) throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired); } - var service = new StackShareService(client.serializer, this); + var service = new StackShareService(this, client.SerializerOptions); service.AddUsers(invitations); return client.InvokeSync(service); @@ -523,7 +523,7 @@ public Task ShareAsync(List invitations) throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired); } - var service = new StackShareService(client.serializer, this); + var service = new StackShareService(this, client.SerializerOptions); service.AddUsers(invitations); return client.InvokeAsync(service); @@ -549,7 +549,7 @@ public ContentstackResponse UnShare(string email) throw new ArgumentNullException("email", CSConstants.EmailRequired); } - var service = new StackShareService(client.serializer, this); + var service = new StackShareService(this, client.SerializerOptions); service.RemoveUsers(email); return client.InvokeSync(service); @@ -576,7 +576,7 @@ public Task UnShareAsync(string email) throw new ArgumentNullException("email", CSConstants.EmailRequired); } - var service = new StackShareService(client.serializer, this); + var service = new StackShareService(this, client.SerializerOptions); service.RemoveUsers(email); return client.InvokeAsync(service); @@ -594,6 +594,7 @@ public Task UnShareAsync(string email) /// /// Locale code fot language /// The + /* public Locale Locale(string code = null) { ThrowIfNotLoggedIn(); @@ -601,6 +602,7 @@ public Locale Locale(string code = null) return new Locale(this, code); } + */ /* // The following resource methods are temporarily commented out as they reference excluded model types @@ -798,6 +800,7 @@ public ManagementToken ManagementTokens(string uid = null) /// /// /// The + /* public Role Role(string uid = null) { ThrowIfNotLoggedIn(); @@ -805,6 +808,7 @@ public Role Role(string uid = null) return new Role(this, uid); } + */ /// /// A is a set of entries and assets that needs to be deployed (published or unpublished) all at once to a particular environment. @@ -818,6 +822,7 @@ public Role Role(string uid = null) /// /// /// The + /* public Release Release(string uid = null) { ThrowIfNotLoggedIn(); @@ -825,6 +830,7 @@ public Release Release(string uid = null) return new Release(this, uid); } + */ /// @@ -839,6 +845,7 @@ public Release Release(string uid = null) /// /// /// The + /* public Workflow Workflow(string uid = null) { ThrowIfNotLoggedIn(); @@ -846,6 +853,7 @@ public Workflow Workflow(string uid = null) return new Workflow(this, uid); } + */ /// /// A displays the historical and current details of activities such as publish, unpublish, or delete that can be performed on entries and/or assets. @@ -860,6 +868,7 @@ public Workflow Workflow(string uid = null) /// /// /// The + /* public PublishQueue PublishQueue(string uid = null) { ThrowIfNotLoggedIn(); @@ -867,6 +876,7 @@ public PublishQueue PublishQueue(string uid = null) return new PublishQueue(this, uid); } + */ /// /// A a mechanism that sends real-time information to any third-party app or service to keep your application in sync with your Contentstack account. /// @@ -879,6 +889,7 @@ public PublishQueue PublishQueue(string uid = null) /// /// /// The + /* public Webhook Webhook(string uid = null) { ThrowIfNotLoggedIn(); @@ -886,6 +897,7 @@ public Webhook Webhook(string uid = null) return new Webhook(this, uid); } + */ /// /// A displays a record of all the activities performed in a stack and helps you keep a track of all published items, updates, deletes, and current status of the existing content. @@ -899,6 +911,7 @@ public Webhook Webhook(string uid = null) /// /// /// The + /* public AuditLog AuditLog(string uid = null) { ThrowIfNotLoggedIn(); @@ -906,6 +919,7 @@ public AuditLog AuditLog(string uid = null) return new AuditLog(this, uid); } + */ /// /// A allows you to manage variant groups and their associated content types. @@ -920,6 +934,7 @@ public AuditLog AuditLog(string uid = null) /// /// /// The + /* public VariantGroup VariantGroup(string uid = null) { ThrowIfNotLoggedIn(); @@ -927,6 +942,7 @@ public VariantGroup VariantGroup(string uid = null) return new VariantGroup(this, uid); } + */ /// /// Gets the bulk operation instance for performing bulk operations on entries and assets. diff --git a/Contentstack.Management.Core/Models/StackSettings.cs b/Contentstack.Management.Core/Models/StackSettings.cs index 563882e..15f549a 100644 --- a/Contentstack.Management.Core/Models/StackSettings.cs +++ b/Contentstack.Management.Core/Models/StackSettings.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text.Json.Serialization; diff --git a/Contentstack.Management.Core/Models/User.cs b/Contentstack.Management.Core/Models/User.cs index 111ac29..0161b30 100644 --- a/Contentstack.Management.Core/Models/User.cs +++ b/Contentstack.Management.Core/Models/User.cs @@ -36,7 +36,7 @@ public ContentstackResponse ForgotPassword(string email) { _client.ThrowIfAlreadyLoggedIn(); - var forgotPassword = new ForgotPasswordService(_client.serializer, email); + var forgotPassword = new ForgotPasswordService(_client.SerializerOptions, email); return _client.InvokeSync(forgotPassword); } @@ -57,7 +57,7 @@ public Task ForgotPasswordAsync(string email) { _client.ThrowIfAlreadyLoggedIn(); - var forgotPassword = new ForgotPasswordService(_client.serializer, email); + var forgotPassword = new ForgotPasswordService(_client.SerializerOptions, email); return _client.InvokeAsync(forgotPassword); } @@ -80,7 +80,7 @@ public ContentstackResponse ResetPassword(string resetToken, string password, st { _client.ThrowIfAlreadyLoggedIn(); - var resetPassword = new ResetPasswordService(_client.serializer, resetToken, password, confirmPassword); + var resetPassword = new ResetPasswordService(_client.SerializerOptions, resetToken, password, confirmPassword); return _client.InvokeSync(resetPassword); } @@ -103,7 +103,7 @@ public Task ResetPasswordAsync(string resetToken, string p { _client.ThrowIfAlreadyLoggedIn(); - var resetPassword = new ResetPasswordService(_client.serializer, resetToken, password, confirmPassword); + var resetPassword = new ResetPasswordService(_client.SerializerOptions, resetToken, password, confirmPassword); return _client.InvokeAsync(resetPassword); } diff --git a/Contentstack.Management.Core/Queryable/Query.cs b/Contentstack.Management.Core/Queryable/Query.cs index 6e9a14b..e071188 100644 --- a/Contentstack.Management.Core/Queryable/Query.cs +++ b/Contentstack.Management.Core/Queryable/Query.cs @@ -13,7 +13,7 @@ public class Query private readonly ParameterCollection _collection = new ParameterCollection(); private readonly string _apiVersion; - internal Query(Stack stack, string resourcePath, string apiVersion = null) + internal Query(Stack stack, string resourcePath, string? apiVersion = null) { if(stack == null) { @@ -79,6 +79,7 @@ public Query IncludeCount() return this; } + /* /// /// The Find all object call fetches the list of all objects owned by a particular user account. /// @@ -118,6 +119,7 @@ public Task FindAsync(ParameterCollection collection = nul return _stack.client.InvokeAsync(service, false, _apiVersion); } + */ #endregion #region Throw Error diff --git a/Contentstack.Management.Core/Services/ContentstackService.cs b/Contentstack.Management.Core/Services/ContentstackService.cs index 394ca65..60a994c 100644 --- a/Contentstack.Management.Core/Services/ContentstackService.cs +++ b/Contentstack.Management.Core/Services/ContentstackService.cs @@ -8,6 +8,7 @@ using Contentstack.Management.Core.Utils; using Contentstack.Management.Core.Queryable; using System.Net.Http.Headers; +using Contentstack.Management.Core.Models; namespace Contentstack.Management.Core.Services { @@ -28,14 +29,14 @@ internal class ContentstackService : IContentstackService #endregion #region Constructor - internal ContentstackService(JsonSerializerOptions serializerOptions, object stack = null, ParameterCollection collection = null) + internal ContentstackService(JsonSerializerOptions serializerOptions, Models.Stack stack = null, ParameterCollection collection = null) { if (serializerOptions == null) { throw new ArgumentNullException("serializerOptions", CSConstants.JSONSerializerError); } - /* + // Restored Stack integration for STJ-only migration if (stack != null) { if (!string.IsNullOrEmpty(stack.APIKey)) @@ -49,12 +50,11 @@ internal ContentstackService(JsonSerializerOptions serializerOptions, object sta } this.ManagementToken = stack.ManagementToken; - }else + } + else { this.ManagementToken = null; } - */ - // Temporarily disabled Stack integration this.collection = collection ?? new ParameterCollection(); _serializerOptions = serializerOptions; diff --git a/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs b/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs index cf159bb..859ca10 100644 --- a/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs +++ b/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs @@ -1,4 +1,4 @@ - + using Contentstack.Management.Core.Queryable; using System.Text.Json; namespace Contentstack.Management.Core.Services.Organization diff --git a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs index 796c223..c2f9fd2 100644 --- a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs +++ b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs @@ -1,6 +1,6 @@ using System; using Contentstack.Management.Core.Queryable; -using Newtonsoft.Json; +using System.Text.Json; using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Organization @@ -9,7 +9,7 @@ internal class OrganizationRolesService : ContentstackService { #region Internal - internal OrganizationRolesService(JsonSerializer serializer, string uid, ParameterCollection collection) : base(serializer, collection: collection) + internal OrganizationRolesService(string uid, ParameterCollection collection, JsonSerializerOptions stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), collection: collection) { if (string.IsNullOrEmpty(uid)) { diff --git a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs index 0da448b..ccb3792 100644 --- a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs index 7fc254b..65cbe13 100644 --- a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs index 255c41b..03c1880 100644 --- a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text.Json; diff --git a/Contentstack.Management.Core/Services/Stack/FetchStackService.cs b/Contentstack.Management.Core/Services/Stack/FetchStackService.cs index 411625b..0978cc4 100644 --- a/Contentstack.Management.Core/Services/Stack/FetchStackService.cs +++ b/Contentstack.Management.Core/Services/Stack/FetchStackService.cs @@ -1,4 +1,4 @@ -using System; +using System; using Contentstack.Management.Core.Queryable; using System.Text.Json; diff --git a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs index 56ff6e8..78b8eaf 100644 --- a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs index 4d4ca43..3f36e52 100644 --- a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs @@ -1,7 +1,5 @@ using System; -using System.Globalization; -using System.IO; -using Newtonsoft.Json; +using System.Text.Json; using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack @@ -11,8 +9,8 @@ internal class StackOwnershipService : ContentstackService private readonly string _email; #region Internal - internal StackOwnershipService(JsonSerializer serializer, Core.Models.Stack stack, string email) - : base(serializer, stack) + internal StackOwnershipService(Core.Models.Stack stack, string email, JsonSerializerOptions stjOptions = null) + : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (string.IsNullOrEmpty(stack.APIKey)) { @@ -31,16 +29,13 @@ internal StackOwnershipService(JsonSerializer serializer, Core.Models.Stack stac public override void ContentBody() { - using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) + var requestData = new { - JsonWriter writer = new JsonTextWriter(stringWriter); - writer.WriteStartObject(); - writer.WritePropertyName("transfer_to"); - writer.WriteValue(_email); - writer.WriteEndObject(); - string snippet = stringWriter.ToString(); - this.ByteContent = System.Text.Encoding.UTF8.GetBytes(snippet); - } + transfer_to = _email + }; + + string jsonString = JsonSerializer.Serialize(requestData, SerializerOptions); + this.ByteContent = System.Text.Encoding.UTF8.GetBytes(jsonString); } } } \ No newline at end of file diff --git a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs index 8955179..ed97327 100644 --- a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.IO; using Contentstack.Management.Core.Models; diff --git a/Contentstack.Management.Core/Services/Stack/StackShareService.cs b/Contentstack.Management.Core/Services/Stack/StackShareService.cs index be81a5a..e9e2d49 100644 --- a/Contentstack.Management.Core/Services/Stack/StackShareService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackShareService.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; -using System.Globalization; -using System.IO; +using System.Text.Json; +using System.Linq; using Contentstack.Management.Core.Models; -using Newtonsoft.Json; using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack @@ -14,7 +13,7 @@ internal class StackShareService : ContentstackService private string _removeUser; - internal StackShareService(JsonSerializer serializer, Core.Models.Stack stack) : base(serializer, stack) + internal StackShareService(Core.Models.Stack stack, JsonSerializerOptions stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (string.IsNullOrEmpty(stack.APIKey)) { @@ -37,40 +36,33 @@ internal void RemoveUsers(string emails) public override void ContentBody() { - using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) + object requestData; + + if (_invitations != null) { - JsonWriter writer = new JsonTextWriter(stringWriter); - writer.WriteStartObject(); - if (_invitations != null) + requestData = new { - writer.WritePropertyName("emails"); - writer.WriteStartArray(); - foreach (UserInvitation user in _invitations) - writer.WriteValue(user.Email); - writer.WriteEndArray(); - - writer.WritePropertyName("roles"); - writer.WriteStartObject(); - foreach (UserInvitation invitation in _invitations) - { - writer.WritePropertyName(invitation.Email); - writer.WriteStartArray(); - foreach (string role in invitation.Roles) - writer.WriteValue(role); - writer.WriteEndArray(); - } - writer.WriteEndObject(); - } - else if (_removeUser != null) + emails = _invitations.Select(u => u.Email).ToArray(), + roles = _invitations.ToDictionary( + invitation => invitation.Email, + invitation => invitation.Roles.ToArray() + ) + }; + } + else if (_removeUser != null) + { + requestData = new { - writer.WritePropertyName("email"); - writer.WriteValue(_removeUser); - } - writer.WriteEndObject(); - - string snippet = stringWriter.ToString(); - this.ByteContent = System.Text.Encoding.UTF8.GetBytes(snippet); + email = _removeUser + }; } + else + { + requestData = new { }; + } + + string jsonString = JsonSerializer.Serialize(requestData, SerializerOptions); + this.ByteContent = System.Text.Encoding.UTF8.GetBytes(jsonString); } } } diff --git a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs index 3d92b66..b75ec15 100644 --- a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs +++ b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; -using System.Globalization; -using System.IO; +using System.Text.Json; +using System.Linq; using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Queryable; -using Newtonsoft.Json; using Contentstack.Management.Core.Utils; namespace Contentstack.Management.Core.Services.Stack @@ -14,8 +13,8 @@ internal class UpdateUserRoleService : ContentstackService #region Internal private readonly List _users; - internal UpdateUserRoleService(JsonSerializer serializer, Core.Models.Stack stack, ListuserInvitation) - : base(serializer, stack) + internal UpdateUserRoleService(Core.Models.Stack stack, List userInvitation, JsonSerializerOptions stjOptions = null) + : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (userInvitation == null) { @@ -33,25 +32,16 @@ internal UpdateUserRoleService(JsonSerializer serializer, Core.Models.Stack stac public override void ContentBody() { - using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) + var requestData = new { - JsonWriter writer = new JsonTextWriter(stringWriter); - writer.WriteStartObject(); - writer.WritePropertyName("users"); - writer.WriteStartObject(); - foreach (UserInvitation invitation in this._users) - { - writer.WritePropertyName(invitation.Uid); - writer.WriteStartArray(); - foreach (string role in invitation.Roles) - writer.WriteValue(role); - writer.WriteEndArray(); - } - writer.WriteEndObject(); - writer.WriteEndObject(); - string snippet = stringWriter.ToString(); - this.ByteContent = System.Text.Encoding.UTF8.GetBytes(snippet); - } + users = _users.ToDictionary( + invitation => invitation.Uid, + invitation => invitation.Roles.ToArray() + ) + }; + + string jsonString = JsonSerializer.Serialize(requestData, SerializerOptions); + this.ByteContent = System.Text.Encoding.UTF8.GetBytes(jsonString); } #endregion } diff --git a/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs b/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs index a87f697..fa24455 100644 --- a/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs +++ b/Contentstack.Management.Core/Services/User/ForgotPasswordService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs b/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs index bf8a251..79dd006 100644 --- a/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs +++ b/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs @@ -1,4 +1,4 @@ -using System; +using System; using Contentstack.Management.Core.Queryable; using System.Text.Json; diff --git a/Contentstack.Management.Core/Services/User/LoginService.cs b/Contentstack.Management.Core/Services/User/LoginService.cs index 006f85c..450a671 100644 --- a/Contentstack.Management.Core/Services/User/LoginService.cs +++ b/Contentstack.Management.Core/Services/User/LoginService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Net; using System.Text.Json; diff --git a/Contentstack.Management.Core/Services/User/LogoutService.cs b/Contentstack.Management.Core/Services/User/LogoutService.cs index de97ded..a199ff9 100644 --- a/Contentstack.Management.Core/Services/User/LogoutService.cs +++ b/Contentstack.Management.Core/Services/User/LogoutService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/Services/User/ResetPasswordService.cs b/Contentstack.Management.Core/Services/User/ResetPasswordService.cs index 4db1b4c..c07e6f3 100644 --- a/Contentstack.Management.Core/Services/User/ResetPasswordService.cs +++ b/Contentstack.Management.Core/Services/User/ResetPasswordService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text.Json; using Contentstack.Management.Core.Utils; diff --git a/Contentstack.Management.Core/contentstack.management.core.csproj b/Contentstack.Management.Core/contentstack.management.core.csproj index acefc32..ebd9fef 100644 --- a/Contentstack.Management.Core/contentstack.management.core.csproj +++ b/Contentstack.Management.Core/contentstack.management.core.csproj @@ -79,13 +79,13 @@ - - + + - + @@ -96,7 +96,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -113,30 +113,27 @@ - + - - - - + + - - + + - + - + - - + - - + + diff --git a/Directory.Build.props b/Directory.Build.props index 02afb64..2ad39e3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 1.0.0-beta.1 + 1.0.0-beta.2