diff --git a/cli/Squidex.CLI/Directory.Build.props b/cli/Squidex.CLI/Directory.Build.props index 836ab765..472b1be7 100644 --- a/cli/Squidex.CLI/Directory.Build.props +++ b/cli/Squidex.CLI/Directory.Build.props @@ -15,6 +15,6 @@ Squidex HeadlessCMS true snupkg - 9.6 + 10.0 diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ISession.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ISession.cs index 6a16d9e7..5519e848 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ISession.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ISession.cs @@ -6,7 +6,6 @@ // ========================================================================== using Squidex.ClientLibrary; -using Squidex.ClientLibrary.Management; namespace Squidex.CLI.Commands.Implementation; @@ -22,17 +21,5 @@ public interface ISession DirectoryInfo WorkingDirectory { get; } - IAppsClient Apps { get; } - - IAssetsClient Assets { get; } - - IBackupsClient Backups { get; } - - ISchemasClient Schemas { get; } - - IExtendableRulesClient Rules { get; } - - IContentsClient Contents(string schemaName) where TEntity : Content where TData : class, new(); - - IContentsClient Contents(string schemaName); + ISquidexClient Client { get; } } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ExportHelper.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ExportHelper.cs index b351ce49..d63520e7 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ExportHelper.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ExportHelper.cs @@ -15,7 +15,7 @@ public static async Task ExportAsync(this ISession session, IExportSettings sett { var ctx = QueryContext.Default.Unpublished(settings.Unpublished); - var contents = session.Contents(settings.Schema); + var contents = session.Client.DynamicContents(settings.Schema); var total = 0L; var totalRead = 0; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ImportHelper.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ImportHelper.cs index c1f56bce..505c4af1 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ImportHelper.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/ImExport/ImportHelper.cs @@ -21,7 +21,7 @@ public static class ImportHelper { public static async Task ImportAsync(this ISession session, IImportSettings setting, ILogger log, IEnumerable datas) { - var contents = session.Contents(setting.Schema); + var contents = session.Client.DynamicContents(setting.Schema); var totalWritten = 0; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs index 10856e4d..878a1d16 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/App/AppSynchronizer.cs @@ -39,7 +39,7 @@ public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession s await log.DoSafeAsync("Exporting clients", async () => { - var clients = await session.Apps.GetClientsAsync(session.App); + var clients = await session.Client.Apps.GetClientsAsync(); model.Clients = new Dictionary(); @@ -51,7 +51,7 @@ await log.DoSafeAsync("Exporting clients", async () => await log.DoSafeAsync("Exporting languages", async () => { - var languages = await session.Apps.GetLanguagesAsync(session.App); + var languages = await session.Client.Apps.GetLanguagesAsync(); model.Languages = new Dictionary(); @@ -63,7 +63,7 @@ await log.DoSafeAsync("Exporting languages", async () => await log.DoSafeAsync("Exporting Roles", async () => { - var roles = await session.Apps.GetRolesAsync(session.App); + var roles = await session.Client.Apps.GetRolesAsync(); model.Roles = new Dictionary(); @@ -75,7 +75,7 @@ await log.DoSafeAsync("Exporting Roles", async () => await log.DoSafeAsync("Exporting asset scripts", async () => { - var assetScripts = await session.Apps.GetAssetScriptsAsync(session.App); + var assetScripts = await session.Client.Apps.GetAssetScriptsAsync(); model.AssetScripts = assetScripts.ToModel(); }); @@ -160,14 +160,14 @@ await log.DoSafeAsync($"Contributor '{email}' creating", async () => { var request = new AssignContributorDto { ContributorId = email, Role = value.Role, Invite = true }; - await session.Apps.PostContributorAsync(session.App, request); + await session.Client.Apps.PostContributorAsync(request); }); } } private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options, ISession session) { - var current = await session.Apps.GetClientsAsync(session.App); + var current = await session.Client.Apps.GetClientsAsync(); if (options.Delete) { @@ -182,7 +182,7 @@ private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options, await log.DoSafeAsync($"Client '{client.Id}' deleting", async () => { - await session.Apps.DeleteClientAsync(session.App, client.Id); + await session.Client.Apps.DeleteClientAsync(client.Id); }); } } @@ -200,7 +200,7 @@ await log.DoSafeAsync($"Client '{clientId}' creating", async () => { var request = new CreateClientDto { Id = clientId }; - current = await session.Apps.PostClientAsync(session.App, request); + current = await session.Client.Apps.PostClientAsync(request); }); } @@ -222,14 +222,14 @@ await log.DoSafeAsync($"Client '{clientId}' updating", async () => { var request = client.ToUpdate(); - await session.Apps.PutClientAsync(session.App, clientId, request); + await session.Client.Apps.PutClientAsync(clientId, request); }); } } private async Task SynchronizeLanguagesAsync(AppModel model, SyncOptions options, ISession session) { - var current = await session.Apps.GetLanguagesAsync(session.App); + var current = await session.Client.Apps.GetLanguagesAsync(); if (options.Delete) { @@ -242,7 +242,7 @@ private async Task SynchronizeLanguagesAsync(AppModel model, SyncOptions options await log.DoSafeAsync($"Language '{language.Iso2Code}' deleting", async () => { - await session.Apps.DeleteLanguageAsync(session.App, language.Iso2Code); + await session.Client.Apps.DeleteLanguageAsync(language.Iso2Code); }); } } @@ -260,7 +260,7 @@ await log.DoSafeAsync($"Language '{isoCode}' creating", async () => { var request = new AddLanguageDto { Language = isoCode }; - current = await session.Apps.PostLanguageAsync(session.App, request); + current = await session.Client.Apps.PostLanguageAsync(request); }); } @@ -275,14 +275,14 @@ await log.DoSafeAsync($"Language '{isoCode}' creating", async () => await log.DoSafeAsync($"Language '{isoCode}' updating", async () => { - await session.Apps.PutLanguageAsync(session.App, isoCode, language); + await session.Client.Apps.PutLanguageAsync(isoCode, language); }); } } private async Task SynchronizeRolesAsync(AppModel model, SyncOptions options, ISession session) { - var current = await session.Apps.GetRolesAsync(session.App); + var current = await session.Client.Apps.GetRolesAsync(); if (options.Delete) { @@ -298,7 +298,7 @@ private async Task SynchronizeRolesAsync(AppModel model, SyncOptions options, IS await log.DoSafeAsync($"Role '{role.Name}' deleting", async () => { - await session.Apps.DeleteRoleAsync(session.App, role.Name); + await session.Client.Apps.DeleteRoleAsync(role.Name); }); } } @@ -316,7 +316,7 @@ await log.DoSafeAsync($"Role '{roleName}' creating", async () => { var request = new AddRoleDto { Name = roleName }; - current = await session.Apps.PostRoleAsync(session.App, request); + current = await session.Client.Apps.PostRoleAsync(request); }); } @@ -333,7 +333,7 @@ await log.DoSafeAsync($"Role '{roleName}' updating", async () => { var request = role.ToUpdate(); - await session.Apps.PutRoleAsync(session.App, roleName, request); + await session.Client.Apps.PutRoleAsync(roleName, request); }); } } @@ -349,7 +349,7 @@ await log.DoSafeAsync("Asset scripts updating", async () => { var request = model.AssetScripts?.ToUpdate() ?? new UpdateAssetScriptsDto(); - await session.Apps.PutAssetScriptsAsync(session.App, request); + await session.Client.Apps.PutAssetScriptsAsync(request); }); } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs index d4800de5..3362e5ff 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs @@ -61,7 +61,7 @@ await log.DoSafeAsync($"Exporting Assets ({assetBatch})", async () => }); } - await session.Assets.GetAllAsync(session.App, async asset => + await session.Client.Assets.GetAllAsync(async asset => { var model = asset.ToModel(); @@ -143,7 +143,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s var assetIndex = 0; - var results = await session.Assets.BulkUpdateAssetsAsync(session.App, request); + var results = await session.Client.Assets.BulkUpdateAssetsAsync(request); foreach (var asset in model.Assets) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/DownloadPipeline.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/DownloadPipeline.cs index cfde2c16..1b60341f 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/DownloadPipeline.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/DownloadPipeline.cs @@ -64,7 +64,7 @@ public DownloadPipeline(ISession session, ILogger log, IFileSystem fs) if (assetHash == null || !string.Equals(asset.FileHash, assetHash, StringComparison.Ordinal)) { - var response = await session.Assets.GetAssetContentBySlugAsync(session.App, asset.Id, string.Empty); + var response = await session.Client.Assets.GetAssetContentBySlugAsync(asset.Id, string.Empty); await using (response.Stream) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/UploadPipeline.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/UploadPipeline.cs index 9eda2fd4..579e77b3 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/UploadPipeline.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/UploadPipeline.cs @@ -24,7 +24,7 @@ internal sealed class UploadPipeline public UploadPipeline(ISession session, ILogger log, IFileSystem fs) { - var tree = new AssetFolderTree(session.Assets, session.App); + var tree = new AssetFolderTree(session.Client.Assets); var fileNameStep = new TransformBlock(async asset => { @@ -68,7 +68,7 @@ public UploadPipeline(ISession session, ILogger log, IFileSystem fs) { var file = new FileParameter(stream, asset.FileName, asset.MimeType); - var result = await session.Assets.PostUpsertAssetAsync(session.App, asset.Id, null, true, file); + var result = await session.Client.Assets.PostUpsertAssetAsync(asset.Id, null, true, file); log.ProcessCompleted(process); } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs index e7770635..ba1af65b 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs @@ -37,14 +37,14 @@ public Task CleanupAsync(IFileSystem fs) public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session) { - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var schemaMap = schemas.Items.ToDictionary(x => x.Id, x => x.Name); var context = QueryContext.Default.Unpublished().IgnoreFallback(); foreach (var schema in schemas.Items) { - var client = session.Contents(schema.Name); + var client = session.Client.DynamicContents(schema.Name); var contents = new List(); var contentBatch = 0; @@ -114,7 +114,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s GetFiles(sync.FileSystem) .Select(x => (x, sync.Read(x, log))); - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var schemaMap = schemas.Items.ToDictionary(x => x.Name, x => x.Id); var mapper = new Extensions.Mapper(session.Url, session.App, options.Languages); @@ -125,7 +125,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { mapper.Map(model); - var client = session.Contents(model.Contents[0].Schema); + var client = session.Client.DynamicContents(model.Contents[0].Schema); var request = new BulkUpdate { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs index 5494ab72..cf424702 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Rules/RulesSynchronizer.cs @@ -38,7 +38,7 @@ public Task CleanupAsync(IFileSystem fs) public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session) { - var current = await session.Rules.GetRulesAsync(); + var current = await session.Client.ExtendableRules.GetRulesAsync(); await MapSchemaIdsToNamesAsync(session, current); @@ -90,7 +90,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s return; } - var current = await session.Rules.GetRulesAsync(); + var current = await session.Client.ExtendableRules.GetRulesAsync(); if (!current.Items.HasDistinctNames(x => x.Name)) { @@ -108,7 +108,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { await log.DoSafeAsync($"Rule '{name}' deleting", async () => { - await session.Rules.DeleteRuleAsync(rule.Id); + await session.Client.ExtendableRules.DeleteRuleAsync(rule.Id); rulesByName.Remove(name); }); @@ -134,7 +134,7 @@ await log.DoSafeAsync($"Rule '{newRule.Name}' creating", async () => var request = newRule.ToCreate(); - var created = await session.Rules.CreateRuleAsync(request); + var created = await session.Client.ExtendableRules.CreateRuleAsync(request); rulesByName[newRule.Name] = created; }); @@ -153,7 +153,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' updating", rule.Version, asyn { var request = newRule.ToUpdate(); - rule = await session.Rules.UpdateRuleAsync(rule.Id, request); + rule = await session.Client.ExtendableRules.UpdateRuleAsync(rule.Id, request); return rule.Version; }); @@ -164,7 +164,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' updating", rule.Version, asyn { await log.DoVersionedAsync($"Rule '{newRule.Name}' enabling", rule.Version, async () => { - var result = await session.Rules.EnableRuleAsync(rule.Id); + var result = await session.Client.ExtendableRules.EnableRuleAsync(rule.Id); return result.Version; }); @@ -173,7 +173,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' enabling", rule.Version, asyn { await log.DoVersionedAsync($"Rule '{newRule.Name}' disabling", rule.Version, async () => { - var result = await session.Rules.DisableRuleAsync(rule.Id); + var result = await session.Client.ExtendableRules.DisableRuleAsync(rule.Id); return result.Version; }); @@ -184,7 +184,7 @@ await log.DoVersionedAsync($"Rule '{newRule.Name}' disabling", rule.Version, asy private async Task MapSchemaIdsToNamesAsync(ISession session, ExtendableRules current) { - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var map = schemas.Items.ToDictionary(x => x.Id, x => x.Name); @@ -200,7 +200,7 @@ private async Task MapSchemaIdsToNamesAsync(ISession session, ExtendableRules cu private async Task MapSchemaNamesToIdsAsync(ISession session, List models) { - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var map = schemas.Items.ToDictionary(x => x.Name, x => x.Id); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs index e83afe17..c0f1241b 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs @@ -60,7 +60,7 @@ public Task DescribeAsync(ISyncService sync, MarkdownWriter writer) public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session) { - var current = await session.Schemas.GetSchemasAsync(session.App); + var current = await session.Client.Schemas.GetSchemasAsync(); var schemaMap = current.Items.ToDictionary(x => x.Id, x => x.Name); @@ -68,7 +68,7 @@ public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession s { await log.DoSafeAsync($"Exporting '{schema.Name}'", async () => { - var details = await session.Schemas.GetSchemaAsync(session.App, schema.Name); + var details = await session.Client.Schemas.GetSchemaAsync(schema.Name); var model = new SchemaModel { @@ -99,7 +99,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s return; } - var current = await session.Schemas.GetSchemasAsync(session.App); + var current = await session.Client.Schemas.GetSchemasAsync(); var schemasByName = current.Items.ToDictionary(x => x.Name); @@ -111,7 +111,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { await log.DoSafeAsync($"Schema {name} deleting", async () => { - await session.Schemas.DeleteSchemaAsync(session.App, name); + await session.Client.Schemas.DeleteSchemaAsync(name); }); } } @@ -126,7 +126,7 @@ await log.DoSafeAsync($"Schema {name} deleting", async () => await log.DoSafeAsync($"Schema {model.Name} creating", async () => { - var created = await session.Schemas.PostSchemaAsync(session.App, model.ToCreate()); + var created = await session.Client.Schemas.PostSchemaAsync(model.ToCreate()); schemasByName[model.Name] = created; }); @@ -151,7 +151,7 @@ await log.DoSafeAsync($"Schema {model.Name} creating", async () => await log.DoVersionedAsync($"Schema {model.Name} updating", version, async () => { - var result = await session.Schemas.PutSchemaSyncAsync(session.App, model.Name, model.Schema); + var result = await session.Client.Schemas.PutSchemaSyncAsync(model.Name, model.Schema); return result.Version; }); diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncService.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncService.cs index f39d345b..b940bee6 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncService.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncService.cs @@ -42,7 +42,7 @@ protected override JsonDictionaryContract CreateDictionaryContract(Type objectTy public SyncService(IFileSystem fileSystem, ISession session) { - Folders = new AssetFolderTree(session.Assets, session.App); + Folders = new AssetFolderTree(session.Client.Assets); jsonSerializerSettings = new JsonSerializerSettings { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs index 7d296b57..eb329ee5 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs @@ -37,9 +37,9 @@ public Task CleanupAsync(IFileSystem fs) public async Task ExportAsync(ISyncService sync, SyncOptions options, ISession session) { - var current = await session.Apps.GetWorkflowsAsync(session.App); + var current = await session.Client.Apps.GetWorkflowsAsync(); - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var schemaMap = schemas.Items.ToDictionary(x => x.Id, x => x.Name); await current.Items.OrderBy(x => x.Name).Foreach(async (workflow, i) => @@ -87,7 +87,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s return; } - var current = await session.Apps.GetWorkflowsAsync(session.App); + var current = await session.Client.Apps.GetWorkflowsAsync(); if (!current.Items.HasDistinctNames(x => x.Name)) { @@ -105,7 +105,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { await log.DoSafeAsync($"Workflow '{name}' deleting", async () => { - await session.Apps.DeleteWorkflowAsync(session.App, workflow.Id); + await session.Client.Apps.DeleteWorkflowAsync(workflow.Id); workflowsByName.Remove(name); }); @@ -132,13 +132,13 @@ await log.DoSafeAsync($"Workflow '{workflow.Name}' creating", async () => Name = workflow.Name }; - var created = await session.Apps.PostWorkflowAsync(session.App, request); + var created = await session.Client.Apps.PostWorkflowAsync(request); workflowsByName[workflow.Name] = created.Items.Find(x => x.Name == workflow.Name); }); } - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); var schemaMap = schemas.Items.ToDictionary(x => x.Name, x => x.Id); foreach (var workflow in models) @@ -154,7 +154,7 @@ await log.DoSafeAsync($"Workflow '{workflow.Name}' creating", async () => await log.DoSafeAsync($"Workflow '{workflow.Name}' updating", async () => { - await session.Apps.PutWorkflowAsync(session.App, existing.Id, workflow); + await session.Client.Apps.PutWorkflowAsync(existing.Id, workflow); }); } } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs index b3882528..3f3953c6 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/ConfigurationService.cs @@ -9,7 +9,6 @@ using Squidex.CLI.Commands.Implementation; using Squidex.CLI.Commands.Implementation.Utils; using Squidex.ClientLibrary; -using Squidex.ClientLibrary.Configuration; namespace Squidex.CLI.Configuration; @@ -168,14 +167,14 @@ public ISession StartSession(string appName, bool emulate = false) { var options = CreateOptions(app, emulate); - return new Session(app.Name, WorkingDirectory, new SquidexClientManager(options)); + return new Session(WorkingDirectory, new SquidexClient(options)); } if (!string.IsNullOrWhiteSpace(configuration.CurrentApp) && configuration.Apps.TryGetValue(configuration.CurrentApp, out app)) { var options = CreateOptions(app, emulate); - return new Session(app.Name, WorkingDirectory, new SquidexClientManager(options)); + return new Session(WorkingDirectory, new SquidexClient(options)); } throw new CLIException("Cannot find valid configuration."); @@ -185,21 +184,17 @@ private static SquidexOptions CreateOptions(ConfiguredApp app, bool emulate) { var options = new SquidexOptions { + IgnoreSelfSignedCertificates = app.IgnoreSelfSigned, AppName = app.Name, ClientId = app.ClientId, ClientSecret = app.ClientSecret, Url = app.ServiceUrl, - HttpClientTimeout = TimeSpan.FromHours(1) + Timeout = TimeSpan.FromHours(1) }; - if (app.IgnoreSelfSigned) - { - options.Configurator = AcceptAllCertificatesConfigurator.Instance; - } - if (emulate) { - options.ClientFactory = new GetOnlyHttpClientFactory(); + options.ClientProvider = new GetOnlyHttpClientProvider(options); } return options; diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClient.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClient.cs index 324a881a..f0b47d8a 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClient.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClient.cs @@ -9,14 +9,10 @@ namespace Squidex.CLI.Configuration; -public sealed class GetOnlyHttpClient : HttpClient +public sealed class GetOnlyHttpMessageHandler : DelegatingHandler { - public GetOnlyHttpClient(HttpMessageHandler messageHandler) - : base(messageHandler) - { - } - - public override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken) + protected override HttpResponseMessage Send(HttpRequestMessage request, + CancellationToken cancellationToken) { if (request.Method != HttpMethod.Get) { @@ -26,7 +22,8 @@ public override HttpResponseMessage Send(HttpRequestMessage request, Cancellatio return base.Send(request, cancellationToken); } - public override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override Task SendAsync(HttpRequestMessage request, + CancellationToken cancellationToken) { if (request.Method != HttpMethod.Get) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientFactory.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientFactory.cs index 7826f7b4..990c8ce0 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientFactory.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/GetOnlyHttpClientFactory.cs @@ -5,19 +5,27 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using Google.Protobuf.WellKnownTypes; +using Squidex.ClientLibrary; using Squidex.ClientLibrary.Configuration; +using Squidex.ClientLibrary.Utils; namespace Squidex.CLI.Configuration; -public sealed class GetOnlyHttpClientFactory : IHttpClientFactory +public sealed class GetOnlyHttpClientProvider : StaticHttpClientProvider { - public HttpClient? CreateHttpClient(HttpMessageHandler messageHandler) + public GetOnlyHttpClientProvider(SquidexOptions options) + : base(options) { - return new GetOnlyHttpClient(messageHandler); } - public HttpMessageHandler? CreateHttpMessageHandler(HttpMessageHandler inner) + protected override HttpMessageHandler CreateMessageHandler(SquidexOptions options) { - return null; + var baseHandler = base.CreateMessageHandler(options); + + return new GetOnlyHttpMessageHandler + { + InnerHandler = baseHandler + }; } } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs index bc1ff860..7962091c 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Configuration/Session.cs @@ -7,87 +7,27 @@ using Squidex.CLI.Commands.Implementation; using Squidex.ClientLibrary; -using Squidex.ClientLibrary.Management; namespace Squidex.CLI.Configuration; public sealed class Session : ISession { - private readonly SquidexClientManager clientManager; - private readonly Dictionary> contents = new Dictionary>(); - private IAppsClient apps; - private IAssetsClient assets; - private IBackupsClient backups; - private ISchemasClient schemas; - private IExtendableRulesClient rules; - - public string App { get; } - public DirectoryInfo WorkingDirectory { get; } - public IAppsClient Apps - { - get => apps ??= clientManager.CreateAppsClient(); - } - - public IAssetsClient Assets - { - get => assets ??= clientManager.CreateAssetsClient(); - } + public ISquidexClient Client { get; } - public IBackupsClient Backups - { - get => backups ??= clientManager.CreateBackupsClient(); - } - - public IExtendableRulesClient Rules - { - get => rules ??= clientManager.CreateExtendableRulesClient(); - } - - public ISchemasClient Schemas - { - get => schemas ??= clientManager.CreateSchemasClient(); - } + public string App => Client.Options.AppName; - public string ClientId - { - get => clientManager.Options.ClientId; - } + public string ClientId => Client.Options.ClientId; - public string ClientSecret - { - get => clientManager.Options.ClientSecret; - } + public string ClientSecret => Client.Options.ClientSecret; - public string Url - { - get => clientManager.Options.Url; - } + public string Url => Client.Options.Url; - public Session(string app, DirectoryInfo workingDirectory, SquidexClientManager clientManager) + public Session(DirectoryInfo workingDirectory, ISquidexClient client) { - App = app; - WorkingDirectory = workingDirectory; - this.clientManager = clientManager; - } - - public IContentsClient Contents(string schemaName) where TEntity : Content where TData : class, new() - { - return clientManager.CreateContentsClient(schemaName); - } - - public IContentsClient Contents(string schemaName) - { - if (!contents.TryGetValue(schemaName, out var client)) - { - client = clientManager.CreateDynamicContentsClient(schemaName); - - contents[schemaName] = client; - } - - return client; + Client = client; } } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs index b356b89d..63c5c13f 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs @@ -35,7 +35,7 @@ public async Task List(ListArguments arguments) { var session = configuration.StartSession(arguments.App); - var apps = await session.Apps.GetAppsAsync(); + var apps = await session.Client.Apps.GetAppsAsync(); if (arguments.Table) { @@ -71,7 +71,7 @@ public async Task Create(CreateArguments arguments) Name = name }; - await session.Apps.PostAppAsync(request); + await session.Client.Apps.PostAppAsync(request); log.WriteLine("> App created."); } @@ -93,7 +93,7 @@ public async Task Delete(DeleteArguments arguments) throw new CLIException("Confirmed app name does not match."); } - await session.Apps.DeleteAppAsync(name); + await session.Client.Apps.DeleteAppAsync(); log.WriteLine("> App deleted."); } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs index e8626c40..14f14b67 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs @@ -38,11 +38,9 @@ public async Task Import(ImportArguments arguments) { var session = configuration.StartSession(arguments.App); - var assets = session.Assets; - using (var fs = await FileSystems.CreateAsync(arguments.Path)) { - var folders = new AssetFolderTree(session.Assets, session.App); + var folders = new AssetFolderTree(session.Client.Assets); var assetQuery = new AssetQuery(); @@ -58,7 +56,7 @@ public async Task Import(ImportArguments arguments) assetQuery.ParentId = await folders.GetIdAsync(targetFolder); assetQuery.Filter = $"fileName eq '{file.Name}'"; - var existings = await assets.GetAssetsAsync(session.App, assetQuery); + var existings = await session.Client.Assets.GetAssetsAsync(assetQuery); var existing = existings.Items.FirstOrDefault(); var fileHash = file.GetFileHash(); @@ -79,13 +77,13 @@ public async Task Import(ImportArguments arguments) } else if (existing != null) { - await assets.PutAssetContentAsync(session.App, existing.Id, fileParameter); + await session.Client.Assets.PutAssetContentAsync(existing.Id, fileParameter); log.StepSuccess("Existing Asset"); } else { - var result = await assets.PostAssetAsync(session.App, assetQuery.ParentId, null, arguments.Duplicate, fileParameter); + var result = await session.Client.Assets.PostAssetAsync(assetQuery.ParentId, null, arguments.Duplicate, fileParameter); if (result._meta?.IsDuplicate == "true") { @@ -116,11 +114,9 @@ public async Task Export(ImportArguments arguments) { var session = configuration.StartSession(arguments.App); - var assets = session.Assets; - using (var fs = await FileSystems.CreateAsync(arguments.Path)) { - var folderTree = new AssetFolderTree(session.Assets, session.App); + var folderTree = new AssetFolderTree(session.Client.Assets); var folderNames = new HashSet(); var parentId = await folderTree.GetIdAsync(arguments.TargetFolder); @@ -148,7 +144,7 @@ public async Task Export(ImportArguments arguments) try { - await assets.GetAllByQueryAsync(session.App, async asset => + await session.Client.Assets.GetAllByQueryAsync(async asset => { await downloadPipeline.DownloadAsync(asset); }, diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs index cdbd3408..bb1dcf31 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs @@ -36,7 +36,7 @@ public async Task Create(CreateArguments arguments) var backupStarted = DateTime.UtcNow.AddMinutes(-5); - await session.Backups.PostBackupAsync(session.App); + await session.Client.Backups.PostBackupAsync(); log.WriteLine("Backup started, waiting for completion..."); @@ -46,7 +46,7 @@ public async Task Create(CreateArguments arguments) { while (!tcs.Token.IsCancellationRequested) { - var backups = await session.Backups.GetBackupsAsync(session.App, tcs.Token); + var backups = await session.Client.Backups.GetBackupsAsync(tcs.Token); var backup = backups.Items.Find(x => x.Started >= backupStarted); if (backup?.Stopped != null) @@ -69,7 +69,7 @@ public async Task Create(CreateArguments arguments) await using (var fs = new FileStream(arguments.File, FileMode.CreateNew)) { - using (var download = await session.Backups.GetBackupContentAsync(session.App, foundBackup.Id)) + using (var download = await session.Client.Backups.GetBackupContentAsync(foundBackup.Id)) { await download.Stream.CopyToAsync(fs); } @@ -79,7 +79,7 @@ public async Task Create(CreateArguments arguments) { log.WriteLine("Removing backup from app..."); - await session.Backups.DeleteBackupAsync(session.App, foundBackup.Id); + await session.Client.Backups.DeleteBackupAsync(foundBackup.Id); } log.WriteLine("> Backup completed and downloaded"); diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs index d7b48d06..0190f263 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Content.cs @@ -42,8 +42,8 @@ public async Task TestData(TestDataArguments arguments) { var session = configuration.StartSession(arguments.App); - var taskForSchema = session.Schemas.GetSchemaAsync(session.App, arguments.Schema); - var taskForLanguages = session.Apps.GetLanguagesAsync(session.App); + var taskForSchema = session.Client.Schemas.GetSchemaAsync(arguments.Schema); + var taskForLanguages = session.Client.Apps.GetLanguagesAsync(); await Task.WhenAll( taskForSchema, diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs index d2e12041..c622315e 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs @@ -39,7 +39,7 @@ public async Task List(ListArguments arguments) { var session = configuration.StartSession(arguments.App); - var schemas = await session.Schemas.GetSchemasAsync(session.App); + var schemas = await session.Client.Schemas.GetSchemasAsync(); if (arguments.Table) { @@ -63,11 +63,11 @@ public async Task Get(GetArguments arguments) { var session = configuration.StartSession(arguments.App); - var schema = await session.Schemas.GetSchemaAsync(session.App, arguments.Name); + var schema = await session.Client.Schemas.GetSchemaAsync(arguments.Name); if (arguments.WithReferencedNames) { - var allSchemas = await session.Schemas.GetSchemasAsync(session.App); + var allSchemas = await session.Client.Schemas.GetSchemasAsync(); var result = new SchemaWithRefs(schema).EnrichSchemaNames(allSchemas.Items); @@ -118,7 +118,7 @@ public async Task Sync(SyncArguments arguments) SchemaDto? targetSchema; try { - targetSchema = await session.Schemas.GetSchemaAsync(session.App, schemaName); + targetSchema = await session.Client.Schemas.GetSchemaAsync(schemaName); } catch { @@ -131,14 +131,14 @@ public async Task Sync(SyncArguments arguments) if (!arguments.NoRefFix && request.ReferencedSchemas.Any()) { - var allSchemas = await session.Schemas.GetSchemasAsync(session.App); + var allSchemas = await session.Client.Schemas.GetSchemasAsync(); request.AdjustReferences(allSchemas.Items); } request.Schema.Name = schemaName; - await session.Schemas.PostSchemaAsync(session.App, request.Schema); + await session.Client.Schemas.PostSchemaAsync(request.Schema); log.WriteLine("> Created schema because it does not exists in the target system."); } @@ -148,7 +148,7 @@ public async Task Sync(SyncArguments arguments) if (!arguments.NoRefFix && request.ReferencedSchemas.Any()) { - var allSchemas = await session.Schemas.GetSchemasAsync(session.App); + var allSchemas = await session.Client.Schemas.GetSchemasAsync(); request.AdjustReferences(allSchemas.Items); } @@ -156,7 +156,7 @@ public async Task Sync(SyncArguments arguments) request.Schema.NoFieldDeletion = arguments.NoFieldDeletion; request.Schema.NoFieldRecreation = arguments.NoFieldRecreation; - await session.Schemas.PutSchemaSyncAsync(session.App, schemaName, request.Schema); + await session.Client.Schemas.PutSchemaSyncAsync(schemaName, request.Schema); log.WriteLine("> Synchronized schema"); } diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs index 0206e5de..e74a46c3 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs @@ -29,7 +29,7 @@ private sealed record AuthorRecord(string Id, AuthorData Author); public AuthorImporter(ISession session, ILogger log) { - client = session.Contents("author"); + client = session.Client.Contents("author"); this.log = log; } diff --git a/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.ReadObjectResponse.liquid b/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.ReadObjectResponse.liquid new file mode 100644 index 00000000..de0451c5 --- /dev/null +++ b/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.ReadObjectResponse.liquid @@ -0,0 +1,58 @@ +protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) +{ + if (response == null || response.Content == null) + { +{%- if GenerateNullableReferenceTypes -%} + return new ObjectResponseResult(default(T)!, string.Empty); +{%- else -%} + return new ObjectResponseResult(default(T), string.Empty); +{%- endif -%} + } + + if (_options.ReadResponseAsString) + { + var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); + try + { + var typedBody = {% if UseSystemTextJson %}System.Text.Json.JsonSerializer.Deserialize{% else %}Newtonsoft.Json.JsonConvert.DeserializeObject{% endif %}(responseText, {% if UseRequestAndResponseSerializationSettings %}Response{% endif %}JsonSerializerSettings); +{%- if GenerateNullableReferenceTypes -%} + return new ObjectResponseResult(typedBody!, responseText); +{%- else -%} + return new ObjectResponseResult(typedBody, responseText); +{%- endif -%} + } + catch ({% if UseSystemTextJson %}System.Text.Json.JsonException{% else %}Newtonsoft.Json.JsonException{% endif %} exception) + { + var message = "Could not deserialize the response body string as " + typeof(T).FullName + "."; + throw new {{ ExceptionClass }}(message, (int)response.StatusCode, responseText, headers, exception); + } + } + else + { + try + { + using (var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false)) +{%- if UseSystemTextJson -%} + { + var typedBody = await System.Text.Json.JsonSerializer.DeserializeAsync(responseStream, {% if UseRequestAndResponseSerializationSettings %}Response{% endif %}JsonSerializerSettings, cancellationToken).ConfigureAwait(false); +{%- else -%} + using (var streamReader = new System.IO.StreamReader(responseStream)) + using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader)) + { + var serializer = Newtonsoft.Json.JsonSerializer.Create({% if UseRequestAndResponseSerializationSettings %}Response{% endif %}JsonSerializerSettings); + var typedBody = serializer.Deserialize(jsonTextReader); +{%- endif -%} +{%- if GenerateNullableReferenceTypes -%} + return new ObjectResponseResult(typedBody!, string.Empty); +{%- else -%} + return new ObjectResponseResult(typedBody, string.Empty); +{%- endif -%} + } + } + catch ({% if UseSystemTextJson %}System.Text.Json.JsonException{% else %}Newtonsoft.Json.JsonException{% endif %} exception) + { + var message = "Could not deserialize the response body stream as " + typeof(T).FullName + "."; + throw new {{ ExceptionClass }}(message, (int)response.StatusCode, string.Empty, headers, exception); + } + } +} \ No newline at end of file diff --git a/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.liquid b/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.liquid index 9af69c6f..cb64bdd6 100644 --- a/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.liquid +++ b/csharp/Squidex.ClientLibrary/CodeGeneration/Client.Class.liquid @@ -5,7 +5,7 @@ {% if UseBaseUrl and GenerateBaseUrlProperty -%} private string _baseUrl = "{{ BaseUrl }}"; {% endif -%} - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; {% if UseRequestAndResponseSerializationSettings -%} private System.Lazy<{{ JsonSerializerSettingsType }}> _requestSettings; private System.Lazy<{{ JsonSerializerSettingsType }}> _responseSettings; @@ -13,9 +13,9 @@ private System.Lazy<{{ JsonSerializerSettingsType }}> _settings; {% endif -%} - public {{ Class }}(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public {{ Class }}(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; {% if UseRequestAndResponseSerializationSettings -%} _requestSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(true)); _responseSettings = new System.Lazy<{{ JsonSerializerSettingsType }}>(() => CreateSerializerSettings(false)); @@ -119,6 +119,7 @@ {% endif -%} var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append({% if UseBaseUrl %}BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/{% else %}"{% endif %}{{ operation.Path }}{% if operation.HasQueryParameters %}?{% endif %}"); + urlBuilder_.Replace("{app}", _options.AppName); {% for parameter in operation.PathParameters -%} {% if parameter.IsOptional -%} if ({{ parameter.VariableName }} != null) @@ -143,7 +144,7 @@ urlBuilder_.Length--; {% endif -%} - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { {% if UseHttpRequestMessageCreationMethod -%} @@ -152,12 +153,6 @@ using (var request_ = new System.Net.Http.HttpRequestMessage()) {% endif -%} { -{% for parameter in operation.Parameters %} -{% if parameter.VariableName == "app" %} - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); -{% endif -%} -{% endfor -%} - {% for parameter in operation.HeaderParameters %} {% if parameter.IsRequired -%} if ({{ parameter.VariableName }} == null) @@ -365,7 +360,6 @@ } finally { - _httpClientProvider.Return(client_); } } diff --git a/csharp/Squidex.ClientLibrary/CodeGeneration/CodeGeneration.csproj b/csharp/Squidex.ClientLibrary/CodeGeneration/CodeGeneration.csproj index 1393ab7d..bfacfa04 100644 --- a/csharp/Squidex.ClientLibrary/CodeGeneration/CodeGeneration.csproj +++ b/csharp/Squidex.ClientLibrary/CodeGeneration/CodeGeneration.csproj @@ -22,6 +22,9 @@ + + Always + Always diff --git a/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs b/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs index 49c3dcf2..5a5a70ff 100644 --- a/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs +++ b/csharp/Squidex.ClientLibrary/CodeGeneration/Program.cs @@ -18,9 +18,22 @@ namespace CodeGeneration; public static class Program { - public static void Main() + public static async Task Main() { - var document = OpenApiDocument.FromUrlAsync("https://localhost:5001/api/swagger/v1/swagger.json").Result; + var document = await OpenApiDocument.FromUrlAsync("https://localhost:5001/api/swagger/v1/swagger.json"); + + foreach (var operation in document.Operations) + { + var parameters = operation.Operation.Parameters; + + foreach (var parameter in parameters.ToList()) + { + if (parameter.Kind == OpenApiParameterKind.Path && parameter.Name == "app") + { + parameters.Remove(parameter); + } + } + } var generatorSettings = new CSharpClientGeneratorSettings(); generatorSettings.ExceptionClass = "SquidexManagementException"; diff --git a/csharp/Squidex.ClientLibrary/Directory.Build.props b/csharp/Squidex.ClientLibrary/Directory.Build.props index 803965c8..5fb9305b 100644 --- a/csharp/Squidex.ClientLibrary/Directory.Build.props +++ b/csharp/Squidex.ClientLibrary/Directory.Build.props @@ -15,7 +15,7 @@ Squidex HeadlessCMS true snupkg - 14.2.0 + 15.0.0 diff --git a/csharp/Squidex.ClientLibrary/README.md b/csharp/Squidex.ClientLibrary/README.md index 8a795357..973d3239 100644 --- a/csharp/Squidex.ClientLibrary/README.md +++ b/csharp/Squidex.ClientLibrary/README.md @@ -6,70 +6,4 @@ Also available on [nuget.org](https://www.nuget.org/packages/Squidex.ClientLibra ## How to use it? -Our recommendation is to have a look to the other samples to see how it works, but here is a short introduction. - -The client library uses the following namespace: `Squidex.ClientLibrary` - -### 1. Create your model. - -For each schema you have to create two classes. - -1. The data object: - -```` -public sealed class BlogPostData -{ - // Squidex delivers hash maps for each field, but the - // InvariantConverter helps to simplify the model. - [JsonConverter(typeof(InvariantConverter))] - public string Title { get; set; } - - [JsonConverter(typeof(InvariantConverter))] - public string Slug { get; set; } - - // For localizable fields you can use dictionaries. - public Dictionary Text { get; set; } -} -```` - -2. The entity object - -```` -public sealed class BlogPost : Content -{ -} -```` - - -### 2. Initialize the client manager - -```` -var clientManager = - new SquidexClientManager( - new SquidexOptions - { - AppName = "...", - ClientId = "...", - ClientSecret = "...", - Url = "https://cloud.squidex.io" - }); -```` - -### 3. Create a client for your schema - -```` -var client = clientManager.CreateContentsClient("posts"); -```` - -### 4. Use the client - -```` -// Read posts pages -var posts = await client.GetAsync(page * pageSize, pageSize); - -// Read post by id. -var post = client.GetAsync(id); - -// Read posts by slug. -var posts = await client.GetAsync(filter: $"data/slug/iv eq '{slug}'"); -```` \ No newline at end of file +Go to the documentation for installation and usage instructions: https://docs.squidex.io/02-documentation/software-development-kits/.net-standard \ No newline at end of file diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs index a1f0a299..ac053f56 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/HttpClientProvider.cs @@ -9,36 +9,13 @@ namespace Squidex.ClientLibrary.ServiceExtensions; -/// -/// Default http client provider, that works as wrapper over . -/// -public sealed class HttpClientProvider : IHttpClientProvider +internal sealed class HttpClientProvider : IHttpClientProvider { private readonly Func factory; - /// - /// Initializes a new instance of the class with the wrapped see. - /// - /// The wrapped . Cannot be null. - /// The logical name of the client to create. Cannot be null. - /// is null. - /// is null. - public HttpClientProvider(System.Net.Http.IHttpClientFactory httpClientFactory, string httpClientName) + public HttpClientProvider(Func factory) { - if (httpClientFactory == null) - { - throw new ArgumentNullException(nameof(httpClientFactory)); - } - - if (httpClientName == null) - { - throw new ArgumentNullException(nameof(httpClientName)); - } - - factory = () => - { - return httpClientFactory.CreateClient(httpClientName); - }; + this.factory = factory; } /// @@ -46,9 +23,4 @@ public HttpClient Get() { return factory(); } - - /// - public void Return(HttpClient httpClient) - { - } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/ISquidexClientFactory.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/ISquidexClientFactory.cs new file mode 100644 index 00000000..e94068a2 --- /dev/null +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/ISquidexClientFactory.cs @@ -0,0 +1,31 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +namespace Squidex.ClientLibrary.ServiceExtensions; + +/// +/// Provides a client. +/// +public interface ISquidexClientProvider +{ + /// + /// Gets the default client. + /// + /// + /// The default client. + /// + ISquidexClient Get(); + + /// + /// Gets the client with the given name. + /// + /// The client name. + /// + /// The client with the given name. + /// + ISquidexClient Get(string name); +} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientLibraryServiceExtensions.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientLibraryServiceExtensions.cs index a9383a05..9d688b26 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientLibraryServiceExtensions.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientLibraryServiceExtensions.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Http; using Microsoft.Extensions.Options; -using Squidex.ClientLibrary; using Squidex.ClientLibrary.ServiceExtensions; using Squidex.ClientLibrary.Utils; @@ -21,58 +20,48 @@ namespace Microsoft.Extensions.DependencyInjection; public static class SquidexClientLibraryServiceExtensions { /// - /// The name of the HTTP client. + /// Adds the Squidex client manager to the service collection. /// - public const string ClientName = "SquidexClient"; + /// The service collection. + /// A callback to configure Squidex. + /// The service collection that was passed in. + public static IServiceCollection AddSquidexClient(this IServiceCollection services, Action? configure = null) + { + return services.AddSquidexClient(Options.Options.DefaultName, configure); + } /// /// Adds the Squidex client manager to the service collection. /// /// The service collection. + /// The name of the client. /// A callback to configure Squidex. /// The service collection that was passed in. - public static IServiceCollection AddSquidexClient(this IServiceCollection services, Action? configure) + public static IServiceCollection AddSquidexClient(this IServiceCollection services, string name, Action? configure = null) { if (configure != null) { - services.Configure(configure); + services.Configure(name, configure); } - services.AddOptions() - .PostConfigure((options, c) => + services.AddOptions(name) + .PostConfigure((options, c) => { - options.ClientProvider = new HttpClientProvider(c.GetRequiredService(), ClientName); + var clientName = ClientName(name); + + options.ClientProvider = new HttpClientProvider(() => c.CreateClient(clientName)); }); services.TryAddSingleton, - OptionsValidator>(); - - AddSquidexHttpClient(services, null); - - services.TryAddSingleton( - c => new SquidexClientManager(c.GetRequiredService>().Value)); - - services.AddSquidexClient(m => m.CreateAppsClient()); - services.AddSquidexClient(m => m.CreateAssetsClient()); - services.AddSquidexClient(m => m.CreateBackupsClient()); - services.AddSquidexClient(m => m.CreateCommentsClient()); - services.AddSquidexClient(m => m.CreateDiagnosticsClient()); - services.AddSquidexClient(m => m.CreateEventConsumersClient()); - services.AddSquidexClient(m => m.CreateExtendableRulesClient()); - services.AddSquidexClient(m => m.CreateCommentsClient()); - services.AddSquidexClient(m => m.CreateHistoryClient()); - services.AddSquidexClient(m => m.CreateLanguagesClient()); - services.AddSquidexClient(m => m.CreatePingClient()); - services.AddSquidexClient(m => m.CreatePlansClient()); - services.AddSquidexClient(m => m.CreateRulesClient()); - services.AddSquidexClient(m => m.CreateSchemasClient()); - services.AddSquidexClient(m => m.CreateSearchClient()); - services.AddSquidexClient(m => m.CreateStatisticsClient()); - services.AddSquidexClient(m => m.CreateTeamsClient()); - services.AddSquidexClient(m => m.CreateTemplatesClient()); - services.AddSquidexClient(m => m.CreateTranslationsClient()); - services.AddSquidexClient(m => m.CreateUserManagementClient()); - services.AddSquidexClient(m => m.CreateUsersClient()); + SquidexOptionsValidator>(); + + services.TryAddSingleton(); + + services.TryAddSingleton( + c => c.GetRequiredService().Get()); + + services.AddSquidexHttpClient(name); return services; } @@ -80,32 +69,30 @@ public static IServiceCollection AddSquidexClient(this IServiceCollection servic /// /// Adds the Squidex client to the service collection. /// - /// The service collection. - /// A callback to provider the client from the manager. - /// The service collection that was passed in. - /// The type of the client to register. - public static IServiceCollection AddSquidexClient(this IServiceCollection services, Func provider) where TClient : class + /// The service collection to configure. + /// The callback to configure the HTTP client. + /// The http client builder to make more customizatons. + public static IHttpClientBuilder AddSquidexHttpClient(this IServiceCollection services, Action? configure = null) { - services.TryAddSingleton(c => provider(c.GetRequiredService())); - - return services; + return services.AddSquidexHttpClient(Options.Options.DefaultName, configure); } /// /// Adds the Squidex client to the service collection. /// /// The service collection to configure. + /// The name of the client. /// The callback to configure the HTTP client. /// The http client builder to make more customizatons. - public static IHttpClientBuilder AddSquidexHttpClient(this IServiceCollection services, Action? configure = null) + public static IHttpClientBuilder AddSquidexHttpClient(this IServiceCollection services, string name, Action? configure = null) { - return services.AddHttpClient(ClientName, (c, httpClient) => + return services.AddHttpClient(ClientName(name), (c, httpClient) => { - var options = c.GetRequiredService>().Value; + var options = c.GetRequiredService>().Get(name); - if (options.ConfigureHttpClientWithTimeout) + if (options.ConfigureHttpClientWithTimeout && options.Timeout != null) { - httpClient.Timeout = options.HttpClientTimeout; + httpClient.Timeout = options.Timeout.Value; } if (options.ConfigureHttpClientWithUrl) @@ -133,7 +120,7 @@ public static void AddSquidexAuthenticatorAsAdditionalHandler(this HttpMessageHa { var options = builder.Services.GetRequiredService>().Value; - builder.AdditionalHandlers.Add(new AuthenticatingHttpMessageHandler(options.Authenticator)); + builder.AdditionalHandlers.Add(new AuthenticatingHttpMessageHandler(options)); } /// @@ -144,6 +131,11 @@ public static void SetSquidexAuthenticatorAsPrimaryHandler(this HttpMessageHandl { var options = builder.Services.GetRequiredService>().Value; - builder.PrimaryHandler = new AuthenticatingHttpMessageHandler(options.Authenticator); + builder.PrimaryHandler = new AuthenticatingHttpMessageHandler(options); + } + + internal static string ClientName(string name) + { + return $"SquidexHttpClient_{name}"; } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs new file mode 100644 index 00000000..1c94fd49 --- /dev/null +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexClientProvider.cs @@ -0,0 +1,37 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Collections.Concurrent; +using Microsoft.Extensions.Options; + +namespace Squidex.ClientLibrary.ServiceExtensions; + +internal sealed class SquidexClientProvider : ISquidexClientProvider +{ + private readonly ConcurrentDictionary clients = new ConcurrentDictionary(); + private readonly IOptionsMonitor optionsMonitor; + + public SquidexClientProvider(IOptionsMonitor optionsMonitor) + { + this.optionsMonitor = optionsMonitor; + } + + public ISquidexClient Get() + { + return Get(Options.DefaultName); + } + + public ISquidexClient Get(string name) + { + return clients.GetOrAdd(name, (name, optionsMonitor) => + { + var options = optionsMonitor.Get(name); + + return new SquidexClient(options); + }, optionsMonitor); + } +} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/OptionsValidator.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexOptionsValidator.cs similarity index 90% rename from csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/OptionsValidator.cs rename to csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexOptionsValidator.cs index c1453099..a57a4436 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/OptionsValidator.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.ServiceExtensions/SquidexOptionsValidator.cs @@ -9,7 +9,7 @@ namespace Squidex.ClientLibrary.ServiceExtensions; -internal sealed class OptionsValidator : IValidateOptions +internal sealed class SquidexOptionsValidator : IValidateOptions { public ValidateOptionsResult Validate(string? name, SquidexServiceOptions options) { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/AssetFolderTreeTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/AssetFolderTreeTests.cs index b51e18d2..a9052dab 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/AssetFolderTreeTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/AssetFolderTreeTests.cs @@ -19,7 +19,7 @@ public class AssetFolderTreeTests public AssetFolderTreeTests() { - sut = new AssetFolderTree(assets, "my-app"); + sut = new AssetFolderTree(assets); } [Theory] @@ -54,7 +54,7 @@ public async Task Should_query_for_path_once_for_each_subtree() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", folder1.Id, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(folder1.Id, A._, A._)) .Returns(new AssetFoldersDto { Items = new List(), @@ -64,7 +64,7 @@ public async Task Should_query_for_path_once_for_each_subtree() } }); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", folder2.Id, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(folder2.Id, A._, A._)) .Returns(new AssetFoldersDto { Items = new List(), @@ -77,7 +77,7 @@ public async Task Should_query_for_path_once_for_each_subtree() Assert.Equal("folder1", await sut.GetPathAsync(folder1.Id)); Assert.Equal("folder2", await sut.GetPathAsync(folder2.Id)); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedTwiceExactly(); } @@ -98,7 +98,7 @@ public async Task Should_not_query_for_path_again_if_child_already_queried() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", folder2.Id, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(folder2.Id, A._, A._)) .Returns(new AssetFoldersDto { Items = new List(), @@ -112,7 +112,7 @@ public async Task Should_not_query_for_path_again_if_child_already_queried() Assert.Equal("folder1/folder2", await sut.GetPathAsync(folder2.Id)); Assert.Equal("folder1", await sut.GetPathAsync(folder1.Id)); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedOnceExactly(); } @@ -133,7 +133,7 @@ public async Task Should_not_query_for_path_again_if_parent_already_queried() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", folder1.Id, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(folder1.Id, A._, A._)) .Returns(new AssetFoldersDto { Items = new List @@ -149,7 +149,7 @@ public async Task Should_not_query_for_path_again_if_parent_already_queried() Assert.Equal("folder1", await sut.GetPathAsync(folder1.Id)); Assert.Equal("folder1/folder2", await sut.GetPathAsync(folder2.Id)); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedOnceExactly(); } @@ -170,7 +170,7 @@ public async Task Should_query_for_id_once_for_each_tree_item() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", RootId, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(RootId, A._, A._)) .Returns(new AssetFoldersDto { Items = new List @@ -184,7 +184,7 @@ public async Task Should_query_for_id_once_for_each_tree_item() Assert.Equal(folder1.Id, await sut.GetIdAsync("folder1")); Assert.Equal(folder2.Id, await sut.GetIdAsync("folder2")); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedOnceExactly(); } @@ -205,7 +205,7 @@ public async Task Should_not_query_for_id_again_if_parent_already_queried() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", folder1.Id, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(folder1.Id, A._, A._)) .Returns(new AssetFoldersDto { Items = new List @@ -221,7 +221,7 @@ public async Task Should_not_query_for_id_again_if_parent_already_queried() Assert.Equal("folder1", await sut.GetPathAsync(folder1.Id)); Assert.Equal("folder1/folder2", await sut.GetPathAsync(folder2.Id)); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedOnceExactly(); } @@ -242,7 +242,7 @@ public async Task Should_query_for_id_once_and_create_new_folder() FolderName = "folder2" }; - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", RootId, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(RootId, A._, A._)) .Returns(new AssetFoldersDto { Items = new List @@ -252,7 +252,7 @@ public async Task Should_query_for_id_once_and_create_new_folder() Path = new List() }); - A.CallTo(() => assets.PostAssetFolderAsync("my-app", + A.CallTo(() => assets.PostAssetFolderAsync( A.That.Matches(x => x.FolderName == "folder2" && x.ParentId == RootId), A._)) .Returns(folder2); @@ -260,7 +260,7 @@ public async Task Should_query_for_id_once_and_create_new_folder() Assert.Equal(folder1.Id, await sut.GetIdAsync("folder1")); Assert.Equal(folder2.Id, await sut.GetIdAsync("folder2")); - A.CallTo(() => assets.GetAssetFoldersAsync("my-app", A._, A._, A._)) + A.CallTo(() => assets.GetAssetFoldersAsync(A._, A._, A._)) .MustHaveHappenedOnceExactly(); } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientServiceTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientServiceTests.cs index afb69a39..99dfe824 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientServiceTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientServiceTests.cs @@ -17,22 +17,12 @@ public async Task Should_query_content() { var sut = CreateSut(); - var result = await sut.CreateDynamicContentsClient("blog").GetAsync(); + var result = await sut.DynamicContents("blog").GetAsync(); Assert.NotEmpty(result.Items); } - [Fact] - public async Task Should_query_content_with_overriden_credentials() - { - var sut = CreateSutWithOverridenCredentials(); - - var result = await sut.CreateDynamicContentsClient("blog").GetAsync(); - - Assert.NotEmpty(result.Items); - } - - private static ISquidexClientManager CreateSut() + private static ISquidexClient CreateSut() { var sut = new ServiceCollection() @@ -44,32 +34,7 @@ private static ISquidexClientManager CreateSut() options.Url = "https://cloud.squidex.io"; }) .BuildServiceProvider() - .GetRequiredService(); - - return sut; - } - - private static ISquidexClientManager CreateSutWithOverridenCredentials() - { - var sut = - new ServiceCollection() - .AddSquidexClient(options => - { - options.AppName = "squidex-website"; - options.ClientId = "INVALID"; - options.ClientSecret = "INVALID"; - options.AppCredentials = new Dictionary - { - ["squidex-website"] = new AppCredentials - { - ClientId = "squidex-website:default", - ClientSecret = "QGgqxd7bDHBTEkpC6fj8sbdPWgZrPrPfr3xzb3LKoec=", - } - }; - options.Url = "https://cloud.squidex.io"; - }) - .BuildServiceProvider() - .GetRequiredService(); + .GetRequiredService(); return sut; } @@ -97,13 +62,13 @@ public async Task Should_not_try_authenticate_again_if_it_failed(int retryHours, return counts; }).Services .BuildServiceProvider() - .GetRequiredService(); + .GetRequiredService(); for (var i = 0; i < 10; i++) { try { - await sut.CreatePingClient().GetAppPingAsync("app"); + await sut.Ping.GetAppPingAsync(); } catch { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientTests.cs index 6825696d..fc0a52e8 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/BasicClientTests.cs @@ -12,11 +12,11 @@ namespace Squidex.ClientLibrary.Tests; public class BasicClientTests { - private readonly ISquidexClientManager sut; + private readonly ISquidexClient sut; public BasicClientTests() { - sut = new SquidexClientManager(new SquidexOptions + sut = new SquidexClient(new SquidexOptions { AppName = "squidex-website", ClientId = "squidex-website:reader", @@ -27,23 +27,19 @@ public BasicClientTests() [Fact(Skip = "No permissions.")] public async Task Should_make_ping_api_request() { - var pingClient = sut.CreatePingClient(); - - await pingClient.GetAppPingAsync("squidex-website"); + await sut.Ping.GetAppPingAsync(); } [Fact] public async Task Should_make_ping_request() { - var pingClient = sut.CreatePingClient(); - - await pingClient.GetPingAsync(); + await sut.Ping.GetPingAsync(); } [Fact] public async Task Should_get_content() { - var result = await sut.CreateDynamicContentsClient("blog").GetAsync(); + var result = await sut.DynamicContents("blog").GetAsync(); Assert.NotEmpty(result.Items); } @@ -53,7 +49,7 @@ public async Task Should_get_content_with_invalid_token() { ((CachingAuthenticator)sut.Options.Authenticator).SetToCache(sut.Options.AppName, "TOKEN", DateTime.MaxValue); - var result = await sut.CreateDynamicContentsClient("blog").GetAsync(); + var result = await sut.DynamicContents("blog").GetAsync(); Assert.NotEmpty(result.Items); } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexClientManagerTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexClientManagerTests.cs index 24d5993e..9683a486 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexClientManagerTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexClientManagerTests.cs @@ -6,16 +6,15 @@ // ========================================================================== using Microsoft.Extensions.DependencyInjection; +using Squidex.ClientLibrary.ServiceExtensions; using Xunit; namespace Squidex.ClientLibrary.Tests; public class SquidexClientManagerTests { - [Theory] - [InlineData("https://cloud.squidex.io")] - [InlineData("https://cloud.squidex.io/")] - public void Should_build_client_manager_from_service(string url) + [Fact] + public void Should_build_client_from_service() { var sut = new ServiceCollection() @@ -23,15 +22,62 @@ public void Should_build_client_manager_from_service(string url) { options.AppName = "app"; options.ClientId = "id"; - options.ClientSecret = "secet"; - options.Url = url; + options.ClientSecret = "secret"; + options.Url = "https://custom.squidex.io"; }) .BuildServiceProvider() - .GetRequiredService(); + .GetRequiredService(); - var result = sut.GenerateUrl("relative/url"); + Assert.Equal("https://custom.squidex.io/", sut.Options.Url); + } - Assert.Equal("https://cloud.squidex.io/relative/url", result); + [Fact] + public void Should_build_client_from_service_with_custom_options() + { + var sut = + new ServiceCollection() + .AddSquidexClient(null) + .Configure(options => + { + options.AppName = "app"; + options.ClientId = "id"; + options.ClientSecret = "secret"; + options.Url = "https://custom.squidex.io"; + }) + .BuildServiceProvider() + .GetRequiredService(); + + Assert.Equal("https://custom.squidex.io/", sut.Options.Url); + } + + [Fact] + public void Should_build_client_from_named_service() + { + var provider = + new ServiceCollection() + .AddSquidexClient(null) + .Configure(options => + { + options.AppName = "app"; + options.ClientId = "id"; + options.ClientSecret = "secret"; + options.Url = "https://custom1.squidex.io"; + }) + .Configure("named", options => + { + options.AppName = "app"; + options.ClientId = "id"; + options.ClientSecret = "secret"; + options.Url = "https://custom2.squidex.io"; + }) + .BuildServiceProvider() + .GetRequiredService(); + + var sut1 = provider.Get(); + var sut2 = provider.Get("named"); + + Assert.Equal("https://custom1.squidex.io/", sut1.Options.Url); + Assert.Equal("https://custom2.squidex.io/", sut2.Options.Url); } [Theory] @@ -122,19 +168,19 @@ public void Should_throw_exception_if_asset_cdn_not_configured() Assert.Throws(() => sut.GenerateAssetCDNUrl("relative/url")); } - private static SquidexClientManager BuildClientManager(Action? configure = null) + private static SquidexClient BuildClientManager(Action? configure = null) { var options = new SquidexOptions { AppName = "app", ClientId = "id", - ClientSecret = "secet", + ClientSecret = "secret", Url = "https://squidex.io" }; configure?.Invoke(options); - var sut = new SquidexClientManager(options); + var sut = new SquidexClient(options); return sut; } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexOptionsTests.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexOptionsTests.cs index fd2f5886..bafc72ff 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexOptionsTests.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary.Tests/SquidexOptionsTests.cs @@ -30,10 +30,5 @@ public void Should_bind_to_config() Assert.Equal("My-App", options.AppName); Assert.Equal("My-ClientId", options.ClientId); Assert.Equal("My-ClientSecret", options.ClientSecret); - - var appCredentials = options.AppCredentials!["My-App2"]; - - Assert.Equal("My-ClientId2", appCredentials.ClientId); - Assert.Equal("My-ClientSecret2", appCredentials.ClientSecret); } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AppCredentials.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AppCredentials.cs deleted file mode 100644 index feea6b3a..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AppCredentials.cs +++ /dev/null @@ -1,68 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary; - -/// -/// Application specific credentials. -/// -public sealed class AppCredentials : OptionsBase -{ - private string clientId; - private string clientSecret; - - /// - /// Gets or sets the client identifier. - /// - /// - /// The client identifier. This is a required option. - /// - /// Option is frozen and cannot be changed anymore. - public string ClientId - { - get => clientId; - set => Set(ref clientId, value); - } - - /// - /// Gets or sets the client secret. - /// - /// - /// The client secret. This is a required option. - /// - /// Option is frozen and cannot be changed anymore. - public string ClientSecret - { - get => clientSecret; - set => Set(ref clientSecret, value); - } - - /// - /// Validates the options. - /// - public void CheckAndFreeze() - { - if (IsFrozen) - { - return; - } - -#pragma warning disable MA0015 // Specify the parameter name in ArgumentException - if (string.IsNullOrWhiteSpace(clientId)) - { - throw new ArgumentException("Client id is not defined.", nameof(ClientId)); - } - - if (string.IsNullOrWhiteSpace(clientSecret)) - { - throw new ArgumentException("Client secret is not defined.", nameof(ClientSecret)); - } - - Freeze(); -#pragma warning restore MA0015 // Specify the parameter name in ArgumentException - } -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetFolderTree.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetFolderTree.cs index afde1b21..135cc88d 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetFolderTree.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/AssetFolderTree.cs @@ -20,23 +20,19 @@ public sealed class AssetFolderTree private static readonly string RootId = Guid.Empty.ToString(); private readonly Dictionary nodes = new Dictionary(); private readonly IAssetsClient assetsClient; - private readonly string appName; private readonly AssetFolderNode rootNode = new AssetFolderNode(RootId, string.Empty, string.Empty); /// /// Initializes a new instance of the class. /// /// The assets client. Cannot be null. - /// The app name. Cannot be null. - public AssetFolderTree(IAssetsClient assetsClient, string appName) + public AssetFolderTree(IAssetsClient assetsClient) { Guard.NotNull(assetsClient, nameof(assetsClient)); - Guard.NotNull(appName, nameof(appName)); nodes[RootId] = rootNode; this.assetsClient = assetsClient; - this.appName = appName; } /// @@ -140,7 +136,7 @@ private async Task AddFolderAsync(AssetFolderNode current, stri ParentId = current.Id }; - var folder = await assetsClient.PostAssetFolderAsync(appName, request); + var folder = await assetsClient.PostAssetFolderAsync(request); current = TryAdd(current, folder.Id, name); current.HasBeenQueried = true; @@ -155,7 +151,7 @@ private async Task QueryAsync(string id, bool needsChildren) return node; } - var folders = await assetsClient.GetAssetFoldersAsync(appName, id); + var folders = await assetsClient.GetAssetFoldersAsync(id); var current = rootNode; diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/AcceptAllCertificatesConfigurator.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/AcceptAllCertificatesConfigurator.cs deleted file mode 100644 index 6ded8451..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/AcceptAllCertificatesConfigurator.cs +++ /dev/null @@ -1,35 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary.Configuration; - -/// -/// Configures the HTTP client to accept all SSL certificates. -/// -/// -public sealed class AcceptAllCertificatesConfigurator : IHttpConfigurator -{ - /// - /// The only instance of this class. - /// - public static readonly AcceptAllCertificatesConfigurator Instance = new AcceptAllCertificatesConfigurator(); - - private AcceptAllCertificatesConfigurator() - { - } - - /// - public void Configure(HttpClient httpClient) - { - } - - /// - public void Configure(HttpClientHandler httpClientHandler) - { - httpClientHandler.ServerCertificateCustomValidationCallback += (message, certificate, chain, errors) => true; - } -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/Authenticator.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/Authenticator.cs index 7771711b..8ea44652 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/Authenticator.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/Authenticator.cs @@ -56,43 +56,31 @@ public async Task GetBearerTokenAsync(string appName, CancellationToken ct) { var httpClient = options.ClientProvider.Get(); - try - { - var clientId = options.ClientId; - var clientSecret = options.ClientSecret; - if (options.AppCredentials != null && options.AppCredentials.TryGetValue(appName, out var credentials)) - { - clientId = credentials.ClientId; - clientSecret = credentials.ClientSecret; - } + var clientId = options.ClientId; + var clientSecret = options.ClientSecret; - ThrowFromPreviousAttempt(clientId, clientSecret); + ThrowFromPreviousAttempt(clientId, clientSecret); - var httpRequest = BuildRequest(clientId, clientSecret); + var httpRequest = BuildRequest(clientId, clientSecret); - using (var response = await httpClient.SendAsync(httpRequest, ct)) + using (var response = await httpClient.SendAsync(httpRequest, ct)) + { + if (!response.IsSuccessStatusCode) { - if (!response.IsSuccessStatusCode) - { - var exception = new SecurityException($"Failed to retrieve access token for client '{options.ClientId}', got HTTP {response.StatusCode}."); + var exception = new SecurityException($"Failed to retrieve access token for client '{options.ClientId}', got HTTP {response.StatusCode}."); - StorePreviousAttempt(clientId, clientSecret, exception); - throw exception; - } + StorePreviousAttempt(clientId, clientSecret, exception); + throw exception; + } #if NET5_0_OR_GREATER - var jsonString = await response.Content.ReadAsStringAsync(ct); + var jsonString = await response.Content.ReadAsStringAsync(ct); #else - var jsonString = await response.Content.ReadAsStringAsync(); + var jsonString = await response.Content.ReadAsStringAsync(); #endif - var jsonToken = JToken.Parse(jsonString); + var jsonToken = JToken.Parse(jsonString); - return jsonToken["access_token"]!.ToString(); - } - } - finally - { - options.ClientProvider.Return(httpClient); + return jsonToken["access_token"]!.ToString(); } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/GlobalContextClientFactory.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/GlobalContextClientFactory.cs deleted file mode 100644 index c0b41c00..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/GlobalContextClientFactory.cs +++ /dev/null @@ -1,58 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary.Configuration; - -/// -/// A that adds the context options to all requests. -/// -/// -public sealed class GlobalContextClientFactory : IHttpClientFactory -{ - private readonly QueryContext context; - - private sealed class ApplyHeadersHandler : DelegatingHandler - { - private readonly QueryContext context; - - public ApplyHeadersHandler(QueryContext context) - { - this.context = context; - } - - protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) - { - context?.AddToHeaders(request.Headers); - - return base.SendAsync(request, cancellationToken); - } - } - - /// - /// Initializes a new instance of the class with the context to apply. - /// - /// The context to apply. - public GlobalContextClientFactory(QueryContext context) - { - this.context = context; - } - - /// - public HttpMessageHandler? CreateHttpMessageHandler(HttpMessageHandler inner) - { - return new ApplyHeadersHandler(context) - { - InnerHandler = inner - }; - } - - /// - public HttpClient? CreateHttpClient(HttpMessageHandler messageHandler) - { - return null; - } -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientFactory.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientFactory.cs deleted file mode 100644 index d81dfd00..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientFactory.cs +++ /dev/null @@ -1,35 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary.Configuration; - -/// -/// Optional interface to create new instances. -/// -/// -/// Implement this class if you have custom requirements how the HTTP requests need to be done. -/// -public interface IHttpClientFactory -{ - /// - /// Creates the HTTP client from the message. - /// - /// The message handler. - /// - /// The HTTP client. - /// - HttpClient? CreateHttpClient(HttpMessageHandler messageHandler); - - /// - /// Creates the HTTP message handler from the inner handler. - /// - /// The inner handler. - /// - /// The HTTP message handler. - /// - HttpMessageHandler? CreateHttpMessageHandler(HttpMessageHandler inner); -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientProvider.cs index 15f40d33..b64b7192 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientProvider.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpClientProvider.cs @@ -22,10 +22,4 @@ public interface IHttpClientProvider /// The HTTP client. /// HttpClient Get(); - - /// - /// Return a HTTP client. - /// - /// The HTTP client to release. - void Return(HttpClient httpClient); } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpConfigurator.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpConfigurator.cs deleted file mode 100644 index 479fd525..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/IHttpConfigurator.cs +++ /dev/null @@ -1,26 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary.Configuration; - -/// -/// Implement this interface to change the behavior of HTTP requests. -/// -public interface IHttpConfigurator -{ - /// - /// Configures the specified HTTP client. - /// - /// The HTTP client to configure. - void Configure(HttpClient httpClient); - - /// - /// Configures the specified HTTP client handler. - /// - /// The HTTP client handler to configure. - void Configure(HttpClientHandler httpClientHandler); -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/NoopHttpConfigurator.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/NoopHttpConfigurator.cs deleted file mode 100644 index 3c1b4f42..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/NoopHttpConfigurator.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary.Configuration; - -/// -/// Default implementation of the and that does -/// not do anything and provides the default behavior. -/// -/// -/// -public sealed class NoopHttpConfigurator : IHttpConfigurator, IHttpClientFactory -{ - /// - /// The only instance of this class. - /// - public static readonly NoopHttpConfigurator Instance = new NoopHttpConfigurator(); - - private NoopHttpConfigurator() - { - } - - /// - public void Configure(HttpClient httpClient) - { - } - - /// - public void Configure(HttpClientHandler httpClientHandler) - { - } - - /// - public HttpClient? CreateHttpClient(HttpMessageHandler messageHandler) - { - return null; - } - - /// - public HttpMessageHandler? CreateHttpMessageHandler(HttpMessageHandler inner) - { - return inner; - } -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/StaticHttpClientProvider.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/StaticHttpClientProvider.cs index f34fb673..37a9af2f 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/StaticHttpClientProvider.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Configuration/StaticHttpClientProvider.cs @@ -12,9 +12,10 @@ namespace Squidex.ClientLibrary.Configuration; /// /// Provides a static instance. /// -public sealed class StaticHttpClientProvider : IHttpClientProvider +public class StaticHttpClientProvider : IHttpClientProvider { - private readonly HttpClient staticHttpClient; + private readonly SquidexOptions options; + private HttpClient? staticHttpClient; /// /// Initializes a new instance of the class. @@ -24,45 +25,60 @@ public StaticHttpClientProvider(SquidexOptions options) { Guard.NotNull(options, nameof(options)); - staticHttpClient = CreateClient(options); + this.options = options; } - private static HttpClient CreateClient(SquidexOptions options) + /// + /// Creates the client from the options. + /// + /// The options. + /// + /// The created HTTP client. + /// + protected virtual HttpClient CreateHttpClient(SquidexOptions options) { - var handler = new HttpClientHandler(); + var messageHandler = CreateMessageHandler(options); - options.Configurator.Configure(handler); - - HttpMessageHandler messageHandler = new AuthenticatingHttpMessageHandler(options.Authenticator) + var httpClient = new HttpClient(messageHandler, false) { - InnerHandler = handler + BaseAddress = new Uri(options.Url, UriKind.Absolute) }; - messageHandler = options.ClientFactory.CreateHttpMessageHandler(messageHandler) ?? messageHandler; + if (options.Timeout != null) + { + httpClient.Timeout = options.Timeout.Value; + } - var httpClient = - options.ClientFactory.CreateHttpClient(messageHandler) ?? - new HttpClient(messageHandler, false); + return httpClient; + } - // Apply this setting afterwards, to override the value from the client factory. - httpClient.BaseAddress = new Uri(options.Url, UriKind.Absolute); + /// + /// Creates the client handler from the options. + /// + /// The options. + /// + /// The created HTTP client handler. + /// + protected virtual HttpMessageHandler CreateMessageHandler(SquidexOptions options) + { + var innerHandler = new HttpClientHandler(); - // Also override timeout when create from factory. - httpClient.Timeout = options.HttpClientTimeout; + if (options.IgnoreSelfSignedCertificates) + { + innerHandler.ServerCertificateCustomValidationCallback = (_, _, _, _) => true; + } - options.Configurator.Configure(httpClient); + var messageHandler = new AuthenticatingHttpMessageHandler(options) + { + InnerHandler = innerHandler + }; - return httpClient; + return messageHandler; } /// public HttpClient Get() { - return staticHttpClient; - } - - /// - public void Return(HttpClient httpClient) - { + return staticHttpClient ?? CreateHttpClient(options); } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs index 819bc538..ccb86266 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsClient.cs @@ -24,20 +24,15 @@ namespace Squidex.ClientLibrary; /// /// Initializes a new instance of the class - /// with the name of the schema, the options from the and the HTTP client. + /// with the name of the schema, the options from the and the HTTP client. /// - /// The options from the . Cannot be null. - /// Name of the app. Cannot be null or empty. + /// The options from the . Cannot be null. /// Name of the schema. Cannot be null or empty. - /// The HTTP client provider. Cannot be null. /// is null. - /// is null. /// is null. - /// is null. - /// is empty. /// is empty. - public ContentsClient(SquidexOptions options, string appName, string schemaName, IHttpClientProvider httpClientProvider) - : base(options, appName, httpClientProvider) + public ContentsClient(SquidexOptions options, string schemaName) + : base(options) { Guard.NotNullOrEmpty(schemaName, nameof(schemaName)); @@ -91,57 +86,51 @@ public async Task StreamAllAsync(Func callback, int skip = 0, Que context = (context ?? QueryContext.Default).WithoutTotal(); - var httpClient = HttpClientProvider.Get(); - try + var httpClient = Options.ClientProvider.Get(); + + using (var request = BuildRequest(HttpMethod.Get, BuildUrl($"stream?skip={skip}", false), null, context)) { - using (var request = BuildRequest(HttpMethod.Get, BuildUrl($"stream?skip={skip}", false), null, context)) + using (var response = await httpClient.SendAsync(request, ct)) { - using (var response = await httpClient.SendAsync(request, ct)) - { - await EnsureResponseIsValidAsync(response); + await EnsureResponseIsValidAsync(response); #if NETSTANDARD2_0 || NETCOREAPP3_1 - using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync())) + using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync())) #else - using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync(ct))) + using (var reader = new StreamReader(await response.Content.ReadAsStreamAsync(ct))) #endif - { - string? line; + { + string? line; #if NET7_0_OR_GREATER - while ((line = await reader.ReadLineAsync(ct)) != null) + while ((line = await reader.ReadLineAsync(ct)) != null) #else - while ((line = await reader.ReadLineAsync()) != null) + while ((line = await reader.ReadLineAsync()) != null) #endif - { - ct.ThrowIfCancellationRequested(); + { + ct.ThrowIfCancellationRequested(); - if (string.IsNullOrWhiteSpace(line)) - { - continue; - } + if (string.IsNullOrWhiteSpace(line)) + { + continue; + } - const string Prefix = "data: "; + const string Prefix = "data: "; - if (!line.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase)) - { - throw new SquidexException("Line does not start with data prefix.", 0, null); - } + if (!line.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase)) + { + throw new SquidexException("Line does not start with data prefix.", 0, null); + } #pragma warning disable IDE0057 // Use range operator - var contentJson = line.Substring(Prefix.Length); + var contentJson = line.Substring(Prefix.Length); #pragma warning restore IDE0057 // Use range operator - var contentItem = contentJson.FromJson(); + var contentItem = contentJson.FromJson(); - await callback(contentItem); - } + await callback(contentItem); } } } } - finally - { - HttpClientProvider.Return(httpClient); - } } /// @@ -171,15 +160,6 @@ public Task GetAsync(string id, long version, QueryContext? context = n return RequestJsonAsync(HttpMethod.Get, BuildUrl($"{id}/?version={version}", true, context), null, context, ct); } - /// - public Task GetDataAsync(string id, int version, QueryContext? context = null, - CancellationToken ct = default) - { - Guard.NotNullOrEmpty(id, nameof(id)); - - return RequestJsonAsync(HttpMethod.Get, BuildUrl($"{id}/{version}", true, context), null, context, ct); - } - /// public Task> GetReferencingAsync(TEntity entity, ContentQuery? query = null, QueryContext? context = null, CancellationToken ct = default) @@ -372,11 +352,11 @@ private string BuildUrl(string path, bool query, QueryContext? context = null) { if (ShouldUseCDN(query, context)) { - return $"{Options.ContentCDN}{AppName}/{SchemaName}/{path}"; + return $"{Options.ContentCDN}{Options.AppName}/{SchemaName}/{path}"; } else { - return $"api/content/{AppName}/{SchemaName}/{path}"; + return $"api/content/{Options.AppName}/{SchemaName}/{path}"; } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs index 83dc5751..ffb10807 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ContentsSharedClient.cs @@ -23,17 +23,12 @@ namespace Squidex.ClientLibrary; { /// /// Initializes a new instance of the class - /// with the name of the schema, the options from the and the HTTP client. + /// with the name of the schema, the options from the and the HTTP client. /// - /// The options from the . Cannot be null. - /// Name of the app. Cannot be null or empty. - /// The HTTP client provider. Cannot be null. + /// The options from the . Cannot be null. /// is null. - /// is null. - /// is null. - /// is empty. - public ContentsSharedClient(SquidexOptions options, string appName, IHttpClientProvider httpClientProvider) - : base(options, appName, httpClientProvider) + public ContentsSharedClient(SquidexOptions options) + : base(options) { } @@ -107,11 +102,11 @@ private string BuildUrl(string path, bool query, QueryContext? context = null) { if (ShouldUseCDN(query, context)) { - return $"{Options.ContentCDN}{AppName}/{path}"; + return $"{Options.ContentCDN}{Options.AppName}/{path}"; } else { - return $"api/content/{AppName}/{path}"; + return $"api/content/{Options.AppName}/{path}"; } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Status.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs similarity index 98% rename from csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Status.cs rename to csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs index 2c43e938..6020582e 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Status.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/Status.cs @@ -7,7 +7,7 @@ using System.ComponentModel; -namespace Squidex.ClientLibrary; +namespace Squidex.ClientLibrary.EnrichedEvents; /// /// Default status strings. diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/StatusTypeConverter.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/StatusTypeConverter.cs similarity index 96% rename from csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/StatusTypeConverter.cs rename to csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/StatusTypeConverter.cs index 3c312128..e3500761 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/StatusTypeConverter.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/EnrichedEvents/StatusTypeConverter.cs @@ -8,7 +8,7 @@ using System.ComponentModel; using System.Globalization; -namespace Squidex.ClientLibrary; +namespace Squidex.ClientLibrary.EnrichedEvents; /// /// Converter for the Status. diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs index 9a1aca59..769bdd6c 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ExtendableRulesClient.cs @@ -19,17 +19,12 @@ public sealed class ExtendableRulesClient : SquidexClientBase, IExtendableRulesC { /// /// Initializes a new instance of the class - /// with the name of the schema, the options from the and the HTTP client. + /// with the name of the schema, the options from the and the HTTP client. /// - /// The options from the . Cannot be null. - /// Name of the app. Cannot be null or empty. - /// The HTTP client provider. Cannot be null. + /// The options from the . Cannot be null. /// is null. - /// is null. - /// is null. - /// is empty. - public ExtendableRulesClient(SquidexOptions options, string appName, IHttpClientProvider httpClientProvider) - : base(options, appName, httpClientProvider) + public ExtendableRulesClient(SquidexOptions options) + : base(options) { } @@ -88,6 +83,6 @@ public Task DeleteRuleAsync(string id, private string BuildUrl(string? path = null) { - return $"api/apps/{AppName}/rules/{path}"; + return $"api/apps/{Options.AppName}/rules/{path}"; } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsClient.cs index 10dcbc8e..8f1516cb 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsClient.cs @@ -14,14 +14,6 @@ namespace Squidex.ClientLibrary; /// The type that represents the data structure. public interface IContentsClient where TEntity : Content where TData : class, new() { - /// - /// Gets the name of the app for which this client has been created. - /// - /// - /// The name of the app for which this client has been created. - /// - string AppName { get; } - /// /// Gets the name of the schema for which this client has been created. /// @@ -325,22 +317,6 @@ Task GetAsync(string id, QueryContext? context = null, Task GetAsync(string id, long version, QueryContext? context = null, CancellationToken ct = default); - /// - /// Gets a content item by ID and version. - /// - /// The ID of the content item. Cannot be null or empty. - /// The version of the content. - /// The context object to add additonal headers to the request and change the behavior of the API when querying content items. - /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. - /// - /// The content item or null if not found. - /// - /// is null. - /// is empty. - [Obsolete("Use GetAsync with version.")] - Task GetDataAsync(string id, int version, QueryContext? context = null, - CancellationToken ct = default); - /// /// Query content items by an optional query. /// diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsSharedClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsSharedClient.cs index 8c40e33e..12eb3332 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsSharedClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/IContentsSharedClient.cs @@ -14,14 +14,6 @@ namespace Squidex.ClientLibrary; /// The type that represents the data structure. public interface IContentsSharedClient where TEntity : Content where TData : class, new() { - /// - /// Gets the name of the app for which this client has been created. - /// - /// - /// The name of the app for which this client has been created. - /// - string AppName { get; } - /// /// Executes a bulk update. /// diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClient.cs new file mode 100644 index 00000000..7a5e8c7e --- /dev/null +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClient.cs @@ -0,0 +1,287 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using Squidex.ClientLibrary.Management; + +namespace Squidex.ClientLibrary; + +/// +/// Provides access to all endpoints through individual clients and handles authentication. +/// +public interface ISquidexClient +{ + /// + /// Gets the options that are used to initialize the client manager. + /// + /// + /// The options that are used to initialize the client manager. + /// + /// + /// This object is frozen and cannot be changed later. + /// + SquidexOptions Options { get; } + + /// + /// Generates the URL to the image with the specified ID. + /// + /// The ID of the asset. + /// + /// THe URL to the image. + /// + string? GenerateImageUrl(string? id); + + /// + /// Generates the URL to the image with the first specified ID. + /// + /// The ID of the asset. + /// + /// THe URL to the image. + /// + string? GenerateImageUrl(IEnumerable? id); + + /// + /// Generates an absolute URL. + /// + /// The relative URL. + /// + /// The absolute URL. + /// + string? GenerateUrl(string? relativeUrl); + + /// + /// Generates an absolute URL for the asset CDN. + /// + /// The relative URL. + /// Asset CDN not configured. + /// + /// The absolute URL. + /// + string? GenerateAssetCDNUrl(string relativeUrl); + + /// + /// Generates an absolute URL for the content CDN. + /// + /// The relative URL. + /// Content CDN not configured. + /// + /// The absolute URL. + /// + string? GenerateContentCDNUrl(string relativeUrl); + + /// + /// Gets a client instance to query and manage app configuration. + /// + /// + /// The returned client. + /// + IAppsClient Apps { get; } + + /// + /// Gets a client instance to query and manage assets. + /// + /// + /// The returned client. + /// + IAssetsClient Assets { get; } + + /// + /// Gets a client instance to query and manage backups. + /// + /// + /// The returned client. + /// + IBackupsClient Backups { get; } + + /// + /// Gets a client instance to query and manage comments. + /// + /// + /// The returned client. + /// + ICommentsClient Comments { get; } + + /// + /// Gets a client instance to query diagnostics data. + /// + /// + /// The returned client. + /// + IDiagnosticsClient Diagnostics { get; } + + /// + /// Gets a client instance to query and manage event consumers. + /// + /// + /// The returned client. + /// + IEventConsumersClient EventConsumers { get; } + + /// + /// Gets a client instance to query and manage histories. + /// + /// + /// The returned client. + /// + IHistoryClient History { get; } + + /// + /// Gets a client instance to query all supported languages. + /// + /// + /// The returned client. + /// + /// + /// Do not create new clients frequently. + /// + ILanguagesClient Languages { get; } + + /// + /// Gets a client instance to ping the server for monitoring. + /// + /// + /// The returned client. + /// + IPingClient Ping { get; } + + /// + /// Gets a client instance to query and manage plans and subscriptions. + /// + /// + /// The returned client. + /// + IPlansClient Plans { get; } + + /// + /// Gets a client instance to query and manage rules. + /// + /// + /// The returned client. + /// + IRulesClient Rules { get; } + + /// + /// Gets a client instance to query and manage schemas. + /// + /// + /// The returned client. + /// + ISchemasClient Schemas { get; } + + /// + /// Gets a client instance to make searches across content and records. + /// + /// + /// The returned client. + /// + ISearchClient Search { get; } + + /// + /// Gets a client instance to query statistics. + /// + /// + /// The returned client. + /// + IStatisticsClient Statistics { get; } + + /// + /// Gets a client instance to query and manage teams. + /// + /// + /// The returned client. + /// + ITeamsClient Teams { get; } + + /// + /// Gets a client instance to query templates. + /// + /// + /// The returned client. + /// + ITemplatesClient Templates { get; } + + /// + /// Gets a client instance to translate content. + /// + /// + /// The returned client. + /// + ITranslationsClient Translations { get; } + + /// + /// Gets a client instance to query user information. + /// + /// + /// The returned client. + /// + IUsersClient Users { get; } + + /// + /// Gets a client instance to query and manage users as administrator. + /// + /// + /// The returned client. + /// + IUserManagementClient UserManagement { get; } + + /// + /// Gets a client instance to query and manage untyped rules. + /// + /// + /// The returned client. + /// + IExtendableRulesClient ExtendableRules { get; } + + /// + /// Gets a client instance to query and manage contents across all schemas with dynamic data shape. + /// + /// + /// The returned client. + /// + IContentsSharedClient SharedDynamicContents { get; } + + /// + /// Gets a client instance to query and manage contents for a schema. + /// + /// The type for the content entity. + /// The type that represents the data structure. + /// The name of the schema. Cannot be null or empty. + /// + /// The returned client. + /// + /// is null. + /// is empty. + IContentsClient Contents(string schemaName) where TEntity : Content where TData : class, new(); + + /// + /// Gets a client instance to query and manage contents for a schema with dynamic data shape. + /// + /// The name of the schema. Cannot be null or empty. + /// + /// The returned client. + /// + /// is null. + /// is empty. + IContentsClient DynamicContents(string schemaName); + + /// + /// Gets a client instance to query and manage contents across all schemas. + /// + /// The type for the content entity. + /// The type that represents the data structure. + /// + /// The returned client. + /// + IContentsSharedClient SharedContents() where TEntity : Content where TData : class, new(); + + /// + /// Creates a to make all kind of authorized requests. + /// + /// + /// The returned client. + /// + HttpClient CreateHttpClient(); +} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClientManager.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClientManager.cs deleted file mode 100644 index a9bf1afa..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/ISquidexClientManager.cs +++ /dev/null @@ -1,412 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Squidex.ClientLibrary.Management; - -namespace Squidex.ClientLibrary; - -/// -/// Provides access to all endpoints through individual clients and handles authentication. -/// -public interface ISquidexClientManager -{ - /// - /// Gets the options that are used to initialize the client manager. - /// - /// - /// The options that are used to initialize the client manager. - /// - /// - /// This object is frozen and cannot be changed later. - /// - SquidexOptions Options { get; } - - /// - /// Gets the name of the App. - /// - /// - /// The name of the App. - /// - string App { get; } - - /// - /// Generates the URL to the image with the specified ID. - /// - /// The ID of the asset. - /// - /// THe URL to the image. - /// - string? GenerateImageUrl(string? id); - - /// - /// Generates the URL to the image with the first specified ID. - /// - /// The ID of the asset. - /// - /// THe URL to the image. - /// - string? GenerateImageUrl(IEnumerable? id); - - /// - /// Generates an absolute URL. - /// - /// The relative URL. - /// - /// The absolute URL. - /// - string? GenerateUrl(string? relativeUrl); - - /// - /// Generates an absolute URL for the asset CDN. - /// - /// The relative URL. - /// Asset CDN not configured. - /// - /// The absolute URL. - /// - string? GenerateAssetCDNUrl(string relativeUrl); - - /// - /// Generates an absolute URL for the content CDN. - /// - /// The relative URL. - /// Content CDN not configured. - /// - /// The absolute URL. - /// - string? GenerateContentCDNUrl(string relativeUrl); - - /// - /// Creates a client instance to query and manage app configuration. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IAppsClient CreateAppsClient(); - - /// - /// Creates a client instance to query and manage assets. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IAssetsClient CreateAssetsClient(); - - /// - /// Creates a client instance to query and manage backups. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IBackupsClient CreateBackupsClient(); - - /// - /// Creates a client instance to query and manage comments. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ICommentsClient CreateCommentsClient(); - - /// - /// Creates a client instance to query diagnostics data. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IDiagnosticsClient CreateDiagnosticsClient(); - - /// - /// Creates a client instance to query and manage event consumers. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IEventConsumersClient CreateEventConsumersClient(); - - /// - /// Creates a client instance to query and manage histories. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IHistoryClient CreateHistoryClient(); - - /// - /// Creates a client instance to query all supported languages. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ILanguagesClient CreateLanguagesClient(); - - /// - /// Creates a client instance to ping the server for monitoring. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IPingClient CreatePingClient(); - - /// - /// Creates a client instance to query and manage plans and subscriptions. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IPlansClient CreatePlansClient(); - - /// - /// Creates a client instance to query and manage rules. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IRulesClient CreateRulesClient(); - - /// - /// Creates a client instance to query and manage schemas. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ISchemasClient CreateSchemasClient(); - - /// - /// Creates a client instance to make searches across content and records. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ISearchClient CreateSearchClient(); - - /// - /// Creates a client instance to query statistics. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IStatisticsClient CreateStatisticsClient(); - - /// - /// Creates a client instance to query and manage teams. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ITeamsClient CreateTeamsClient(); - - /// - /// Creates a client instance to query templates. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ITemplatesClient CreateTemplatesClient(); - - /// - /// Creates a client instance to translate content. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - ITranslationsClient CreateTranslationsClient(); - - /// - /// Creates a client instance to query user information. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IUsersClient CreateUsersClient(); - - /// - /// Creates a client instance to query and manage users as administrator. - /// - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IUserManagementClient CreateUserManagementClient(); - - /// - /// Creates a client instance to query and manage untyped rules. - /// - /// The optional app name. - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IExtendableRulesClient CreateExtendableRulesClient(string? appName = null); - - /// - /// Creates a client instance to query and manage contents for a schema. - /// - /// The type for the content entity. - /// The type that represents the data structure. - /// The name of the schema. Cannot be null or empty. - /// - /// The created client. - /// - /// is null. - /// is empty. - /// - /// Do not create new clients frequently. - /// - IContentsClient CreateContentsClient(string schemaName) where TEntity : Content where TData : class, new(); - - /// - /// Creates a client instance to query and manage contents for an app and schema. - /// - /// The type for the content entity. - /// The type that represents the data structure. - /// The name of the app. Cannot be null or empty. - /// The name of the schema. Cannot be null or empty. - /// - /// The created client. - /// - /// is null. - /// is null. - /// is empty. - /// is empty. - /// - /// Do not create new clients frequently. - /// - IContentsClient CreateContentsClient(string appName, string schemaName) where TEntity : Content where TData : class, new(); - - /// - /// Creates a client instance to query and manage contents for a schema with dynamic data shape. - /// - /// The name of the schema. Cannot be null or empty. - /// - /// The created client. - /// - /// is null. - /// is empty. - /// - /// Do not create new clients frequently. - /// - IContentsClient CreateDynamicContentsClient(string schemaName); - - /// - /// Creates a client instance to query and manage contents for an app and schema with dynamic data shape. - /// - /// The name of the app. Cannot be null or empty. - /// The name of the schema. Cannot be null or empty. - /// - /// The created client. - /// - /// is null. - /// is null. - /// is empty. - /// is empty. - /// - /// Do not create new clients frequently. - /// - IContentsClient CreateDynamicContentsClient(string appName, string schemaName); - - /// - /// Creates a client instance to query and manage contents across all schemas. - /// - /// The type for the content entity. - /// The type that represents the data structure. - /// The optional app name. - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IContentsSharedClient CreateSharedContentsClient(string? appName = null) where TEntity : Content where TData : class, new(); - - /// - /// Creates a client instance to query and manage contents across all schemas with dynamic data shape. - /// - /// The optional app name. - /// - /// The created client. - /// - /// - /// Do not create new clients frequently. - /// - IContentsSharedClient CreateSharedDynamicContentsClient(string? appName = null); - - /// - /// Creates a to make all kind of authorized requests. - /// - /// - /// The created client. - /// - /// - /// Remember to return the client after each request. - /// - HttpClient CreateHttpClient(); - - /// - /// Returns the http client. - /// - /// The HTTP client to return. - void ReturnHttpClient(HttpClient httpClient); -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/AssetsClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/AssetsClient.cs index ab074522..d8eee125 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/AssetsClient.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/AssetsClient.cs @@ -17,19 +17,17 @@ public partial interface IAssetsClient /// /// Gets the upload progress. /// - /// The name of the app. /// The file id of the upload. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// The upload progress in bytes. /// - Task GetUploadProgressAsync(string app, string fileId, + Task GetUploadProgressAsync(string fileId, CancellationToken cancellationToken = default); /// /// Upload a new asset using tus protocol. /// - /// The name of the app. /// The file to upload. /// Optional arguments. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. @@ -37,24 +35,22 @@ Task GetUploadProgressAsync(string app, string fileId, /// Task for completion. /// /// A server side error occurred. - Task UploadAssetAsync(string app, FileParameter file, AssetUploadOptions options = default, + Task UploadAssetAsync(FileParameter file, AssetUploadOptions options = default, CancellationToken cancellationToken = default); /// Get assets. - /// The name of the app. /// The optional asset query. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Assets returned. /// /// A server side error occurred. - Task GetAssetsAsync(string app, AssetQuery? query = null, + Task GetAssetsAsync(AssetQuery? query = null, CancellationToken cancellationToken = default); /// /// Get assets. /// - /// The name of the app. /// The callback that is invoke for each asset. /// The number of assets per request. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. @@ -62,13 +58,12 @@ Task GetAssetsAsync(string app, AssetQuery? query = null, /// Assets returned. /// /// A server side error occurred. - Task GetAllAsync(string app, Func callback, int batchSize = 200, + Task GetAllAsync(Func callback, int batchSize = 200, CancellationToken cancellationToken = default); /// /// Get assets. /// - /// The name of the app. /// The callback that is invoke for each asset. /// The optional asset query. /// The number of assets per request. @@ -77,7 +72,7 @@ Task GetAllAsync(string app, Func callback, int batchSize = 200, /// Assets returned. /// /// A server side error occurred. - Task GetAllByQueryAsync(string app, Func callback, AssetQuery? query = null, int batchSize = 200, + Task GetAllByQueryAsync(Func callback, AssetQuery? query = null, int batchSize = 200, CancellationToken cancellationToken = default); } @@ -96,59 +91,47 @@ public partial class AssetsClient } /// - public async Task GetUploadProgressAsync(string app, string fileId, + public async Task GetUploadProgressAsync(string fileId, CancellationToken cancellationToken = default) { Guard.NotNull(fileId, nameof(fileId)); - var url = $"api/apps/{app}/assets/tus/"; + var url = $"api/apps/{_options.AppName}/assets/tus/"; - var httpClient = _httpClientProvider.Get(); - try - { - return await httpClient.GetUploadProgressAsync(url, fileId, cancellationToken); - } - finally - { - _httpClientProvider.Return(httpClient); - } + var httpClient = _options.ClientProvider.Get(); + + return await httpClient.GetUploadProgressAsync(url, fileId, cancellationToken); } /// - public async Task UploadAssetAsync(string app, FileParameter file, AssetUploadOptions options = default, + public async Task UploadAssetAsync(FileParameter file, AssetUploadOptions options = default, CancellationToken cancellationToken = default) { Guard.NotNull(file, nameof(file)); - var url = $"api/apps/{app}/assets/tus"; + var url = $"api/apps/{_options.AppName}/assets/tus"; - var httpClient = _httpClientProvider.Get(); - try - { - await httpClient.UploadWithProgressAsync(url, file.ToUploadFile(), options.ToOptions(this), cancellationToken); - } - finally - { - _httpClientProvider.Return(httpClient); - } + var httpClient = _options.ClientProvider.Get(); + + await httpClient.UploadWithProgressAsync(url, file.ToUploadFile(), options.ToOptions(this), cancellationToken); } /// - public Task GetAssetsAsync(string app, AssetQuery? query = null, + public Task GetAssetsAsync(AssetQuery? query = null, CancellationToken cancellationToken = default) { - return GetAssetsAsync(app, query?.Top, query?.Skip, query?.OrderBy, query?.Filter, query?.ParentId, query?.ToIdString(), query?.ToQueryJson(), cancellationToken); + return GetAssetsAsync(query?.Top, query?.Skip, query?.OrderBy, query?.Filter, query?.ParentId, query?.ToIdString(), query?.ToQueryJson(), cancellationToken); } /// - public Task GetAllAsync(string app, Func callback, int batchSize = 200, + public Task GetAllAsync(Func callback, int batchSize = 200, CancellationToken cancellationToken = default) { - return GetAllByQueryAsync(app, callback, null, batchSize, cancellationToken); + return GetAllByQueryAsync(callback, null, batchSize, cancellationToken); } /// - public async Task GetAllByQueryAsync(string app, Func callback, AssetQuery? query = null, int batchSize = 200, + public async Task GetAllByQueryAsync(Func callback, AssetQuery? query = null, int batchSize = 200, CancellationToken cancellationToken = default) { Guard.Between(batchSize, 10, 10_000, nameof(batchSize)); @@ -163,7 +146,7 @@ public async Task GetAllByQueryAsync(string app, Func callback, { var isAnyAdded = false; - var getResult = await GetAssetsAsync(app, query, cancellationToken); + var getResult = await GetAssetsAsync(query, cancellationToken); foreach (var item in getResult.Items) { diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Generated.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Generated.cs index 090e672e..ccdd03f3 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Generated.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Management/Generated.cs @@ -92,12 +92,12 @@ public partial interface IUserManagementClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class UserManagementClient : IUserManagementClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public UserManagementClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public UserManagementClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -129,6 +129,7 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management?"); + urlBuilder_.Replace("{app}", _options.AppName); if (query != null) { urlBuilder_.Append(System.Uri.EscapeDataString("query") + "=").Append(System.Uri.EscapeDataString(ConvertToString(query, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); @@ -143,12 +144,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -207,7 +207,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -225,13 +224,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -304,7 +303,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -322,14 +320,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management/{id}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -394,7 +392,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -416,14 +413,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management/{id}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -502,7 +499,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -520,14 +516,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management/{id}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -606,7 +602,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -624,14 +619,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management/{id}/lock"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -717,7 +712,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -735,14 +729,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/user-management/{id}/unlock"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -828,7 +822,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -845,8 +838,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -854,7 +845,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -982,12 +973,12 @@ public partial interface IUsersClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class UsersClient : IUsersClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public UsersClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public UsersClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -1016,13 +1007,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -1081,7 +1072,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1099,18 +1089,18 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/users?"); + urlBuilder_.Replace("{app}", _options.AppName); if (query != null) { urlBuilder_.Append(System.Uri.EscapeDataString("query") + "=").Append(System.Uri.EscapeDataString(ConvertToString(query, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -1169,7 +1159,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1187,14 +1176,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/users/{id}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -1259,7 +1248,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1277,14 +1265,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/users/{id}/picture"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -1347,7 +1335,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1364,8 +1351,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -1373,7 +1358,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -1462,23 +1447,22 @@ public partial interface ITranslationsClient /// /// Translate a text. /// - /// The name of the app. /// The translation request. /// Text translated. /// A server side error occurred. - System.Threading.Tasks.Task PostTranslationAsync(string app, TranslateDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostTranslationAsync(TranslateDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class TranslationsClient : ITranslationsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public TranslationsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public TranslationsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -1501,30 +1485,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Translate a text. /// - /// The name of the app. /// The translation request. /// Text translated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostTranslationAsync(string app, TranslateDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostTranslationAsync(TranslateDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/translations"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -1597,7 +1574,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1614,8 +1590,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -1623,7 +1597,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -1730,12 +1704,12 @@ public partial interface ITemplatesClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class TemplatesClient : ITemplatesClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public TemplatesClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public TemplatesClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -1764,13 +1738,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/templates"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -1829,7 +1803,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1847,14 +1820,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/templates/{name}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{name}", System.Uri.EscapeDataString(ConvertToString(name, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -1919,7 +1892,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -1936,8 +1908,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -1945,7 +1915,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -2117,12 +2087,12 @@ public partial interface ITeamsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class TeamsClient : ITeamsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public TeamsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public TeamsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -2155,14 +2125,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/contributors"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -2227,7 +2197,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2249,14 +2218,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/contributors"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -2335,7 +2304,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2353,14 +2321,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/contributors/me"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -2435,7 +2403,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2457,15 +2424,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/contributors/{id}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -2540,7 +2507,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2558,13 +2524,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -2623,7 +2589,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2645,13 +2610,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -2734,7 +2699,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2752,14 +2716,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -2824,7 +2788,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2846,14 +2809,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -2932,7 +2895,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -2949,8 +2911,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -2958,7 +2918,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -3047,21 +3007,19 @@ public partial interface IStatisticsClient /// /// Get api calls as log file. /// - /// The name of the app. /// Usage tracking results returned. /// A server side error occurred. - System.Threading.Tasks.Task GetLogAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetLogAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get api calls in date range. /// - /// The name of the app. /// The from date. /// The to date. /// API call returned. /// A server side error occurred. - System.Threading.Tasks.Task GetUsagesAsync(string app, System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetUsagesAsync(System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -3078,10 +3036,9 @@ public partial interface IStatisticsClient /// /// Get total asset size. /// - /// The name of the app. /// Storage usage returned. /// A server side error occurred. - System.Threading.Tasks.Task GetCurrentStorageSizeAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetCurrentStorageSizeAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -3096,12 +3053,11 @@ public partial interface IStatisticsClient /// /// Get asset usage by date. /// - /// The name of the app. /// The from date. /// The to date. /// Storage usage returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetStorageSizesAsync(string app, System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetStorageSizesAsync(System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -3119,12 +3075,12 @@ public partial interface IStatisticsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class StatisticsClient : IStatisticsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public StatisticsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public StatisticsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -3147,26 +3103,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get api calls as log file. /// - /// The name of the app. /// Usage tracking results returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetLogAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetLogAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/usages/log"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3231,7 +3180,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3239,16 +3187,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get api calls in date range. /// - /// The name of the app. /// The from date. /// The to date. /// API call returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetUsagesAsync(string app, System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetUsagesAsync(System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (fromDate == null) throw new System.ArgumentNullException("fromDate"); @@ -3257,18 +3201,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/usages/calls/{fromDate}/{toDate}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{fromDate}", System.Uri.EscapeDataString(fromDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{toDate}", System.Uri.EscapeDataString(toDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3333,7 +3274,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3359,16 +3299,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/usages/calls/{fromDate}/{toDate}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{fromDate}", System.Uri.EscapeDataString(fromDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{toDate}", System.Uri.EscapeDataString(toDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3433,7 +3373,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3441,26 +3380,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get total asset size. /// - /// The name of the app. /// Storage usage returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetCurrentStorageSizeAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetCurrentStorageSizeAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/usages/storage/today"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3525,7 +3457,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3543,14 +3474,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/usages/storage/today"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3615,7 +3546,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3623,16 +3553,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get asset usage by date. /// - /// The name of the app. /// The from date. /// The to date. /// Storage usage returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetStorageSizesAsync(string app, System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetStorageSizesAsync(System.DateTimeOffset fromDate, System.DateTimeOffset toDate, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (fromDate == null) throw new System.ArgumentNullException("fromDate"); @@ -3641,18 +3567,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/usages/storage/{fromDate}/{toDate}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{fromDate}", System.Uri.EscapeDataString(fromDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{toDate}", System.Uri.EscapeDataString(toDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3717,7 +3640,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3743,16 +3665,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/usages/storage/{fromDate}/{toDate}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{fromDate}", System.Uri.EscapeDataString(fromDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{toDate}", System.Uri.EscapeDataString(toDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -3817,7 +3739,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -3834,8 +3755,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -3843,7 +3762,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -3932,23 +3851,22 @@ public partial interface ISearchClient /// /// Get search results. /// - /// The name of the app. /// The search query. /// Search results returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetSearchResultsAsync(string app, string query = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetSearchResultsAsync(string query = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class SearchClient : ISearchClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public SearchClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public SearchClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -3971,32 +3889,25 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get search results. /// - /// The name of the app. /// The search query. /// Search results returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetSearchResultsAsync(string app, string query = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetSearchResultsAsync(string query = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/search?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (query != null) { urlBuilder_.Append(System.Uri.EscapeDataString("query") + "=").Append(System.Uri.EscapeDataString(ConvertToString(query, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -4061,7 +3972,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -4078,8 +3988,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -4087,7 +3995,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -4176,106 +4084,97 @@ public partial interface ISchemasClient /// /// Add a schema field. /// - /// The name of the app. /// The name of the schema. /// The field object that needs to be added to the schema. /// Schema field created. /// A server side error occurred. - System.Threading.Tasks.Task PostFieldAsync(string app, string schema, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostFieldAsync(string schema, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Add a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The field object that needs to be added to the schema. /// Schema field created. /// A server side error occurred. - System.Threading.Tasks.Task PostNestedFieldAsync(string app, string schema, long parentId, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostNestedFieldAsync(string schema, long parentId, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Configure UI fields. /// - /// The name of the app. /// The name of the schema. /// The request that contains the field names. /// Schema UI fields defined. /// A server side error occurred. - System.Threading.Tasks.Task PutSchemaUIFieldsAsync(string app, string schema, ConfigureUIFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutSchemaUIFieldsAsync(string schema, ConfigureUIFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Reorder all fields. /// - /// The name of the app. /// The name of the schema. /// The request that contains the field ids. /// Schema fields reordered. /// A server side error occurred. - System.Threading.Tasks.Task PutSchemaFieldOrderingAsync(string app, string schema, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutSchemaFieldOrderingAsync(string schema, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Reorder all nested fields. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The request that contains the field ids. /// Schema fields reordered. /// A server side error occurred. - System.Threading.Tasks.Task PutNestedFieldOrderingAsync(string app, string schema, long parentId, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutNestedFieldOrderingAsync(string schema, long parentId, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a schema field. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to update. /// The field object that needs to be added to the schema. /// Schema field updated. /// A server side error occurred. - System.Threading.Tasks.Task PutFieldAsync(string app, string schema, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutFieldAsync(string schema, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a schema field. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to disable. /// Schema field deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to update. /// The field object that needs to be added to the schema. /// Schema field updated. /// A server side error occurred. - System.Threading.Tasks.Task PutNestedFieldAsync(string app, string schema, long parentId, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutNestedFieldAsync(string schema, long parentId, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to disable. /// Schema field deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4284,12 +4183,11 @@ public partial interface ISchemasClient /// /// A locked field cannot be updated or deleted. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to lock. /// Schema field shown. /// A server side error occurred. - System.Threading.Tasks.Task LockFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task LockFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4298,13 +4196,12 @@ public partial interface ISchemasClient /// /// A locked field cannot be edited or deleted. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to lock. /// Schema field hidden. /// A server side error occurred. - System.Threading.Tasks.Task LockNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task LockNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4313,12 +4210,11 @@ public partial interface ISchemasClient /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to hide. /// Schema field hidden. /// A server side error occurred. - System.Threading.Tasks.Task HideFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task HideFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4327,13 +4223,12 @@ public partial interface ISchemasClient /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to hide. /// Schema field hidden. /// A server side error occurred. - System.Threading.Tasks.Task HideNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task HideNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4342,12 +4237,11 @@ public partial interface ISchemasClient /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to show. /// Schema field shown. /// A server side error occurred. - System.Threading.Tasks.Task ShowFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task ShowFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4356,13 +4250,12 @@ public partial interface ISchemasClient /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to show. /// Schema field shown. /// A server side error occurred. - System.Threading.Tasks.Task ShowNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task ShowNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4371,12 +4264,11 @@ public partial interface ISchemasClient /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to enable. /// Schema field enabled. /// A server side error occurred. - System.Threading.Tasks.Task EnableFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task EnableFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4385,13 +4277,12 @@ public partial interface ISchemasClient /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to enable. /// Schema field enabled. /// A server side error occurred. - System.Threading.Tasks.Task EnableNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task EnableNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4400,12 +4291,11 @@ public partial interface ISchemasClient /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to disable. /// Schema field disabled. /// A server side error occurred. - System.Threading.Tasks.Task DisableFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DisableFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -4414,150 +4304,137 @@ public partial interface ISchemasClient /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to disable. /// Schema field disabled. /// A server side error occurred. - System.Threading.Tasks.Task DisableNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DisableNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get schemas. /// - /// The name of the app. /// Schemas returned. /// A server side error occurred. - System.Threading.Tasks.Task GetSchemasAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetSchemasAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Create a new schema. /// - /// The name of the app. /// The schema object that needs to be added to the app. /// Schema created. /// A server side error occurred. - System.Threading.Tasks.Task PostSchemaAsync(string app, CreateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostSchemaAsync(CreateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get a schema by name. /// - /// The name of the app. /// The name of the schema to retrieve. /// Schema found. /// A server side error occurred. - System.Threading.Tasks.Task GetSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a schema. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutSchemaAsync(string app, string schema, UpdateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutSchemaAsync(string schema, UpdateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a schema. /// - /// The name of the app. /// The name of the schema to delete. /// Schema deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Synchronize a schema. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutSchemaSyncAsync(string app, string schema, SynchronizeSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutSchemaSyncAsync(string schema, SynchronizeSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a schema category. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutCategoryAsync(string app, string schema, ChangeCategoryDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutCategoryAsync(string schema, ChangeCategoryDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the preview urls. /// - /// The name of the app. /// The name of the schema. /// The preview urls for the schema. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutPreviewUrlsAsync(string app, string schema, System.Collections.Generic.IDictionary request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutPreviewUrlsAsync(string schema, System.Collections.Generic.IDictionary request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the scripts. /// - /// The name of the app. /// The name of the schema. /// The schema scripts object that needs to updated. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutScriptsAsync(string app, string schema, SchemaScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutScriptsAsync(string schema, SchemaScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the rules. /// - /// The name of the app. /// The name of the schema. /// The schema rules object that needs to updated. /// Schema updated. /// A server side error occurred. - System.Threading.Tasks.Task PutRulesAsync(string app, string schema, ConfigureFieldRulesDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutRulesAsync(string schema, ConfigureFieldRulesDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Publish a schema. /// - /// The name of the app. /// The name of the schema to publish. /// Schema published. /// A server side error occurred. - System.Threading.Tasks.Task PublishSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PublishSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Unpublish a schema. /// - /// The name of the app. /// The name of the schema to unpublish. /// Schema unpublished. /// A server side error occurred. - System.Threading.Tasks.Task UnpublishSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task UnpublishSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class SchemasClient : ISchemasClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public SchemasClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public SchemasClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -4580,16 +4457,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Add a schema field. /// - /// The name of the app. /// The name of the schema. /// The field object that needs to be added to the schema. /// Schema field created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostFieldAsync(string app, string schema, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostFieldAsync(string schema, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -4598,17 +4471,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -4697,7 +4567,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -4705,17 +4574,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Add a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The field object that needs to be added to the schema. /// Schema field created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostNestedFieldAsync(string app, string schema, long parentId, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostNestedFieldAsync(string schema, long parentId, AddFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -4727,18 +4592,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -4827,7 +4689,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -4835,16 +4696,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Configure UI fields. /// - /// The name of the app. /// The name of the schema. /// The request that contains the field names. /// Schema UI fields defined. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutSchemaUIFieldsAsync(string app, string schema, ConfigureUIFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutSchemaUIFieldsAsync(string schema, ConfigureUIFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -4853,17 +4710,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/ui"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -4942,7 +4796,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -4950,16 +4803,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Reorder all fields. /// - /// The name of the app. /// The name of the schema. /// The request that contains the field ids. /// Schema fields reordered. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutSchemaFieldOrderingAsync(string app, string schema, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutSchemaFieldOrderingAsync(string schema, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -4968,17 +4817,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/ordering"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -5057,7 +4903,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5065,17 +4910,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Reorder all nested fields. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The request that contains the field ids. /// Schema fields reordered. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutNestedFieldOrderingAsync(string app, string schema, long parentId, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutNestedFieldOrderingAsync(string schema, long parentId, ReorderFieldsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5087,18 +4928,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/ordering"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -5177,7 +5015,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5185,17 +5022,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a schema field. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to update. /// The field object that needs to be added to the schema. /// Schema field updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutFieldAsync(string app, string schema, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutFieldAsync(string schema, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5207,18 +5040,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -5297,7 +5127,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5305,16 +5134,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a schema field. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to disable. /// Schema field deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5323,18 +5148,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -5409,7 +5231,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5417,18 +5238,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to update. /// The field object that needs to be added to the schema. /// Schema field updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutNestedFieldAsync(string app, string schema, long parentId, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutNestedFieldAsync(string schema, long parentId, long id, UpdateFieldDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5443,20 +5260,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -5535,7 +5348,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5543,17 +5355,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a nested field. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to disable. /// Schema field deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5565,19 +5373,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -5652,7 +5457,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5663,16 +5467,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A locked field cannot be updated or deleted. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to lock. /// Schema field shown. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task LockFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task LockFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5681,18 +5481,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}/lock"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -5768,7 +5565,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5779,17 +5575,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A locked field cannot be edited or deleted. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to lock. /// Schema field hidden. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task LockNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task LockNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5801,19 +5593,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}/lock"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -5889,7 +5678,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -5900,16 +5688,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to hide. /// Schema field hidden. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task HideFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task HideFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -5918,18 +5702,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}/hide"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6005,7 +5786,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6016,17 +5796,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to hide. /// Schema field hidden. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task HideNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task HideNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6038,19 +5814,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}/hide"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6126,7 +5899,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6137,16 +5909,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to show. /// Schema field shown. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ShowFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task ShowFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6155,18 +5923,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}/show"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6242,7 +6007,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6253,17 +6017,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A hidden field is not part of the API response, but can still be edited in the portal. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to show. /// Schema field shown. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task ShowNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task ShowNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6275,19 +6035,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}/show"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6363,7 +6120,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6374,16 +6130,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to enable. /// Schema field enabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task EnableFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task EnableFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6392,18 +6144,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}/enable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6479,7 +6228,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6490,17 +6238,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to enable. /// Schema field enabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task EnableNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task EnableNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6512,19 +6256,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}/enable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6600,7 +6341,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6611,16 +6351,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The ID of the field to disable. /// Schema field disabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DisableFieldAsync(string app, string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DisableFieldAsync(string schema, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6629,18 +6365,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{id}/disable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6716,7 +6449,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6727,17 +6459,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// A disabled field cannot not be edited in the squidex portal anymore, but will be part of the API response. /// - /// The name of the app. /// The name of the schema. /// The parent field id. /// The ID of the field to disable. /// Schema field disabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DisableNestedFieldAsync(string app, string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DisableNestedFieldAsync(string schema, long parentId, long id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -6749,19 +6477,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/fields/{parentId}/nested/{id}/disable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{parentId}", System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6837,7 +6562,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6845,26 +6569,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get schemas. /// - /// The name of the app. /// Schemas returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetSchemasAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetSchemasAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -6929,7 +6646,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -6937,30 +6653,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Create a new schema. /// - /// The name of the app. /// The schema object that needs to be added to the app. /// Schema created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostSchemaAsync(string app, CreateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostSchemaAsync(CreateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7043,7 +6752,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7051,31 +6759,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get a schema by name. /// - /// The name of the app. /// The name of the schema to retrieve. /// Schema found. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -7140,7 +6841,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7148,16 +6848,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a schema. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutSchemaAsync(string app, string schema, UpdateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutSchemaAsync(string schema, UpdateSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7166,17 +6862,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7255,7 +6948,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7263,31 +6955,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a schema. /// - /// The name of the app. /// The name of the schema to delete. /// Schema deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -7356,7 +7041,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7364,16 +7048,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Synchronize a schema. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutSchemaSyncAsync(string app, string schema, SynchronizeSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutSchemaSyncAsync(string schema, SynchronizeSchemaDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7382,17 +7062,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/sync"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7471,7 +7148,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7479,16 +7155,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a schema category. /// - /// The name of the app. /// The name of the schema. /// The schema object that needs to updated. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutCategoryAsync(string app, string schema, ChangeCategoryDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutCategoryAsync(string schema, ChangeCategoryDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7497,17 +7169,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/category"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7586,7 +7255,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7594,16 +7262,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the preview urls. /// - /// The name of the app. /// The name of the schema. /// The preview urls for the schema. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutPreviewUrlsAsync(string app, string schema, System.Collections.Generic.IDictionary request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutPreviewUrlsAsync(string schema, System.Collections.Generic.IDictionary request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7612,17 +7276,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/preview-urls"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7701,7 +7362,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7709,16 +7369,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the scripts. /// - /// The name of the app. /// The name of the schema. /// The schema scripts object that needs to updated. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutScriptsAsync(string app, string schema, SchemaScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutScriptsAsync(string schema, SchemaScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7727,17 +7383,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/scripts"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7816,7 +7469,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7824,16 +7476,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the rules. /// - /// The name of the app. /// The name of the schema. /// The schema rules object that needs to updated. /// Schema updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutRulesAsync(string app, string schema, ConfigureFieldRulesDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutRulesAsync(string schema, ConfigureFieldRulesDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); @@ -7842,17 +7490,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/rules"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -7931,7 +7576,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -7939,31 +7583,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Publish a schema. /// - /// The name of the app. /// The name of the schema to publish. /// Schema published. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PublishSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PublishSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/publish"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -8039,7 +7676,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8047,31 +7683,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Unpublish a schema. /// - /// The name of the app. /// The name of the schema to unpublish. /// Schema unpublished. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task UnpublishSchemaAsync(string app, string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task UnpublishSchemaAsync(string schema, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (schema == null) throw new System.ArgumentNullException("schema"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/schemas/{schema}/unpublish"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{schema}", System.Uri.EscapeDataString(ConvertToString(schema, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -8147,7 +7776,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8164,8 +7792,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -8173,7 +7799,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -8270,162 +7896,146 @@ public partial interface IRulesClient /// /// Get rules. /// - /// The name of the app. /// Rules returned. /// A server side error occurred. - System.Threading.Tasks.Task GetRulesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetRulesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Create a new rule. /// - /// The name of the app. /// The rule object that needs to be added to the app. /// Rule created. /// A server side error occurred. - System.Threading.Tasks.Task PostRuleAsync(string app, CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostRuleAsync(CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Cancel the current run. /// - /// The name of the app. /// Rule run cancelled. /// A server side error occurred. - System.Threading.Tasks.Task DeleteRuleRunAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteRuleRunAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a rule. /// - /// The name of the app. /// The ID of the rule to update. /// The rule object that needs to be added to the app. /// Rule updated. /// A server side error occurred. - System.Threading.Tasks.Task PutRuleAsync(string app, string id, UpdateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutRuleAsync(string id, UpdateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a rule. /// - /// The name of the app. /// The ID of the rule to delete. /// Rule deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Enable a rule. /// - /// The name of the app. /// The ID of the rule to enable. /// Rule enabled. /// A server side error occurred. - System.Threading.Tasks.Task EnableRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task EnableRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Disable a rule. /// - /// The name of the app. /// The ID of the rule to disable. /// Rule disabled. /// A server side error occurred. - System.Threading.Tasks.Task DisableRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DisableRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Trigger a rule. /// - /// The name of the app. /// The ID of the rule to disable. /// Rule triggered. /// A server side error occurred. - System.Threading.Tasks.Task TriggerRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task TriggerRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Run a rule. /// - /// The name of the app. /// The ID of the rule to run. /// Runs the rule from snapeshots if possible. /// Rule started. /// A server side error occurred. - System.Threading.Tasks.Task PutRuleRunAsync(string app, string id, bool? fromSnapshots = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutRuleRunAsync(string id, bool? fromSnapshots = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Cancels all rule events. /// - /// The name of the app. /// The ID of the rule to cancel. /// Rule events cancelled. /// A server side error occurred. - System.Threading.Tasks.Task DeleteRuleEventsAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteRuleEventsAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Simulate a rule. /// - /// The name of the app. /// The rule to simulate. /// Rule simulated. /// A server side error occurred. - System.Threading.Tasks.Task SimulatePOSTAsync(string app, CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task SimulatePOSTAsync(CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Simulate a rule. /// - /// The name of the app. /// The ID of the rule to simulate. /// Rule simulated. /// A server side error occurred. - System.Threading.Tasks.Task SimulateGETAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task SimulateGETAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get rule events. /// - /// The name of the app. /// The optional rule id to filter to events. /// The number of events to skip. /// The number of events to take. /// Rule events returned. /// A server side error occurred. - System.Threading.Tasks.Task GetEventsAsync(string app, string ruleId = null, int? skip = null, int? take = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetEventsAsync(string ruleId = null, int? skip = null, int? take = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Cancels all events. /// - /// The name of the app. /// Events cancelled. /// A server side error occurred. - System.Threading.Tasks.Task DeleteEventsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteEventsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Retry the event immediately. /// - /// The name of the app. /// The event to enqueue. /// Rule enqueued. /// A server side error occurred. - System.Threading.Tasks.Task PutEventAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutEventAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Cancels an event. /// - /// The name of the app. /// The event to enqueue. /// Rule deqeued. /// A server side error occurred. - System.Threading.Tasks.Task DeleteEventAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteEventAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -8449,12 +8059,12 @@ public partial interface IRulesClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class RulesClient : IRulesClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public RulesClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public RulesClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -8483,13 +8093,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/rules/actions"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -8548,7 +8158,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8556,26 +8165,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get rules. /// - /// The name of the app. /// Rules returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetRulesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetRulesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -8640,7 +8242,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8648,30 +8249,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Create a new rule. /// - /// The name of the app. /// The rule object that needs to be added to the app. /// Rule created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostRuleAsync(string app, CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostRuleAsync(CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -8750,7 +8344,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8758,26 +8351,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Cancel the current run. /// - /// The name of the app. /// Rule run cancelled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteRuleRunAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteRuleRunAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/run"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -8840,7 +8426,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8848,16 +8433,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a rule. /// - /// The name of the app. /// The ID of the rule to update. /// The rule object that needs to be added to the app. /// Rule updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutRuleAsync(string app, string id, UpdateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutRuleAsync(string id, UpdateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -8866,17 +8447,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -8955,7 +8533,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -8963,31 +8540,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a rule. /// - /// The name of the app. /// The ID of the rule to delete. /// Rule deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -9056,7 +8626,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9064,31 +8633,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Enable a rule. /// - /// The name of the app. /// The ID of the rule to enable. /// Rule enabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task EnableRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task EnableRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/enable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -9164,7 +8726,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9172,31 +8733,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Disable a rule. /// - /// The name of the app. /// The ID of the rule to disable. /// Rule disabled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DisableRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DisableRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/disable"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -9272,7 +8826,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9280,31 +8833,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Trigger a rule. /// - /// The name of the app. /// The ID of the rule to disable. /// Rule triggered. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task TriggerRuleAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task TriggerRuleAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/trigger"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); @@ -9374,7 +8920,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9382,22 +8927,18 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Run a rule. /// - /// The name of the app. /// The ID of the rule to run. /// Runs the rule from snapeshots if possible. /// Rule started. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutRuleRunAsync(string app, string id, bool? fromSnapshots = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutRuleRunAsync(string id, bool? fromSnapshots = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/run?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); if (fromSnapshots != null) { @@ -9405,14 +8946,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); @@ -9476,7 +9014,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9484,31 +9021,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Cancels all rule events. /// - /// The name of the app. /// The ID of the rule to cancel. /// Rule events cancelled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteRuleEventsAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteRuleEventsAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/events"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -9571,7 +9101,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9579,30 +9108,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Simulate a rule. /// - /// The name of the app. /// The rule to simulate. /// Rule simulated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task SimulatePOSTAsync(string app, CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task SimulatePOSTAsync(CreateRuleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/simulate"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -9681,7 +9203,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9689,31 +9210,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Simulate a rule. /// - /// The name of the app. /// The ID of the rule to simulate. /// Rule simulated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task SimulateGETAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task SimulateGETAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/{id}/simulate"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -9778,7 +9292,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9786,20 +9299,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get rule events. /// - /// The name of the app. /// The optional rule id to filter to events. /// The number of events to skip. /// The number of events to take. /// Rule events returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetEventsAsync(string app, string ruleId = null, int? skip = null, int? take = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetEventsAsync(string ruleId = null, int? skip = null, int? take = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/events?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (ruleId != null) { urlBuilder_.Append(System.Uri.EscapeDataString("ruleId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(ruleId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); @@ -9814,14 +9323,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -9886,7 +9392,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9894,26 +9399,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Cancels all events. /// - /// The name of the app. /// Events cancelled. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteEventsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteEventsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/events"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -9976,7 +9474,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -9984,31 +9481,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Retry the event immediately. /// - /// The name of the app. /// The event to enqueue. /// Rule enqueued. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutEventAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutEventAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/events/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); @@ -10078,7 +9568,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10086,31 +9575,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Cancels an event. /// - /// The name of the app. /// The event to enqueue. /// Rule deqeued. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteEventAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteEventAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/rules/events/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -10179,7 +9661,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10193,13 +9674,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/rules/eventtypes"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -10258,7 +9739,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10276,14 +9756,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/rules/eventtypes/{type}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{type}", System.Uri.EscapeDataString(ConvertToString(type, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -10348,7 +9828,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10365,8 +9844,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -10374,7 +9851,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -10463,20 +9940,18 @@ public partial interface IPlansClient /// /// Get app plan information. /// - /// The name of the app. /// App plan information returned. /// A server side error occurred. - System.Threading.Tasks.Task GetPlansAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetPlansAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Change the app plan. /// - /// The name of the app. /// Plan object that needs to be changed. /// Plan changed or redirect url returned. /// A server side error occurred. - System.Threading.Tasks.Task PutPlanAsync(string app, ChangePlanDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutPlanAsync(ChangePlanDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -10502,12 +9977,12 @@ public partial interface IPlansClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class PlansClient : IPlansClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public PlansClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public PlansClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -10530,26 +10005,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app plan information. /// - /// The name of the app. /// App plan information returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetPlansAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetPlansAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/plans"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -10614,7 +10082,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10622,30 +10089,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Change the app plan. /// - /// The name of the app. /// Plan object that needs to be changed. /// Plan changed or redirect url returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutPlanAsync(string app, ChangePlanDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutPlanAsync(ChangePlanDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/plan"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -10724,7 +10184,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10742,14 +10201,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/plans"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -10814,7 +10273,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10836,14 +10294,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/plan"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -10922,7 +10380,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -10939,8 +10396,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -10948,7 +10403,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -11059,22 +10514,21 @@ public partial interface IPingClient /// /// Can be used to test, if the Squidex API is alive and responding. /// - /// The name of the app. /// Service ping successful. /// A server side error occurred. - System.Threading.Tasks.Task GetAppPingAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAppPingAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class PingClient : IPingClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public PingClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public PingClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -11103,13 +10557,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/info"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -11168,7 +10622,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -11185,13 +10638,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/ping"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); PrepareRequest(client_, request_, urlBuilder_); @@ -11244,7 +10697,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -11255,26 +10707,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Can be used to test, if the Squidex API is alive and responding. /// - /// The name of the app. /// Service ping successful. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAppPingAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAppPingAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/ping/{app}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); PrepareRequest(client_, request_, urlBuilder_); @@ -11327,7 +10772,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -11344,8 +10788,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -11353,7 +10795,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -11452,12 +10894,12 @@ public partial interface INewsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class NewsClient : INewsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public NewsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public NewsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -11487,18 +10929,18 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/news/features?"); + urlBuilder_.Replace("{app}", _options.AppName); if (version != null) { urlBuilder_.Append(System.Uri.EscapeDataString("version") + "=").Append(System.Uri.EscapeDataString(ConvertToString(version, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -11557,7 +10999,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -11574,8 +11015,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -11583,7 +11022,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -11684,12 +11123,12 @@ public partial interface ILanguagesClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class LanguagesClient : ILanguagesClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public LanguagesClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public LanguagesClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -11721,13 +11160,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/languages"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -11786,7 +11225,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -11803,8 +11241,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -11812,7 +11248,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -11901,11 +11337,10 @@ public partial interface IHistoryClient /// /// Get historical events. /// - /// The name of the app. /// The name of the channel. /// Events returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetAppHistoryAsync(string app, string channel = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetAppHistoryAsync(string channel = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -11922,12 +11357,12 @@ public partial interface IHistoryClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class HistoryClient : IHistoryClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public HistoryClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public HistoryClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -11950,32 +11385,25 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get historical events. /// - /// The name of the app. /// The name of the channel. /// Events returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetAppHistoryAsync(string app, string channel = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetAppHistoryAsync(string channel = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/history?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (channel != null) { urlBuilder_.Append(System.Uri.EscapeDataString("channel") + "=").Append(System.Uri.EscapeDataString(ConvertToString(channel, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12040,7 +11468,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12059,6 +11486,7 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/history?"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); if (channel != null) { @@ -12066,12 +11494,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12136,7 +11563,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12153,8 +11579,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -12162,7 +11586,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -12287,12 +11711,12 @@ public partial interface IEventConsumersClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class EventConsumersClient : IEventConsumersClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public EventConsumersClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public EventConsumersClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -12321,13 +11745,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/event-consumers"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12386,7 +11810,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12404,14 +11827,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/event-consumers/{consumerName}/start"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{consumerName}", System.Uri.EscapeDataString(ConvertToString(consumerName, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12487,7 +11910,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12505,14 +11927,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/event-consumers/{consumerName}/stop"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{consumerName}", System.Uri.EscapeDataString(ConvertToString(consumerName, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12588,7 +12010,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12606,14 +12027,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/event-consumers/{consumerName}/reset"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{consumerName}", System.Uri.EscapeDataString(ConvertToString(consumerName, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("PUT"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -12689,7 +12110,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12706,8 +12126,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -12715,7 +12133,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -12821,12 +12239,12 @@ public partial interface IDiagnosticsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class DiagnosticsClient : IDiagnosticsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public DiagnosticsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public DiagnosticsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -12855,13 +12273,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/diagnostics/dump"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); PrepareRequest(client_, request_, urlBuilder_); @@ -12924,7 +12342,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -12938,13 +12355,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/diagnostics/gcdump"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); PrepareRequest(client_, request_, urlBuilder_); @@ -13007,7 +12424,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13024,8 +12440,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -13033,7 +12447,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -13122,11 +12536,10 @@ public partial interface ICommentsClient /// /// Get all watching users.. /// - /// The name of the app. /// The path to the resource. /// Watching users returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetWatchingUsersAsync(string app, string resource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetWatchingUsersAsync(string resource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -13135,58 +12548,54 @@ public partial interface ICommentsClient /// /// When passing in a version you can retrieve all updates since then. /// - /// The name of the app. /// The ID of the comments. /// The current version. /// Comments returned. /// A server side error occurred. - System.Threading.Tasks.Task GetCommentsAsync(string app, string commentsId, long? version = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetCommentsAsync(string commentsId, long? version = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Create a new comment. /// - /// The name of the app. /// The ID of the comments. /// The comment object that needs to created. /// Comment created. /// A server side error occurred. - System.Threading.Tasks.Task PostCommentAsync(string app, string commentsId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostCommentAsync(string commentsId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a comment. /// - /// The name of the app. /// The ID of the comments. /// The ID of the comment. /// The comment object that needs to updated. /// Comment updated. /// A server side error occurred. - System.Threading.Tasks.Task PutCommentAsync(string app, string commentsId, string commentId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutCommentAsync(string commentsId, string commentId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a comment. /// - /// The name of the app. /// The ID of the comments. /// The ID of the comment. /// Comment deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteCommentAsync(string app, string commentsId, string commentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteCommentAsync(string commentsId, string commentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class CommentsClient : ICommentsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public CommentsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public CommentsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -13209,28 +12618,21 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all watching users.. /// - /// The name of the app. /// The path to the resource. /// Watching users returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetWatchingUsersAsync(string app, string resource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetWatchingUsersAsync(string resource, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/watching/{resource}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{resource}", System.Uri.EscapeDataString(ConvertToString(resource, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -13295,7 +12697,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13306,22 +12707,18 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// When passing in a version you can retrieve all updates since then. /// - /// The name of the app. /// The ID of the comments. /// The current version. /// Comments returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetCommentsAsync(string app, string commentsId, long? version = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetCommentsAsync(string commentsId, long? version = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (commentsId == null) throw new System.ArgumentNullException("commentsId"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/comments/{commentsId}?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{commentsId}", System.Uri.EscapeDataString(ConvertToString(commentsId, System.Globalization.CultureInfo.InvariantCulture))); if (version != null) { @@ -13329,14 +12726,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -13401,7 +12795,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13409,16 +12802,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Create a new comment. /// - /// The name of the app. /// The ID of the comments. /// The comment object that needs to created. /// Comment created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostCommentAsync(string app, string commentsId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostCommentAsync(string commentsId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (commentsId == null) throw new System.ArgumentNullException("commentsId"); @@ -13427,17 +12816,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/comments/{commentsId}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{commentsId}", System.Uri.EscapeDataString(ConvertToString(commentsId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -13516,7 +12902,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13524,17 +12909,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a comment. /// - /// The name of the app. /// The ID of the comments. /// The ID of the comment. /// The comment object that needs to updated. /// Comment updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutCommentAsync(string app, string commentsId, string commentId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutCommentAsync(string commentsId, string commentId, UpsertCommentDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (commentsId == null) throw new System.ArgumentNullException("commentsId"); @@ -13546,18 +12927,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/comments/{commentsId}/{commentId}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{commentsId}", System.Uri.EscapeDataString(ConvertToString(commentsId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{commentId}", System.Uri.EscapeDataString(ConvertToString(commentId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -13630,7 +13008,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13638,16 +13015,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a comment. /// - /// The name of the app. /// The ID of the comments. /// The ID of the comment. /// Comment deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteCommentAsync(string app, string commentsId, string commentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteCommentAsync(string commentsId, string commentId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (commentsId == null) throw new System.ArgumentNullException("commentsId"); @@ -13656,18 +13029,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/comments/{commentsId}/{commentId}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{commentsId}", System.Uri.EscapeDataString(ConvertToString(commentsId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{commentId}", System.Uri.EscapeDataString(ConvertToString(commentId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -13736,7 +13106,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -13753,8 +13122,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -13762,7 +13129,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -13875,12 +13242,12 @@ public partial interface INotificationsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class NotificationsClient : INotificationsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public NotificationsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public NotificationsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -13917,6 +13284,7 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/users/{userId}/notifications?"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{userId}", System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))); if (version != null) { @@ -13924,12 +13292,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -13988,7 +13355,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14010,15 +13376,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/users/{userId}/notifications/{commentId}"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{userId}", System.Uri.EscapeDataString(ConvertToString(userId, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{commentId}", System.Uri.EscapeDataString(ConvertToString(commentId, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -14087,7 +13453,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14104,8 +13469,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -14113,7 +13476,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -14202,21 +13565,19 @@ public partial interface IBackupsClient /// /// Get the backup content. /// - /// The name of the app. /// The ID of the backup. /// Backup found and content returned. /// A server side error occurred. - System.Threading.Tasks.Task GetBackupContentAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetBackupContentAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a backup. /// - /// The name of the app. /// The ID of the backup to delete. /// Backup deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteBackupAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteBackupAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -14233,19 +13594,17 @@ public partial interface IBackupsClient /// /// Get all backup jobs. /// - /// The name of the app. /// Backups returned. /// A server side error occurred. - System.Threading.Tasks.Task GetBackupsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetBackupsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Start a new backup. /// - /// The name of the app. /// Backup started. /// A server side error occurred. - System.Threading.Tasks.Task PostBackupAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostBackupAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -14269,12 +13628,12 @@ public partial interface IBackupsClient [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class BackupsClient : IBackupsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public BackupsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public BackupsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -14297,31 +13656,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get the backup content. /// - /// The name of the app. /// The ID of the backup. /// Backup found and content returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetBackupContentAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetBackupContentAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/backups/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -14384,7 +13736,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14392,31 +13743,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a backup. /// - /// The name of the app. /// The ID of the backup to delete. /// Backup deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteBackupAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteBackupAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/backups/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -14485,7 +13829,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14505,6 +13848,7 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/backups/{id}?"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); if (appId != null) { @@ -14516,14 +13860,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -14586,7 +13927,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14594,26 +13934,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all backup jobs. /// - /// The name of the app. /// Backups returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetBackupsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetBackupsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/backups"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -14678,7 +14011,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14686,26 +14018,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Start a new backup. /// - /// The name of the app. /// Backup started. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostBackupAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostBackupAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/backups"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json"); request_.Method = new System.Net.Http.HttpMethod("POST"); @@ -14775,7 +14100,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14789,13 +14113,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/restore"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -14854,7 +14178,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14872,13 +14195,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/restore"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -14945,7 +14268,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -14962,8 +14284,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -14971,7 +14291,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -15060,7 +14380,6 @@ public partial interface IAssetsClient /// /// Get the asset content. /// - /// The name of the app. /// The id or slug of the asset. /// Optional suffix that can be used to seo-optimize the link to the image Has not effect. /// The optional version of the asset. @@ -15079,7 +14398,7 @@ public partial interface IAssetsClient /// True to force a new resize even if it already stored. /// Asset found and content or (resized) image returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetContentBySlugAsync(string app, string idOrSlug, string more, long? version = null, long? cache = null, int? download = null, int? width = null, int? height = null, int? quality = null, ResizeMode? mode = null, string bg = null, float? focusX = null, float? focusY = null, bool? nofocus = null, bool? auto = null, bool? force = null, ImageFormat? format = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetContentBySlugAsync(string idOrSlug, string more, long? version = null, long? cache = null, int? download = null, int? width = null, int? height = null, int? quality = null, ResizeMode? mode = null, string bg = null, float? focusX = null, float? focusY = null, bool? nofocus = null, bool? auto = null, bool? force = null, ImageFormat? format = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15112,54 +14431,49 @@ public partial interface IAssetsClient /// /// Get all asset folders for the app. /// - /// The name of the app. /// The optional parent folder id. /// The scope of the query. /// Asset folders returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetFoldersAsync(string app, string parentId = null, AssetFolderScope? scope = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetFoldersAsync(string parentId = null, AssetFolderScope? scope = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Create an asset folder. /// - /// The name of the app. /// The asset folder object that needs to be added to the App. /// Asset folder created. /// A server side error occurred. - System.Threading.Tasks.Task PostAssetFolderAsync(string app, CreateAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostAssetFolderAsync(CreateAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update an asset folder. /// - /// The name of the app. /// The ID of the asset folder. /// The asset folder object that needs to updated. /// Asset folder updated. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetFolderAsync(string app, string id, RenameAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetFolderAsync(string id, RenameAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete an asset folder. /// - /// The name of the app. /// The ID of the asset folder to delete. /// Asset folder deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteAssetFolderAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteAssetFolderAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Move an asset folder. /// - /// The name of the app. /// The ID of the asset folder. /// The asset folder object that needs to updated. /// Asset folder moved. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetFolderParentAsync(string app, string id, MoveAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetFolderParentAsync(string id, MoveAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15168,21 +14482,19 @@ public partial interface IAssetsClient /// /// Get all tags for assets. /// - /// The name of the app. /// Assets tags returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetTagsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetTagsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Rename an asset tag. /// - /// The name of the app. /// The tag to return. /// The required request object. /// Asset tag renamed and new tags returned. /// A server side error occurred. - System.Threading.Tasks.Task> PutTagAsync(string app, string name, RenameTagDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> PutTagAsync(string name, RenameTagDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15191,7 +14503,6 @@ public partial interface IAssetsClient /// /// Get all assets for the app. /// - /// The name of the app. /// Optional number of items to take. /// Optional number of items to skip. /// Optional OData order definition. @@ -15201,7 +14512,7 @@ public partial interface IAssetsClient /// The optional json query. /// Assets returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetsAsync(string app, double? top = null, double? skip = null, string orderby = null, string filter = null, string parentId = null, string ids = null, string q = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetsAsync(double? top = null, double? skip = null, string orderby = null, string filter = null, string parentId = null, string ids = null, string q = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15210,13 +14521,12 @@ public partial interface IAssetsClient /// /// You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. /// - /// The name of the app. /// The optional parent folder id. /// The optional custom asset id. /// True to duplicate the asset, event if the file has been uploaded. /// Asset created. /// A server side error occurred. - System.Threading.Tasks.Task PostAssetAsync(string app, string parentId = null, string id = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostAssetAsync(string parentId = null, string id = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15225,21 +14535,19 @@ public partial interface IAssetsClient /// /// Get all assets for the app. /// - /// The name of the app. /// The required query object. /// Assets returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetsPostAsync(string app, QueryDto query, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetsPostAsync(QueryDto query, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get an asset by id. /// - /// The name of the app. /// The ID of the asset to retrieve. /// Asset found. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15248,46 +14556,42 @@ public partial interface IAssetsClient /// /// You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. /// - /// The name of the app. /// The optional custom asset id. /// The optional parent folder id. /// True to duplicate the asset, event if the file has been uploaded. /// Asset created or updated. /// A server side error occurred. - System.Threading.Tasks.Task PostUpsertAssetAsync(string app, string id, string parentId = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostUpsertAssetAsync(string id, string parentId = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update an asset. /// - /// The name of the app. /// The ID of the asset. /// The asset object that needs to updated. /// Asset updated. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetAsync(string app, string id, AnnotateAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetAsync(string id, AnnotateAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete an asset. /// - /// The name of the app. /// The ID of the asset to delete. /// True to check referrers of this asset. /// True to delete the asset permanently. /// Asset deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteAssetAsync(string app, string id, bool? checkReferrers = null, bool? permanent = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteAssetAsync(string id, bool? checkReferrers = null, bool? permanent = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Bulk update assets. /// - /// The name of the app. /// The bulk update request. /// Assets created, update or delete. /// A server side error occurred. - System.Threading.Tasks.Task> BulkUpdateAssetsAsync(string app, BulkUpdateAssetsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> BulkUpdateAssetsAsync(BulkUpdateAssetsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -15296,34 +14600,32 @@ public partial interface IAssetsClient /// /// Use multipart request to upload an asset. /// - /// The name of the app. /// The ID of the asset. /// Asset updated. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetContentAsync(string app, string id, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetContentAsync(string id, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Moves the asset. /// - /// The name of the app. /// The ID of the asset. /// The asset object that needs to updated. /// Asset moved. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetParentAsync(string app, string id, MoveAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetParentAsync(string id, MoveAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class AssetsClient : IAssetsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public AssetsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public AssetsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -15346,7 +14648,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get the asset content. /// - /// The name of the app. /// The id or slug of the asset. /// Optional suffix that can be used to seo-optimize the link to the image Has not effect. /// The optional version of the asset. @@ -15365,17 +14666,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// True to force a new resize even if it already stored. /// Asset found and content or (resized) image returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetContentBySlugAsync(string app, string idOrSlug, string more, long? version = null, long? cache = null, int? download = null, int? width = null, int? height = null, int? quality = null, ResizeMode? mode = null, string bg = null, float? focusX = null, float? focusY = null, bool? nofocus = null, bool? auto = null, bool? force = null, ImageFormat? format = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetContentBySlugAsync(string idOrSlug, string more, long? version = null, long? cache = null, int? download = null, int? width = null, int? height = null, int? quality = null, ResizeMode? mode = null, string bg = null, float? focusX = null, float? focusY = null, bool? nofocus = null, bool? auto = null, bool? force = null, ImageFormat? format = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (idOrSlug == null) throw new System.ArgumentNullException("idOrSlug"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/assets/{app}/{idOrSlug}/{more}?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{idOrSlug}", System.Uri.EscapeDataString(ConvertToString(idOrSlug, System.Globalization.CultureInfo.InvariantCulture))); urlBuilder_.Replace("{more}", System.Uri.EscapeDataString(ConvertToString(more, System.Globalization.CultureInfo.InvariantCulture))); if (version != null) @@ -15436,19 +14734,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - - - - - - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -15511,7 +14801,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -15544,6 +14833,7 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/assets/{id}?"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); if (version != null) { @@ -15603,16 +14893,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - - - - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -15675,7 +14960,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -15686,19 +14970,15 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all asset folders for the app. /// - /// The name of the app. /// The optional parent folder id. /// The scope of the query. /// Asset folders returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetFoldersAsync(string app, string parentId = null, AssetFolderScope? scope = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetFoldersAsync(string parentId = null, AssetFolderScope? scope = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/folders?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (parentId != null) { urlBuilder_.Append(System.Uri.EscapeDataString("parentId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); @@ -15709,14 +14989,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -15781,7 +15058,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -15789,30 +15065,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Create an asset folder. /// - /// The name of the app. /// The asset folder object that needs to be added to the App. /// Asset folder created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostAssetFolderAsync(string app, CreateAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostAssetFolderAsync(CreateAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/folders"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -15891,7 +15160,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -15899,16 +15167,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update an asset folder. /// - /// The name of the app. /// The ID of the asset folder. /// The asset folder object that needs to updated. /// Asset folder updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetFolderAsync(string app, string id, RenameAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetFolderAsync(string id, RenameAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -15917,17 +15181,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/folders/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -16006,7 +15267,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16014,31 +15274,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete an asset folder. /// - /// The name of the app. /// The ID of the asset folder to delete. /// Asset folder deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteAssetFolderAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteAssetFolderAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/folders/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -16107,7 +15360,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16115,16 +15367,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Move an asset folder. /// - /// The name of the app. /// The ID of the asset folder. /// The asset folder object that needs to updated. /// Asset folder moved. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetFolderParentAsync(string app, string id, MoveAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetFolderParentAsync(string id, MoveAssetFolderDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -16133,17 +15381,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/folders/{id}/parent"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -16222,7 +15467,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16233,26 +15477,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all tags for assets. /// - /// The name of the app. /// Assets tags returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetTagsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetTagsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/tags"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -16317,7 +15554,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16325,16 +15561,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Rename an asset tag. /// - /// The name of the app. /// The tag to return. /// The required request object. /// Asset tag renamed and new tags returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> PutTagAsync(string app, string name, RenameTagDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> PutTagAsync(string name, RenameTagDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (name == null) throw new System.ArgumentNullException("name"); @@ -16343,17 +15575,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/tags/{name}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{name}", System.Uri.EscapeDataString(ConvertToString(name, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -16432,7 +15661,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16443,7 +15671,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all assets for the app. /// - /// The name of the app. /// Optional number of items to take. /// Optional number of items to skip. /// Optional OData order definition. @@ -16453,14 +15680,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// The optional json query. /// Assets returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetsAsync(string app, double? top = null, double? skip = null, string orderby = null, string filter = null, string parentId = null, string ids = null, string q = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetsAsync(double? top = null, double? skip = null, string orderby = null, string filter = null, string parentId = null, string ids = null, string q = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (top != null) { urlBuilder_.Append(System.Uri.EscapeDataString("$top") + "=").Append(System.Uri.EscapeDataString(ConvertToString(top, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); @@ -16491,16 +15715,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - - - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -16565,7 +15784,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16576,20 +15794,16 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. /// - /// The name of the app. /// The optional parent folder id. /// The optional custom asset id. /// True to duplicate the asset, event if the file has been uploaded. /// Asset created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostAssetAsync(string app, string parentId = null, string id = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostAssetAsync(string parentId = null, string id = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); if (parentId != null) { urlBuilder_.Append(System.Uri.EscapeDataString("ParentId") + "=").Append(System.Uri.EscapeDataString(ConvertToString(parentId, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); @@ -16604,15 +15818,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - - var boundary_ = System.Guid.NewGuid().ToString(); var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); content_.Headers.Remove("Content-Type"); @@ -16712,7 +15922,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16723,30 +15932,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get all assets for the app. /// - /// The name of the app. /// The required query object. /// Assets returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetsPostAsync(string app, QueryDto query, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetsPostAsync(QueryDto query, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (query == null) throw new System.ArgumentNullException("query"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/query"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(query, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -16825,7 +16027,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16833,31 +16034,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get an asset by id. /// - /// The name of the app. /// The ID of the asset to retrieve. /// Asset found. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -16922,7 +16116,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -16933,23 +16126,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. /// - /// The name of the app. /// The optional custom asset id. /// The optional parent folder id. /// True to duplicate the asset, event if the file has been uploaded. /// Asset created or updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostUpsertAssetAsync(string app, string id, string parentId = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostUpsertAssetAsync(string id, string parentId = null, bool? duplicate = null, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); if (parentId != null) { @@ -16961,15 +16150,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - - var boundary_ = System.Guid.NewGuid().ToString(); var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); content_.Headers.Remove("Content-Type"); @@ -17069,7 +16254,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17077,16 +16261,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update an asset. /// - /// The name of the app. /// The ID of the asset. /// The asset object that needs to updated. /// Asset updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetAsync(string app, string id, AnnotateAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetAsync(string id, AnnotateAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -17095,17 +16275,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -17184,7 +16361,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17192,23 +16368,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete an asset. /// - /// The name of the app. /// The ID of the asset to delete. /// True to check referrers of this asset. /// True to delete the asset permanently. /// Asset deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteAssetAsync(string app, string id, bool? checkReferrers = null, bool? permanent = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteAssetAsync(string id, bool? checkReferrers = null, bool? permanent = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}?"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); if (checkReferrers != null) { @@ -17220,14 +16392,11 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } urlBuilder_.Length--; - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -17296,7 +16465,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17304,30 +16472,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Bulk update assets. /// - /// The name of the app. /// The bulk update request. /// Assets created, update or delete. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> BulkUpdateAssetsAsync(string app, BulkUpdateAssetsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> BulkUpdateAssetsAsync(BulkUpdateAssetsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/bulk"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -17406,7 +16567,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17417,31 +16577,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Use multipart request to upload an asset. /// - /// The name of the app. /// The ID of the asset. /// Asset updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetContentAsync(string app, string id, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetContentAsync(string id, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}/content"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var boundary_ = System.Guid.NewGuid().ToString(); var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); content_.Headers.Remove("Content-Type"); @@ -17541,7 +16694,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17549,16 +16701,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Moves the asset. /// - /// The name of the app. /// The ID of the asset. /// The asset object that needs to updated. /// Asset moved. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetParentAsync(string app, string id, MoveAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetParentAsync(string id, MoveAssetDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -17567,17 +16715,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/{id}/parent"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -17656,7 +16801,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -17673,8 +16817,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -17682,7 +16824,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try @@ -17771,20 +16913,18 @@ public partial interface IAppsClient /// /// Get the app asset scripts. /// - /// The name of the app to get the asset scripts for. /// Asset scripts returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAssetScriptsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAssetScriptsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the app asset scripts. /// - /// The name of the app to update. /// The values to update. /// Asset scripts updated. /// A server side error occurred. - System.Threading.Tasks.Task PutAssetScriptsAsync(string app, UpdateAssetScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAssetScriptsAsync(UpdateAssetScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -17793,10 +16933,9 @@ public partial interface IAppsClient /// /// Gets all configured clients for the app with the specified name. /// - /// The name of the app. /// Clients returned. /// A server side error occurred. - System.Threading.Tasks.Task GetClientsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetClientsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -17806,11 +16945,10 @@ public partial interface IAppsClient /// Create a new client for the app with the specified name. ///
The client secret is auto generated on the server and returned. The client does not expire, the access token is valid for 30 days. /// - /// The name of the app. /// Client object that needs to be added to the app. /// Client created. /// A server side error occurred. - System.Threading.Tasks.Task PostClientAsync(string app, CreateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostClientAsync(CreateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -17819,12 +16957,11 @@ public partial interface IAppsClient /// /// Only the display name can be changed, create a new client if necessary. /// - /// The name of the app. /// The ID of the client that must be updated. /// Client object that needs to be updated. /// Client updated. /// A server side error occurred. - System.Threading.Tasks.Task PutClientAsync(string app, string id, UpdateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutClientAsync(string id, UpdateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -17833,165 +16970,148 @@ public partial interface IAppsClient /// /// The application that uses this client credentials cannot access the API after it has been revoked. /// - /// The name of the app. /// The ID of the client that must be deleted. /// Client deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteClientAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteClientAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get app contributors. /// - /// The name of the app. /// Contributors returned. /// A server side error occurred. - System.Threading.Tasks.Task GetContributorsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetContributorsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Assign contributor to app. /// - /// The name of the app. /// Contributor object that needs to be added to the app. /// Contributor assigned to app. /// A server side error occurred. - System.Threading.Tasks.Task PostContributorAsync(string app, AssignContributorDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostContributorAsync(AssignContributorDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Remove yourself. /// - /// The name of the app. /// Contributor removed. /// A server side error occurred. - System.Threading.Tasks.Task DeleteMyselfAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteMyselfAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Remove contributor. /// - /// The name of the app. /// The ID of the contributor. /// Contributor removed. /// A server side error occurred. - System.Threading.Tasks.Task DeleteContributorAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteContributorAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get the app image. /// - /// The name of the app. /// App image found and content or (resized) image returned. /// A server side error occurred. - System.Threading.Tasks.Task GetImageAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetImageAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Upload the app image. /// - /// The name of the app to update. /// App image uploaded. /// A server side error occurred. - System.Threading.Tasks.Task UploadImageAsync(string app, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task UploadImageAsync(FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Remove the app image. /// - /// The name of the app to update. /// App image removed. /// A server side error occurred. - System.Threading.Tasks.Task DeleteImageAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteImageAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get app languages. /// - /// The name of the app. /// Languages returned. /// A server side error occurred. - System.Threading.Tasks.Task GetLanguagesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetLanguagesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Attaches an app language. /// - /// The name of the app. /// The language to add to the app. /// Language created. /// A server side error occurred. - System.Threading.Tasks.Task PostLanguageAsync(string app, AddLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostLanguageAsync(AddLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Updates an app language. /// - /// The name of the app. /// The language to update. /// The language object. /// Language updated. /// A server side error occurred. - System.Threading.Tasks.Task PutLanguageAsync(string app, string language, UpdateLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutLanguageAsync(string language, UpdateLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Deletes an app language. /// - /// The name of the app. /// The language to delete from the app. /// Language deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteLanguageAsync(string app, string language, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteLanguageAsync(string language, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get app roles. /// - /// The name of the app. /// Roles returned. /// A server side error occurred. - System.Threading.Tasks.Task GetRolesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetRolesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Add role to app. /// - /// The name of the app. /// Role object that needs to be added to the app. /// Role created. /// A server side error occurred. - System.Threading.Tasks.Task PostRoleAsync(string app, AddRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostRoleAsync(AddRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get app permissions. /// - /// The name of the app. /// App permissions returned. /// A server side error occurred. - System.Threading.Tasks.Task> GetPermissionsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task> GetPermissionsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update an app role. /// - /// The name of the app. /// The name of the role to be updated. /// Role to be updated for the app. /// Role updated. /// A server side error occurred. - System.Threading.Tasks.Task PutRoleAsync(string app, string roleName, UpdateRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutRoleAsync(string roleName, UpdateRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Remove role from app. /// - /// The name of the app. /// The name of the role. /// Role deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteRoleAsync(string app, string roleName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteRoleAsync(string roleName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// @@ -18035,110 +17155,100 @@ public partial interface IAppsClient /// /// Get an app by name. /// - /// The name of the app. /// Apps returned. /// A server side error occurred. - System.Threading.Tasks.Task GetAppAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetAppAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the app. /// - /// The name of the app to update. /// The values to update. /// App updated. /// A server side error occurred. - System.Threading.Tasks.Task PutAppAsync(string app, UpdateAppDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAppAsync(UpdateAppDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete the app. /// - /// The name of the app to delete. /// App deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteAppAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteAppAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Transfer the app. /// - /// The name of the app to update. /// The team information. /// App transferred. /// A server side error occurred. - System.Threading.Tasks.Task PutAppTeamAsync(string app, TransferToTeamDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutAppTeamAsync(TransferToTeamDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get the app settings. /// - /// The name of the app to get the settings for. /// App settings returned. /// A server side error occurred. - System.Threading.Tasks.Task GetSettingsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetSettingsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update the app settings. /// - /// The name of the app to update. /// The values to update. /// App updated. /// A server side error occurred. - System.Threading.Tasks.Task PutSettingsAsync(string app, UpdateAppSettingsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutSettingsAsync(UpdateAppSettingsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Get app workflow. /// - /// The name of the app. /// Workflows returned. /// A server side error occurred. - System.Threading.Tasks.Task GetWorkflowsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task GetWorkflowsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Create a workflow. /// - /// The name of the app. /// The new workflow. /// Workflow created. /// A server side error occurred. - System.Threading.Tasks.Task PostWorkflowAsync(string app, AddWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PostWorkflowAsync(AddWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Update a workflow. /// - /// The name of the app. /// The ID of the workflow to update. /// The new workflow. /// Workflow updated. /// A server side error occurred. - System.Threading.Tasks.Task PutWorkflowAsync(string app, string id, UpdateWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task PutWorkflowAsync(string id, UpdateWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// /// Delete a workflow. /// - /// The name of the app. /// The ID of the workflow to update. /// Workflow deleted. /// A server side error occurred. - System.Threading.Tasks.Task DeleteWorkflowAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); + System.Threading.Tasks.Task DeleteWorkflowAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)); } [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.17.0.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v9.0.0.0))")] public partial class AppsClient : IAppsClient { - private Squidex.ClientLibrary.Configuration.IHttpClientProvider _httpClientProvider; + private Squidex.ClientLibrary.SquidexOptions _options; private System.Lazy _settings; - public AppsClient(Squidex.ClientLibrary.Configuration.IHttpClientProvider httpClientProvider) + public AppsClient(Squidex.ClientLibrary.SquidexOptions options) { - _httpClientProvider = httpClientProvider; + _options = options; _settings = new System.Lazy(CreateSerializerSettings); } @@ -18161,26 +17271,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get the app asset scripts. /// - /// The name of the app to get the asset scripts for. /// Asset scripts returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAssetScriptsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAssetScriptsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/scripts"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -18245,7 +17348,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18253,30 +17355,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the app asset scripts. /// - /// The name of the app to update. /// The values to update. /// Asset scripts updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAssetScriptsAsync(string app, UpdateAssetScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAssetScriptsAsync(UpdateAssetScriptsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/assets/scripts"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -18355,7 +17450,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18366,26 +17460,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Gets all configured clients for the app with the specified name. /// - /// The name of the app. /// Clients returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetClientsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetClientsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/clients"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -18450,7 +17537,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18462,30 +17548,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// Create a new client for the app with the specified name. ///
The client secret is auto generated on the server and returned. The client does not expire, the access token is valid for 30 days. /// - /// The name of the app. /// Client object that needs to be added to the app. /// Client created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostClientAsync(string app, CreateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostClientAsync(CreateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/clients"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -18564,7 +17643,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18575,16 +17653,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Only the display name can be changed, create a new client if necessary. /// - /// The name of the app. /// The ID of the client that must be updated. /// Client object that needs to be updated. /// Client updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutClientAsync(string app, string id, UpdateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutClientAsync(string id, UpdateClientDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -18593,17 +17667,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/clients/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -18682,7 +17753,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18693,31 +17763,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// The application that uses this client credentials cannot access the API after it has been revoked. /// - /// The name of the app. /// The ID of the client that must be deleted. /// Client deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteClientAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteClientAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/clients/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -18792,7 +17855,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18800,26 +17862,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app contributors. /// - /// The name of the app. /// Contributors returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetContributorsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetContributorsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/contributors"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -18884,7 +17939,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -18892,30 +17946,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Assign contributor to app. /// - /// The name of the app. /// Contributor object that needs to be added to the app. /// Contributor assigned to app. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostContributorAsync(string app, AssignContributorDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostContributorAsync(AssignContributorDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/contributors"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -18994,7 +18041,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19002,26 +18048,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Remove yourself. /// - /// The name of the app. /// Contributor removed. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteMyselfAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteMyselfAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/contributors/me"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -19096,7 +18135,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19104,31 +18142,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Remove contributor. /// - /// The name of the app. /// The ID of the contributor. /// Contributor removed. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteContributorAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteContributorAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/contributors/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -19203,7 +18234,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19211,26 +18241,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get the app image. /// - /// The name of the app. /// App image found and content or (resized) image returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetImageAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetImageAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/image"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/octet-stream")); @@ -19293,7 +18316,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19301,26 +18323,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Upload the app image. /// - /// The name of the app to update. /// App image uploaded. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task UploadImageAsync(string app, FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task UploadImageAsync(FileParameter file = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/image"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var boundary_ = System.Guid.NewGuid().ToString(); var content_ = new System.Net.Http.MultipartFormDataContent(boundary_); content_.Headers.Remove("Content-Type"); @@ -19410,7 +18425,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19418,26 +18432,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Remove the app image. /// - /// The name of the app to update. /// App image removed. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteImageAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteImageAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/image"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -19512,7 +18519,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19520,26 +18526,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app languages. /// - /// The name of the app. /// Languages returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetLanguagesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetLanguagesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/languages"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -19604,7 +18603,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19612,30 +18610,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Attaches an app language. /// - /// The name of the app. /// The language to add to the app. /// Language created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostLanguageAsync(string app, AddLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostLanguageAsync(AddLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/languages"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -19714,7 +18705,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19722,16 +18712,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Updates an app language. /// - /// The name of the app. /// The language to update. /// The language object. /// Language updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutLanguageAsync(string app, string language, UpdateLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutLanguageAsync(string language, UpdateLanguageDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (language == null) throw new System.ArgumentNullException("language"); @@ -19740,17 +18726,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/languages/{language}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{language}", System.Uri.EscapeDataString(ConvertToString(language, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -19829,7 +18812,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19837,31 +18819,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Deletes an app language. /// - /// The name of the app. /// The language to delete from the app. /// Language deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteLanguageAsync(string app, string language, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteLanguageAsync(string language, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (language == null) throw new System.ArgumentNullException("language"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/languages/{language}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{language}", System.Uri.EscapeDataString(ConvertToString(language, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -19936,7 +18911,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -19944,26 +18918,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app roles. /// - /// The name of the app. /// Roles returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetRolesAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetRolesAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/roles"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20028,7 +18995,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20036,30 +19002,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Add role to app. /// - /// The name of the app. /// Role object that needs to be added to the app. /// Role created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostRoleAsync(string app, AddRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostRoleAsync(AddRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/roles"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -20138,7 +19097,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20146,26 +19104,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app permissions. /// - /// The name of the app. /// App permissions returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task> GetPermissionsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task> GetPermissionsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/roles/permissions"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20230,7 +19181,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20238,16 +19188,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update an app role. /// - /// The name of the app. /// The name of the role to be updated. /// Role to be updated for the app. /// Role updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutRoleAsync(string app, string roleName, UpdateRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutRoleAsync(string roleName, UpdateRoleDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (roleName == null) throw new System.ArgumentNullException("roleName"); @@ -20256,17 +19202,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/roles/{roleName}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{roleName}", System.Uri.EscapeDataString(ConvertToString(roleName, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -20345,7 +19288,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20353,31 +19295,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Remove role from app. /// - /// The name of the app. /// The name of the role. /// Role deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteRoleAsync(string app, string roleName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteRoleAsync(string roleName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (roleName == null) throw new System.ArgumentNullException("roleName"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/roles/{roleName}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{roleName}", System.Uri.EscapeDataString(ConvertToString(roleName, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20452,7 +19387,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20470,13 +19404,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20535,7 +19469,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20557,13 +19490,13 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps"); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -20646,7 +19579,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20668,14 +19600,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/teams/{team}/apps"); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{team}", System.Uri.EscapeDataString(ConvertToString(team, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20734,7 +19666,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20742,26 +19673,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get an app by name. /// - /// The name of the app. /// Apps returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetAppAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetAppAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -20826,7 +19750,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20834,30 +19757,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the app. /// - /// The name of the app to update. /// The values to update. /// App updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAppAsync(string app, UpdateAppDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAppAsync(UpdateAppDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -20936,7 +19852,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -20944,26 +19859,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete the app. /// - /// The name of the app to delete. /// App deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteAppAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteAppAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); PrepareRequest(client_, request_, urlBuilder_); @@ -21032,7 +19940,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21040,30 +19947,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Transfer the app. /// - /// The name of the app to update. /// The team information. /// App transferred. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutAppTeamAsync(string app, TransferToTeamDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutAppTeamAsync(TransferToTeamDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/team"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -21142,7 +20042,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21150,26 +20049,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get the app settings. /// - /// The name of the app to get the settings for. /// App settings returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetSettingsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetSettingsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/settings"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -21234,7 +20126,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21242,30 +20133,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update the app settings. /// - /// The name of the app to update. /// The values to update. /// App updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutSettingsAsync(string app, UpdateAppSettingsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutSettingsAsync(UpdateAppSettingsDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/settings"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -21344,7 +20228,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21352,26 +20235,19 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Get app workflow. /// - /// The name of the app. /// Workflows returned. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task GetWorkflowsAsync(string app, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task GetWorkflowsAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/workflows"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -21436,7 +20312,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21444,30 +20319,23 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Create a workflow. /// - /// The name of the app. /// The new workflow. /// Workflow created. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PostWorkflowAsync(string app, AddWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PostWorkflowAsync(AddWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (request == null) throw new System.ArgumentNullException("request"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/workflows"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -21546,7 +20414,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21554,16 +20421,12 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Update a workflow. /// - /// The name of the app. /// The ID of the workflow to update. /// The new workflow. /// Workflow updated. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task PutWorkflowAsync(string app, string id, UpdateWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task PutWorkflowAsync(string id, UpdateWorkflowDto request, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); @@ -21572,17 +20435,14 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/workflows/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(request, _settings.Value); var content_ = new System.Net.Http.StringContent(json_); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); @@ -21661,7 +20521,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21669,31 +20528,24 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() /// /// Delete a workflow. /// - /// The name of the app. /// The ID of the workflow to update. /// Workflow deleted. /// A server side error occurred. - public virtual async System.Threading.Tasks.Task DeleteWorkflowAsync(string app, string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) + public virtual async System.Threading.Tasks.Task DeleteWorkflowAsync(string id, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { - if (app == null) - throw new System.ArgumentNullException("app"); - if (id == null) throw new System.ArgumentNullException("id"); var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("api/apps/{app}/workflows/{id}"); - urlBuilder_.Replace("{app}", System.Uri.EscapeDataString(ConvertToString(app, System.Globalization.CultureInfo.InvariantCulture))); + urlBuilder_.Replace("{app}", _options.AppName); urlBuilder_.Replace("{id}", System.Uri.EscapeDataString(ConvertToString(id, System.Globalization.CultureInfo.InvariantCulture))); - var client_ = _httpClientProvider.Get(); + var client_ = _options.ClientProvider.Get(); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { - - request_.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, app); - request_.Method = new System.Net.Http.HttpMethod("DELETE"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); @@ -21768,7 +20620,6 @@ private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings() } finally { - _httpClientProvider.Return(client_); } } @@ -21785,8 +20636,6 @@ public ObjectResponseResult(T responseObject, string responseText) public string Text { get; } } - public bool ReadResponseAsString { get; set; } - protected virtual async System.Threading.Tasks.Task> ReadObjectResponseAsync(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary> headers, System.Threading.CancellationToken cancellationToken) { if (response == null || response.Content == null) @@ -21794,7 +20643,7 @@ protected virtual async System.Threading.Tasks.Task> Rea return new ObjectResponseResult(default(T), string.Empty); } - if (ReadResponseAsString) + if (_options.ReadResponseAsString) { var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false); try diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SpecialHeaders.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SpecialHeaders.cs deleted file mode 100644 index 39addbde..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SpecialHeaders.cs +++ /dev/null @@ -1,13 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -namespace Squidex.ClientLibrary; - -internal static class SpecialHeaders -{ - public const string AppName = "X-App"; -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs new file mode 100644 index 00000000..3448aab3 --- /dev/null +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClient.cs @@ -0,0 +1,268 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.Collections.Concurrent; +using Squidex.ClientLibrary.Management; +using Squidex.ClientLibrary.Utils; + +namespace Squidex.ClientLibrary; + +/// +/// Default implementation of the interface. +/// +/// +public sealed class SquidexClient : ISquidexClient +{ + private readonly ConcurrentDictionary<(string, Type, Type), object> contentsClient = new ConcurrentDictionary<(string, Type, Type), object>(); + private readonly ConcurrentDictionary dynamicContentsClient = new ConcurrentDictionary(); + private readonly ConcurrentDictionary<(Type, Type), object> sharedContentsClient = new ConcurrentDictionary<(Type, Type), object>(); + private IAppsClient appsClient; + private IAssetsClient assetsClient; + private IBackupsClient backupsClient; + private ICommentsClient commentsClient; + private IContentsSharedClient contentsSharedClient; + private IDiagnosticsClient diagnosticsClient; + private IEventConsumersClient eventConsumersClient; + private IExtendableRulesClient extendableRulesClient; + private IHistoryClient historyClient; + private ILanguagesClient languagesClient; + private IPingClient pingClient; + private IPlansClient plansClient; + private IRulesClient rulesClient; + private ISchemasClient schemasClient; + private ISearchClient searchClient; + private IStatisticsClient statisticsClient; + private ITeamsClient teamsClient; + private ITemplatesClient templatesClient; + private ITranslationsClient translationsClient; + private IUserManagementClient userManagementClient; + private IUsersClient usersClient; + + /// + public SquidexOptions Options { get; } + + /// + /// Initializes a new instance of the class with the options. + /// + /// The options. Cannot be null. + /// is null. + public SquidexClient(SquidexOptions options) + { + Guard.NotNull(options, nameof(options)); + + options.CheckAndFreeze(); + Options = options; + } + + /// + public string? GenerateImageUrl(string? id) + { + if (id == null) + { + return null; + } + + if (!string.IsNullOrWhiteSpace(Options.AssetCDN)) + { + return GenerateUrl(Options.AssetCDN, id); + } + + return GenerateUrl(Options.Url, $"api/assets/{id}"); + } + + /// + public string? GenerateImageUrl(IEnumerable? id) + { + return GenerateImageUrl(id?.FirstOrDefault()); + } + + /// + public string? GenerateUrl(string? relativeUrl) + { + return GenerateUrl(Options.Url, relativeUrl); + } + + /// + public string? GenerateAssetCDNUrl(string relativeUrl) + { + return GenerateUrl(Options.AssetCDN, relativeUrl); + } + + /// + public string? GenerateContentCDNUrl(string relativeUrl) + { + return GenerateUrl(Options.ContentCDN, relativeUrl); + } + + private static string? GenerateUrl(string baseUrl, string? relativeUrl) + { + if (relativeUrl == null) + { + return null; + } + + if (string.IsNullOrWhiteSpace(baseUrl)) + { + throw new InvalidOperationException("URL is not configured."); + } + + return $"{baseUrl}{relativeUrl.TrimStart('/')}"; + } + + /// + public IAppsClient Apps + { + get => appsClient ??= new AppsClient(Options); + } + + /// + public IAssetsClient Assets + { + get => assetsClient ??= new AssetsClient(Options); + } + + /// + public IBackupsClient Backups + { + get => backupsClient ??= new BackupsClient(Options); + } + + /// + public ICommentsClient Comments + { + get => commentsClient ??= new CommentsClient(Options); + } + + /// + public IContentsSharedClient SharedDynamicContents + { + get => contentsSharedClient ??= new ContentsSharedClient(Options); + } + + /// + public IDiagnosticsClient Diagnostics + { + get => diagnosticsClient ??= new DiagnosticsClient(Options); + } + + /// + public IEventConsumersClient EventConsumers + { + get => eventConsumersClient ??= new EventConsumersClient(Options); + } + + /// + public IExtendableRulesClient ExtendableRules + { + get => extendableRulesClient ??= new ExtendableRulesClient(Options); + } + + /// + public IHistoryClient History + { + get => historyClient ??= new HistoryClient(Options); + } + + /// + public ILanguagesClient Languages + { + get => languagesClient ??= new LanguagesClient(Options); + } + + /// + public IPingClient Ping + { + get => pingClient ??= new PingClient(Options); + } + + /// + public IPlansClient Plans + { + get => plansClient ??= new PlansClient(Options); + } + + /// + public IRulesClient Rules + { + get => rulesClient ??= new RulesClient(Options); + } + + /// + public ISchemasClient Schemas + { + get => schemasClient ??= new SchemasClient(Options); + } + + /// + public ISearchClient Search + { + get => searchClient ??= new SearchClient(Options); + } + + /// + public IStatisticsClient Statistics + { + get => statisticsClient ??= new StatisticsClient(Options); + } + + /// + public ITeamsClient Teams + { + get => teamsClient ??= new TeamsClient(Options); + } + + /// + public ITemplatesClient Templates + { + get => templatesClient ??= new TemplatesClient(Options); + } + + /// + public ITranslationsClient Translations + { + get => translationsClient ??= new TranslationsClient(Options); + } + + /// + public IUsersClient Users + { + get => usersClient ??= new UsersClient(Options); + } + + /// + public IUserManagementClient UserManagement + { + get => userManagementClient ??= new UserManagementClient(Options); + } + + /// + public IContentsClient Contents(string schemaName) where TEntity : Content where TData : class, new() + { + return (IContentsClient)contentsClient.GetOrAdd((schemaName, typeof(TEntity), typeof(TData)), k => + new ContentsClient(Options, k.Item1)); + } + + /// + public IContentsClient DynamicContents(string schemaName) + { + return (IContentsClient)dynamicContentsClient.GetOrAdd(schemaName, k => + new ContentsClient(Options, k)); + } + + /// + public IContentsSharedClient SharedContents() where TEntity : Content where TData : class, new() + { + return (IContentsSharedClient)sharedContentsClient.GetOrAdd((typeof(TEntity), typeof(TData)), k => + new ContentsSharedClient(Options)); + } + + /// + public HttpClient CreateHttpClient() + { + return Options.ClientProvider.Get(); + } +} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs deleted file mode 100644 index 391aa00d..00000000 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexClientManager.cs +++ /dev/null @@ -1,320 +0,0 @@ -// ========================================================================== -// Squidex Headless CMS -// ========================================================================== -// Copyright (c) Squidex UG (haftungsbeschraenkt) -// All rights reserved. Licensed under the MIT license. -// ========================================================================== - -using Squidex.ClientLibrary.Management; -using Squidex.ClientLibrary.Utils; - -namespace Squidex.ClientLibrary; - -/// -/// Default implementation of the interface. -/// -/// -public sealed class SquidexClientManager : ISquidexClientManager -{ - /// - public string App - { - get { return Options.AppName; } - } - - /// - public SquidexOptions Options { get; } - - /// - /// Initializes a new instance of the class with the options. - /// - /// The options. Cannot be null. - /// is null. - public SquidexClientManager(SquidexOptions options) - { - Guard.NotNull(options, nameof(options)); - - options.CheckAndFreeze(); - Options = options; - } - - /// - public string? GenerateImageUrl(string? id) - { - if (id == null) - { - return null; - } - - if (!string.IsNullOrWhiteSpace(Options.AssetCDN)) - { - return GenerateUrl(Options.AssetCDN, id); - } - - return GenerateUrl(Options.Url, $"api/assets/{id}"); - } - - /// - public string? GenerateImageUrl(IEnumerable? id) - { - return GenerateImageUrl(id?.FirstOrDefault()); - } - - /// - public string? GenerateUrl(string? relativeUrl) - { - return GenerateUrl(Options.Url, relativeUrl); - } - - /// - public string? GenerateAssetCDNUrl(string relativeUrl) - { - return GenerateUrl(Options.AssetCDN, relativeUrl); - } - - /// - public string? GenerateContentCDNUrl(string relativeUrl) - { - return GenerateUrl(Options.ContentCDN, relativeUrl); - } - - private static string? GenerateUrl(string baseUrl, string? relativeUrl) - { - if (relativeUrl == null) - { - return null; - } - - if (string.IsNullOrWhiteSpace(baseUrl)) - { - throw new InvalidOperationException("URL is not configured."); - } - - return $"{baseUrl}{relativeUrl.TrimStart('/')}"; - } - - /// - public IAppsClient CreateAppsClient() - { - return new AppsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IAssetsClient CreateAssetsClient() - { - return new AssetsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IBackupsClient CreateBackupsClient() - { - return new BackupsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ICommentsClient CreateCommentsClient() - { - return new CommentsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IDiagnosticsClient CreateDiagnosticsClient() - { - return new DiagnosticsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IEventConsumersClient CreateEventConsumersClient() - { - return new EventConsumersClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IHistoryClient CreateHistoryClient() - { - return new HistoryClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ILanguagesClient CreateLanguagesClient() - { - return new LanguagesClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IPingClient CreatePingClient() - { - return new PingClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IPlansClient CreatePlansClient() - { - return new PlansClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IRulesClient CreateRulesClient() - { - return new RulesClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ISchemasClient CreateSchemasClient() - { - return new SchemasClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ISearchClient CreateSearchClient() - { - return new SearchClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IStatisticsClient CreateStatisticsClient() - { - return new StatisticsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ITeamsClient CreateTeamsClient() - { - return new TeamsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ITemplatesClient CreateTemplatesClient() - { - return new TemplatesClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public ITranslationsClient CreateTranslationsClient() - { - return new TranslationsClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IUsersClient CreateUsersClient() - { - return new UsersClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IUserManagementClient CreateUserManagementClient() - { - return new UserManagementClient(Options.ClientProvider) - { - ReadResponseAsString = Options.ReadResponseAsString - }; - } - - /// - public IExtendableRulesClient CreateExtendableRulesClient(string? appName = null) - { - return new ExtendableRulesClient(Options, appName ?? Options.AppName, Options.ClientProvider); - } - - /// - public IContentsClient CreateContentsClient(string schemaName) where TEntity : Content where TData : class, new() - { - return CreateContentsClient(Options.AppName, schemaName); - } - - /// - public IContentsClient CreateContentsClient(string appName, string schemaName) where TEntity : Content where TData : class, new() - { - return new ContentsClient(Options, appName, schemaName, Options.ClientProvider); - } - - /// - public IContentsClient CreateDynamicContentsClient(string schemaName) - { - return CreateDynamicContentsClient(Options.AppName, schemaName); - } - - /// - public IContentsClient CreateDynamicContentsClient(string appName, string schemaName) - { - return new ContentsClient(Options, appName, schemaName, Options.ClientProvider); - } - - /// - public IContentsSharedClient CreateSharedContentsClient(string? appName = null) where TEntity : Content where TData : class, new() - { - return new ContentsSharedClient(Options, appName ?? Options.AppName, Options.ClientProvider); - } - - /// - public IContentsSharedClient CreateSharedDynamicContentsClient(string? appName = null) - { - return new ContentsSharedClient(Options, appName ?? Options.AppName, Options.ClientProvider); - } - - /// - public HttpClient CreateHttpClient() - { - return Options.ClientProvider.Get(); - } - - /// - public void ReturnHttpClient(HttpClient httpClient) - { - Options.ClientProvider.Return(httpClient); - } -} diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexOptions.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexOptions.cs index ac8edb83..db1f84d9 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexOptions.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/SquidexOptions.cs @@ -10,7 +10,7 @@ namespace Squidex.ClientLibrary; /// -/// The options to configure . +/// The options to configure . /// public class SquidexOptions : OptionsBase { @@ -21,13 +21,11 @@ public class SquidexOptions : OptionsBase private string contentCDN; private string assetCDN; private bool readResponseAsString; + private bool ignoreSelfSignedCertificates; private IAuthenticator authenticator; - private IHttpConfigurator configurator; private IHttpClientProvider clientProvider; - private IHttpClientFactory clientFactory; - private TimeSpan httpClientTimeout; + private TimeSpan? timeout; private TimeSpan tokenRetryTime = TimeSpan.FromHours(1); - private IReadOnlyDictionary? appCredentials; /// /// Gets or sets the URL to the Squidex installation. @@ -127,42 +125,28 @@ public bool ReadResponseAsString } /// - /// Gets or sets the authenticator. + /// Gets or sets a value indicating whether self signed certifcates are accepted. /// /// - /// The authenticator. This is a required option. + /// true if signed certifcates are accepted; otherwise, false. /// - /// Option is frozen and cannot be changed anymore. - public IAuthenticator Authenticator + public bool IgnoreSelfSignedCertificates { - get => authenticator; - set => Set(ref authenticator, value); + get => ignoreSelfSignedCertificates; + set => Set(ref ignoreSelfSignedCertificates, value); } /// - /// Gets or sets the configurator that can be used to make changes to the HTTP requests. - /// - /// - /// The configurator. - /// - /// Option is frozen and cannot be changed anymore. - public IHttpConfigurator Configurator - { - get => configurator; - set => Set(ref configurator, value); - } - - /// - /// Gets or sets the client factory. + /// Gets or sets the authenticator. /// /// - /// The client factory. + /// The authenticator. This is a required option. /// /// Option is frozen and cannot be changed anymore. - public IHttpClientFactory ClientFactory + public IAuthenticator Authenticator { - get => clientFactory; - set => Set(ref clientFactory, value); + get => authenticator; + set => Set(ref authenticator, value); } /// @@ -185,10 +169,10 @@ public IHttpClientProvider ClientProvider /// The HTTP client timeout. /// /// Option is frozen and cannot be changed anymore. - public TimeSpan HttpClientTimeout + public TimeSpan? Timeout { - get => httpClientTimeout; - set => Set(ref httpClientTimeout, value); + get => timeout; + set => Set(ref timeout, value); } /// @@ -204,19 +188,6 @@ public TimeSpan TokenRetryTime set => Set(ref tokenRetryTime, value); } - /// - /// Gets or sets credentials for specific apps. - /// - /// - /// The app credentials. - /// - /// Option is frozen and cannot be changed anymore. - public IReadOnlyDictionary? AppCredentials - { - get => appCredentials; - set => Set(ref appCredentials, value); - } - /// /// Validates the options. /// @@ -261,19 +232,9 @@ public void CheckAndFreeze() } #pragma warning disable IDE0074 // Use compound assignment - if (configurator == null) - { - configurator = NoopHttpConfigurator.Instance; - } - - if (clientFactory == null) + if (timeout == TimeSpan.Zero) { - clientFactory = NoopHttpConfigurator.Instance; - } - - if (httpClientTimeout == TimeSpan.Zero) - { - httpClientTimeout = TimeSpan.FromSeconds(100); + timeout = TimeSpan.FromSeconds(100); } if (authenticator == null) @@ -288,23 +249,7 @@ public void CheckAndFreeze() throw new ArgumentException("Client secret is not defined.", nameof(ClientSecret)); } - if (appCredentials != null) - { - var newCredentials = new Dictionary(StringComparer.OrdinalIgnoreCase); - - foreach (var kvp in appCredentials) - { - kvp.Value.CheckAndFreeze(); - - newCredentials[kvp.Key.ToLowerInvariant()] = kvp.Value; - } - - appCredentials = newCredentials; - } - - var squidexAuthenticator = new Authenticator(this); - - authenticator = new CachingAuthenticator(squidexAuthenticator); + authenticator = new CachingAuthenticator(new Authenticator(this)); } if (clientProvider == null) diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/AuthenticatingHttpMessageHandler.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/AuthenticatingHttpMessageHandler.cs index 07c9984b..da3ccf1a 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/AuthenticatingHttpMessageHandler.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/AuthenticatingHttpMessageHandler.cs @@ -15,18 +15,18 @@ namespace Squidex.ClientLibrary.Utils; /// public sealed class AuthenticatingHttpMessageHandler : DelegatingHandler { - private readonly IAuthenticator authenticator; + private readonly SquidexOptions options; /// /// Initializes a new instance of the class with the authenticator. /// - /// The authenticator. Cannot be null. - /// is null. - public AuthenticatingHttpMessageHandler(IAuthenticator authenticator) + /// The options. Cannot be null. + /// is null. + public AuthenticatingHttpMessageHandler(SquidexOptions options) { - Guard.NotNull(authenticator, nameof(authenticator)); + Guard.NotNull(options, nameof(options)); - this.authenticator = authenticator; + this.options = options; } /// @@ -38,20 +38,18 @@ protected override Task SendAsync(HttpRequestMessage reques return base.SendAsync(request, cancellationToken); } - if (!authenticator.ShouldIntercept(request)) + if (!options.Authenticator.ShouldIntercept(request)) { return base.SendAsync(request, cancellationToken); } - var appName = GetAppName(request); - - return InterceptAsync(request, appName, true, cancellationToken); + return InterceptAsync(request, true, cancellationToken); } - private async Task InterceptAsync(HttpRequestMessage request, string appName, bool retry, + private async Task InterceptAsync(HttpRequestMessage request, bool retry, CancellationToken cancellationToken) { - var token = await authenticator.GetBearerTokenAsync(appName, cancellationToken); + var token = await options.Authenticator.GetBearerTokenAsync(options.AppName, cancellationToken); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); @@ -59,28 +57,14 @@ private async Task InterceptAsync(HttpRequestMessage reques if (response.StatusCode == HttpStatusCode.Unauthorized) { - await authenticator.RemoveTokenAsync(appName, token, cancellationToken); + await options.Authenticator.RemoveTokenAsync(options.AppName, token, cancellationToken); if (retry) { - return await InterceptAsync(request, appName, false, cancellationToken); + return await InterceptAsync(request, false, cancellationToken); } } return response; } - - private static string GetAppName(HttpRequestMessage request) - { - var appName = string.Empty; - - if (request.Headers.TryGetValues(SpecialHeaders.AppName, out var appValues)) - { - request.Headers.Remove(SpecialHeaders.AppName); - - appName = appValues.FirstOrDefault() ?? string.Empty; - } - - return appName; - } } diff --git a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/SquidexClientBase.cs b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/SquidexClientBase.cs index 4d0bb14f..3eedbb00 100644 --- a/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/SquidexClientBase.cs +++ b/csharp/Squidex.ClientLibrary/Squidex.ClientLibrary/Utils/SquidexClientBase.cs @@ -17,106 +17,68 @@ namespace Squidex.ClientLibrary.Utils; public abstract class SquidexClientBase { /// - /// Gets the name of the App. + /// Gets the options of the . /// /// - /// The name of the App. - /// - public string AppName { get; } - - /// - /// Gets the options of the . - /// - /// - /// The options of the . + /// The options of the . /// public SquidexOptions Options { get; } - /// - /// The http client provider. - /// - protected IHttpClientProvider HttpClientProvider { get; } - #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - protected internal SquidexClientBase(SquidexOptions options, string appName, IHttpClientProvider httpClientProvider) + protected internal SquidexClientBase(SquidexOptions options) { Guard.NotNull(options, nameof(options)); - Guard.NotNullOrEmpty(appName, nameof(appName)); - Guard.NotNull(httpClientProvider, nameof(httpClientProvider)); - - // The app name can be different from the options app name. - AppName = appName; // Just pass in the options to have direct access to them. Options = options; - - HttpClientProvider = httpClientProvider; } protected internal async Task RequestAsync(HttpMethod method, string path, HttpContent? content, QueryContext? context, CancellationToken ct) { - var httpClient = HttpClientProvider.Get(); - try + var httpClient = Options.ClientProvider.Get(); + + using (var request = BuildRequest(method, path, content, context)) { - using (var request = BuildRequest(method, path, content, context)) + using (var response = await httpClient.SendAsync(request, ct)) { - using (var response = await httpClient.SendAsync(request, ct)) - { - await EnsureResponseIsValidAsync(response); - } + await EnsureResponseIsValidAsync(response); } } - finally - { - HttpClientProvider.Return(httpClient); - } } protected internal async Task RequestStreamAsync(HttpMethod method, string path, HttpContent? content, QueryContext? context, CancellationToken ct) { - var httpClient = HttpClientProvider.Get(); - try + var httpClient = Options.ClientProvider.Get(); + + using (var request = BuildRequest(method, path, content, context)) { - using (var request = BuildRequest(method, path, content, context)) - { - var response = await httpClient.SendAsync(request, ct); + var response = await httpClient.SendAsync(request, ct); - await EnsureResponseIsValidAsync(response); + await EnsureResponseIsValidAsync(response); #if NET5_0_OR_GREATER - return await response.Content.ReadAsStreamAsync(ct); + return await response.Content.ReadAsStreamAsync(ct); #else - return await response.Content.ReadAsStreamAsync(); + return await response.Content.ReadAsStreamAsync(); #endif - } - } - finally - { - HttpClientProvider.Return(httpClient); } } protected internal async Task RequestJsonAsync(HttpMethod method, string path, HttpContent? content, QueryContext? context, CancellationToken ct) { - var httpClient = HttpClientProvider.Get(); - try + var httpClient = Options.ClientProvider.Get(); + + using (var request = BuildRequest(method, path, content, context)) { - using (var request = BuildRequest(method, path, content, context)) + using (var response = await httpClient.SendAsync(request, ct)) { - using (var response = await httpClient.SendAsync(request, ct)) - { - await EnsureResponseIsValidAsync(response); + await EnsureResponseIsValidAsync(response); - return (await response.Content.ReadAsJsonAsync())!; - } + return (await response.Content.ReadAsJsonAsync())!; } } - finally - { - HttpClientProvider.Return(httpClient); - } } protected internal HttpRequestMessage BuildRequest(HttpMethod method, string path, HttpContent? content, QueryContext? context) @@ -128,7 +90,6 @@ protected internal HttpRequestMessage BuildRequest(HttpMethod method, string pat request.Content = content; } - request.Headers.TryAddWithoutValidation(SpecialHeaders.AppName, AppName); context?.AddToHeaders(request.Headers); return request;