From 9021d838366b20b906dbbd64b3096a44afc8e3f2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Apr 2018 11:09:19 +1000 Subject: [PATCH 1/5] redundant file --- Seq.Api.sln.DotSettings | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Seq.Api.sln.DotSettings diff --git a/Seq.Api.sln.DotSettings b/Seq.Api.sln.DotSettings deleted file mode 100644 index d50635d..0000000 --- a/Seq.Api.sln.DotSettings +++ /dev/null @@ -1,2 +0,0 @@ - - AD \ No newline at end of file From afd494cab0b8036c5105ef0caa6a1338604c9839 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Apr 2018 11:10:56 +1000 Subject: [PATCH 2/5] redundant usings --- example/SeqTail/Program.cs | 1 - src/Seq.Api/Model/Backups/BackupEntity.cs | 4 +--- src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs | 1 - src/Seq.Api/SeqConnection.cs | 2 +- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/example/SeqTail/Program.cs b/example/SeqTail/Program.cs index 1504705..162fdd1 100644 --- a/example/SeqTail/Program.cs +++ b/example/SeqTail/Program.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Threading.Tasks; using DocoptNet; using Seq.Api; diff --git a/src/Seq.Api/Model/Backups/BackupEntity.cs b/src/Seq.Api/Model/Backups/BackupEntity.cs index a59bd0b..4631a56 100644 --- a/src/Seq.Api/Model/Backups/BackupEntity.cs +++ b/src/Seq.Api/Model/Backups/BackupEntity.cs @@ -1,6 +1,4 @@ -using System; - -namespace Seq.Api.Model.Backups +namespace Seq.Api.Model.Backups { public class BackupEntity : Entity { diff --git a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs index 3064d4f..dee8d84 100644 --- a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Seq.Api.Model.Inputs; using Seq.Api.Model.License; namespace Seq.Api.ResourceGroups diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index 9789aa5..a70c58b 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -18,7 +18,7 @@ public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCred { if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl)); _client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); - + _root = new Lazy>(() => _client.GetRootAsync()); } From f57c675efa96739448a9bf41f58dece6f1faea56 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Apr 2018 11:11:37 +1000 Subject: [PATCH 3/5] redundant file --- test/Seq.Api.Tests/Properties/AssemblyInfo.cs | 15 --------------- test/Seq.Api.Tests/Seq.Api.Tests.csproj | 2 +- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 test/Seq.Api.Tests/Properties/AssemblyInfo.cs diff --git a/test/Seq.Api.Tests/Properties/AssemblyInfo.cs b/test/Seq.Api.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index 083fd7a..0000000 --- a/test/Seq.Api.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Seq.Api.Tests")] -[assembly: AssemblyTrademark("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 397fd34..f522c93 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -27,4 +27,4 @@ - + \ No newline at end of file From 66ad4e12b9232b7a977cdfc4604a71c7664c237c Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Apr 2018 14:47:20 +1000 Subject: [PATCH 4/5] CancellationToken --- Directory.Build.props | 6 ++ src/Seq.Api/Client/SeqApiClient.cs | 70 +++++++++--------- .../ResourceGroups/ApiKeysResourceGroup.cs | 25 +++---- .../ResourceGroups/ApiResourceGroup.cs | 72 ++++++++++--------- .../AppInstancesResourceGroup.cs | 30 ++++---- .../ResourceGroups/AppsResourceGroup.cs | 29 ++++---- .../ResourceGroups/BackupsResourceGroup.cs | 13 ++-- .../ResourceGroups/DashboardsResourceGroup.cs | 25 +++---- .../ResourceGroups/DataResourceGroup.cs | 13 ++-- .../DiagnosticsResourceGroup.cs | 15 ++-- .../ResourceGroups/EventsResourceGroup.cs | 52 ++++++++------ .../ExpressionsResourceGroup.cs | 9 +-- .../ResourceGroups/FeedsResourceGroup.cs | 25 +++---- src/Seq.Api/ResourceGroups/ISeqConnection.cs | 3 +- .../ResourceGroups/LicensesResourceGroup.cs | 21 +++--- .../ResourceGroups/PermalinksResourceGroup.cs | 31 ++++---- .../RetentionPoliciesResourceGroup.cs | 25 +++---- .../ResourceGroups/SettingsResourceGroup.cs | 29 ++++---- .../ResourceGroups/SignalsResourceGroup.cs | 25 +++---- .../ResourceGroups/SqlQueriesResourceGroup.cs | 25 +++---- .../ResourceGroups/UpdatesResourceGroup.cs | 5 +- .../ResourceGroups/UsersResourceGroup.cs | 49 ++++++------- src/Seq.Api/Seq.Api.csproj | 2 +- src/Seq.Api/SeqConnection.cs | 13 ++-- 24 files changed, 326 insertions(+), 286 deletions(-) create mode 100644 Directory.Build.props diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..2deb00d --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,6 @@ + + + + latest + + \ No newline at end of file diff --git a/src/Seq.Api/Client/SeqApiClient.cs b/src/Seq.Api/Client/SeqApiClient.cs index bb5abfc..fb097a6 100644 --- a/src/Seq.Api/Client/SeqApiClient.cs +++ b/src/Seq.Api/Client/SeqApiClient.cs @@ -60,95 +60,95 @@ public SeqApiClient(string serverUrl, string apiKey = null, bool useDefaultCrede public HttpClient HttpClient => _httpClient; - public Task GetRootAsync() + public Task GetRootAsync(CancellationToken token = default) { - return HttpGetAsync("api"); + return HttpGetAsync("api", token); } - public Task GetAsync(ILinked entity, string link, IDictionary parameters = null) + public Task GetAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetAsync(linkUri); + return HttpGetAsync(linkUri, token); } - public Task GetStringAsync(ILinked entity, string link, IDictionary parameters = null) + public Task GetStringAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetStringAsync(linkUri); + return HttpGetStringAsync(linkUri, token); } - public Task> ListAsync(ILinked entity, string link, IDictionary parameters = null) + public Task> ListAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetAsync>(linkUri); + return HttpGetAsync>(linkUri, token); } - public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - public async Task PostReadStringAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task PostReadStringAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); return await new StreamReader(stream).ReadToEndAsync(); } - public async Task PostReadStreamAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task PostReadStreamAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - return await HttpSendAsync(request).ConfigureAwait(false); + return await HttpSendAsync(request, token).ConfigureAwait(false); } - public async Task PutAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task PutAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Put, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Delete, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Delete, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - public async Task> StreamAsync(ILinked entity, string link, IDictionary parameters = null) + public async Task> StreamAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) { - return await WebSocketStreamAsync(entity, link, parameters, reader => _serializer.Deserialize(new JsonTextReader(reader))); + return await WebSocketStreamAsync(entity, link, parameters, reader => _serializer.Deserialize(new JsonTextReader(reader)), token); } - public async Task> StreamTextAsync(ILinked entity, string link, IDictionary parameters = null) + public async Task> StreamTextAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) { - return await WebSocketStreamAsync(entity, link, parameters, reader => reader.ReadToEnd()); + return await WebSocketStreamAsync(entity, link, parameters, reader => reader.ReadToEnd(), token); } - async Task> WebSocketStreamAsync(ILinked entity, string link, IDictionary parameters, Func deserialize) + async Task> WebSocketStreamAsync(ILinked entity, string link, IDictionary parameters, Func deserialize, CancellationToken token = default) { var linkUri = ResolveLink(entity, link, parameters); @@ -157,35 +157,35 @@ async Task> WebSocketStreamAsync(ILinked entity, string l if (_apiKey != null) socket.Options.SetRequestHeader("X-Seq-ApiKey", _apiKey); - await socket.ConnectAsync(new Uri(linkUri), CancellationToken.None); + await socket.ConnectAsync(new Uri(linkUri), token); return new ObservableStream(socket, deserialize); } - async Task HttpGetAsync(string url) + async Task HttpGetAsync(string url, CancellationToken token = default) { var request = new HttpRequestMessage(HttpMethod.Get, url); - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - async Task HttpGetStringAsync(string url) + async Task HttpGetStringAsync(string url, CancellationToken token = default) { var request = new HttpRequestMessage(HttpMethod.Get, url); - var stream = await HttpSendAsync(request).ConfigureAwait(false); + var stream = await HttpSendAsync(request, token).ConfigureAwait(false); return await new StreamReader(stream).ReadToEndAsync(); } - async Task HttpSendAsync(HttpRequestMessage request) + async Task HttpSendAsync(HttpRequestMessage request, CancellationToken token = default) { if (_apiKey != null) request.Headers.Add("X-Seq-ApiKey", _apiKey); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(SeqApiV6MediaType)); - var response = await _httpClient.SendAsync(request).ConfigureAwait(false); + var response = await _httpClient.SendAsync(request, token).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); - + if (response.IsSuccessStatusCode) return stream; diff --git a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs index 6047ff2..f46b805 100644 --- a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Inputs; @@ -12,36 +13,36 @@ internal ApiKeysResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null) + public async Task> ListAsync(string ownerId = null, CancellationToken token = default) { var parameters = new Dictionary { { "ownerId", ownerId } }; - return await GroupListAsync("Items", parameters).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(ApiKeyEntity entity) + public async Task AddAsync(ApiKeyEntity entity, CancellationToken token = default) { - return await GroupCreateAsync(entity).ConfigureAwait(false); + return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(ApiKeyEntity entity) + public async Task RemoveAsync(ApiKeyEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(ApiKeyEntity entity) + public async Task UpdateAsync(ApiKeyEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs index 23cf62b..97bd4e3 100644 --- a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Client; using Seq.Api.Model; @@ -21,69 +22,69 @@ internal ApiResourceGroup(string name, ISeqConnection connection) protected SeqApiClient Client { get { return _connection.Client; } } - protected Task LoadGroupAsync() + protected Task LoadGroupAsync(CancellationToken token = default) { - return _connection.LoadResourceGroupAsync(_name); + return _connection.LoadResourceGroupAsync(_name, token); } - protected async Task GroupGetAsync(string link, IDictionary parameters = null) + protected async Task GroupGetAsync(string link, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.GetAsync(group, link, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.GetAsync(group, link, parameters, token).ConfigureAwait(false); } - protected async Task GroupGetStringAsync(string link, IDictionary parameters = null) + protected async Task GroupGetStringAsync(string link, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.GetStringAsync(group, link, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.GetStringAsync(group, link, parameters, token).ConfigureAwait(false); } - protected async Task> GroupListAsync(string link, IDictionary parameters = null) + protected async Task> GroupListAsync(string link, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.ListAsync(group, link, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.ListAsync(group, link, parameters, token).ConfigureAwait(false); } - protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - await Client.PostAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + await Client.PostAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupPostReadStringAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupPostReadStringAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.PostReadStringAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.PostReadStringAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupPostReadBytesAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupPostReadBytesAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.PostReadStreamAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.PostReadStreamAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.PostAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.PostAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupPutAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupPutAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - await Client.PutAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + await Client.PutAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - await Client.DeleteAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + await Client.DeleteAsync(group, link, content, parameters, token).ConfigureAwait(false); } - protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null) + protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) { - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.DeleteAsync(group, link, content, parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.DeleteAsync(group, link, content, parameters, token).ConfigureAwait(false); } protected string GetLink(TEntity entity, string link, string orElse) where TEntity : ILinked @@ -92,7 +93,8 @@ protected string GetLink(TEntity entity, string link, string orElse) wh } protected async Task GroupCreateAsync(TEntity entity, - IDictionary parameters = null) where TEntity : ILinked + IDictionary parameters = null, CancellationToken token = default) + where TEntity : ILinked { ILinked resource; string link; @@ -104,11 +106,11 @@ protected async Task GroupCreateAsync(TEntity ent } else { - resource = await LoadGroupAsync().ConfigureAwait(false); + resource = await LoadGroupAsync(token).ConfigureAwait(false); link = "Items"; } - return await Client.PostAsync(resource, link, entity, parameters).ConfigureAwait(false); + return await Client.PostAsync(resource, link, entity, parameters, token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs index fe64248..7672744 100644 --- a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.AppInstances; @@ -12,48 +13,49 @@ internal AppInstancesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync(string appId) + public async Task TemplateAsync(string appId, CancellationToken token = default) { if (appId == null) throw new ArgumentNullException(nameof(appId)); - return await GroupGetAsync("Template", new Dictionary { { "appId", appId } }).ConfigureAwait(false); + return await GroupGetAsync("Template", new Dictionary { { "appId", appId } }, token).ConfigureAwait(false); } - public async Task AddAsync(AppInstanceEntity entity, bool runOnExisting = false) + public async Task AddAsync(AppInstanceEntity entity, bool runOnExisting = false, CancellationToken token = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - return await Client.PostAsync(entity, "Create", entity, new Dictionary { { "runOnExisting", runOnExisting } }).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, new Dictionary { { "runOnExisting", runOnExisting } }, token) + .ConfigureAwait(false); } - public async Task RemoveAsync(AppInstanceEntity entity) + public async Task RemoveAsync(AppInstanceEntity entity, CancellationToken token = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(AppInstanceEntity entity) + public async Task UpdateAsync(AppInstanceEntity entity, CancellationToken token = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task InvokeAsync(AppInstanceEntity entity, string eventId, IReadOnlyDictionary settingOverrides) + public async Task InvokeAsync(AppInstanceEntity entity, string eventId, IReadOnlyDictionary settingOverrides, CancellationToken token = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); if (eventId == null) throw new ArgumentNullException(nameof(eventId)); var postedSettings = settingOverrides ?? new Dictionary(); - await Client.PostAsync(entity, "Invoke", postedSettings, new Dictionary{{"eventId", eventId}}); + await Client.PostAsync(entity, "Invoke", postedSettings, new Dictionary{{"eventId", eventId}}, token); } } } diff --git a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs index 6488b3b..a26cd7e 100644 --- a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Apps; @@ -12,44 +13,44 @@ internal AppsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(AppEntity entity) + public async Task AddAsync(AppEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(AppEntity entity) + public async Task RemoveAsync(AppEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(AppEntity entity) + public async Task UpdateAsync(AppEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task InstallPackageAsync(string feedId, string packageId, string version = null) + public async Task InstallPackageAsync(string feedId, string packageId, string version = null, CancellationToken token = default) { if (feedId == null) throw new ArgumentNullException(nameof(feedId)); if (packageId == null) throw new ArgumentNullException(nameof(packageId)); var parameters = new Dictionary{{ "feedId", feedId}, {"packageId", packageId}}; if (version != null) parameters.Add("version", version); - return await GroupPostAsync("InstallPackage", new object(), parameters).ConfigureAwait(false); + return await GroupPostAsync("InstallPackage", new object(), parameters, token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs index 734d983..2b54591 100644 --- a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Backups; @@ -13,20 +14,20 @@ internal BackupsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task DownloadImmediateAsync() + public async Task DownloadImmediateAsync(CancellationToken token = default) { - return await GroupPostReadBytesAsync("Immediate", new object()).ConfigureAwait(false); + return await GroupPostReadBytesAsync("Immediate", new object(), token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs index 39eee61..c0b96d5 100644 --- a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Monitoring; @@ -12,36 +13,36 @@ internal DashboardsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null, bool shared = false) + public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken token = default) { var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; - return await GroupListAsync("Items", parameters).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(DashboardEntity entity) + public async Task AddAsync(DashboardEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(DashboardEntity entity) + public async Task RemoveAsync(DashboardEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(DashboardEntity entity) + public async Task UpdateAsync(DashboardEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs index 6a464f9..398e130 100644 --- a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Data; using Seq.Api.Model.Signals; @@ -30,10 +31,11 @@ public async Task QueryAsync( DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, - TimeSpan? timeout = null) + TimeSpan? timeout = null, + CancellationToken token = default) { MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters); - return await GroupPostAsync("Query", body, parameters).ConfigureAwait(false); + return await GroupPostAsync("Query", body, parameters, token).ConfigureAwait(false); } /// @@ -53,11 +55,12 @@ public async Task QueryCsvAsync( DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, - TimeSpan? timeout = null) + TimeSpan? timeout = null, + CancellationToken token = default) { MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters); parameters.Add("format", "text/csv"); - return await GroupPostReadStringAsync("Query", body, parameters).ConfigureAwait(false); + return await GroupPostReadStringAsync("Query", body, parameters, token).ConfigureAwait(false); } static void MakeParameters( @@ -77,7 +80,7 @@ static void MakeParameters( if (rangeStartUtc != null) parameters.Add(nameof(rangeStartUtc), rangeStartUtc); - + if (rangeEndUtc != null) parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value); diff --git a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs index a983bd3..9844dfd 100644 --- a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using Seq.Api.Model.Diagnostics; namespace Seq.Api.ResourceGroups @@ -10,19 +11,19 @@ internal DiagnosticsResourceGroup(ISeqConnection connection) { } - public async Task GetServerMetricsAsync() + public async Task GetServerMetricsAsync(CancellationToken token = default) { - return await GroupGetAsync("ServerMetrics").ConfigureAwait(false); + return await GroupGetAsync("ServerMetrics", token: token).ConfigureAwait(false); } - public async Task GetServerStatusAsync() + public async Task GetServerStatusAsync(CancellationToken token = default) { - return await GroupGetAsync("ServerStatus").ConfigureAwait(false); + return await GroupGetAsync("ServerStatus", token: token).ConfigureAwait(false); } - public async Task GetIngestionLogAsync() + public async Task GetIngestionLogAsync(CancellationToken token = default) { - return await GroupGetStringAsync("IngestionLog").ConfigureAwait(false); + return await GroupGetStringAsync("IngestionLog", token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs index 42d6862..db4d529 100644 --- a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Events; using Seq.Api.Model.Shared; @@ -26,13 +27,14 @@ internal EventsResourceGroup(ISeqConnection connection) public async Task FindAsync( string id, bool render = false, - string permalinkId = null) + string permalinkId = null, + CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); var parameters = new Dictionary {{"id", id}}; - return await GroupGetAsync("Item", parameters).ConfigureAwait(false); + return await GroupGetAsync("Item", parameters, token).ConfigureAwait(false); } /// @@ -57,7 +59,7 @@ public async Task FindAsync( /// The complete list of events, ordered from least to most recent. public async Task> ListAsync( SignalExpressionPart signal = null, - string filter = null, + string filter = null, int count = 30, string startAtId = null, string afterId = null, @@ -65,7 +67,8 @@ public async Task> ListAsync( DateTime? fromDateUtc = null, DateTime? toDateUtc = null, int? shortCircuitAfter = null, - string permalinkId = null) + string permalinkId = null, + CancellationToken token = default) { var parameters = new Dictionary { { "count", count } }; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -83,7 +86,7 @@ public async Task> ListAsync( while (true) { - var resultSet = await GroupGetAsync("InSignal", parameters).ConfigureAwait(false); + var resultSet = await GroupGetAsync("InSignal", parameters, token).ConfigureAwait(false); chunks.Add(resultSet.Events); remaining -= resultSet.Events.Count; @@ -129,15 +132,16 @@ public async Task> ListAsync( public async Task InSignalAsync( SignalEntity unsavedSignal = null, SignalExpressionPart signal = null, - string filter = null, + string filter = null, int count = 30, string startAtId = null, - string afterId = null, + string afterId = null, bool render = false, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, int? shortCircuitAfter = null, - string permalinkId = null) + string permalinkId = null, + CancellationToken token = default) { var parameters = new Dictionary{{ "count", count }}; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -151,7 +155,7 @@ public async Task InSignalAsync( if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } var body = unsavedSignal ?? new SignalEntity(); - return await GroupPostAsync("InSignal", body, parameters).ConfigureAwait(false); + return await GroupPostAsync("InSignal", body, parameters, token).ConfigureAwait(false); } /// @@ -176,15 +180,16 @@ public async Task InSignalAsync( /// The complete list of events, ordered from least to most recent. public async Task InSignalAsync( SignalExpressionPart signal, - string filter = null, + string filter = null, int count = 30, string startAtId = null, - string afterId = null, + string afterId = null, bool render = false, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, int? shortCircuitAfter = null, - string permalinkId = null) + string permalinkId = null, + CancellationToken token = default) { if (signal == null) throw new ArgumentNullException(nameof(signal)); @@ -202,7 +207,7 @@ public async Task InSignalAsync( if (shortCircuitAfter != null) { parameters.Add("shortCircuitAfter", shortCircuitAfter.Value); } if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } - return await GroupGetAsync("InSignal", parameters).ConfigureAwait(false); + return await GroupGetAsync("InSignal", parameters, token).ConfigureAwait(false); } /// @@ -219,9 +224,10 @@ public async Task InSignalAsync( public async Task DeleteInSignalAsync( SignalEntity unsavedSignal = null, SignalExpressionPart signal = null, - string filter = null, + string filter = null, DateTime? fromDateUtc = null, - DateTime? toDateUtc = null) + DateTime? toDateUtc = null, + CancellationToken token = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -230,7 +236,7 @@ public async Task DeleteInSignalAsync( if (toDateUtc != null) { parameters.Add("toDateUtc", toDateUtc.Value); } var body = unsavedSignal ?? new SignalEntity(); - return await GroupDeleteAsync("DeleteInSignal", body, parameters).ConfigureAwait(false); + return await GroupDeleteAsync("DeleteInSignal", body, parameters, token).ConfigureAwait(false); } /// @@ -244,14 +250,15 @@ public async Task DeleteInSignalAsync( /// subscriber connects, ensure at least one subscription is made in order to avoid event loss. public async Task> StreamAsync( SignalExpressionPart signal = null, - string filter = null) + string filter = null, + CancellationToken token = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } if (filter != null) { parameters.Add("filter", filter); } - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.StreamAsync(group, "Stream", parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.StreamAsync(group, "Stream", parameters, token).ConfigureAwait(false); } /// @@ -265,14 +272,15 @@ public async Task> StreamAsync( /// subscriber connects, ensure at least one subscription is made in order to avoid event loss. public async Task> StreamDocumentsAsync( SignalExpressionPart signal = null, - string filter = null) + string filter = null, + CancellationToken token = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } if (filter != null) { parameters.Add("filter", filter); } - var group = await LoadGroupAsync().ConfigureAwait(false); - return await Client.StreamTextAsync(group, "Stream", parameters).ConfigureAwait(false); + var group = await LoadGroupAsync(token).ConfigureAwait(false); + return await Client.StreamTextAsync(group, "Stream", parameters, token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs b/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs index c43d1c2..b39c23e 100644 --- a/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Expressions; @@ -11,20 +12,20 @@ internal ExpressionsResourceGroup(ISeqConnection connection) { } - public Task ToStrictAsync(string fuzzy) + public Task ToStrictAsync(string fuzzy, CancellationToken token = default) { return GroupGetAsync("ToStrict", new Dictionary { {"fuzzy", fuzzy} - }); + }, token); } - public Task ToSqlAsync(string fuzzy) + public Task ToSqlAsync(string fuzzy, CancellationToken token = default) { return GroupGetAsync("ToSql", new Dictionary { {"fuzzy", fuzzy} - }); + }, token); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs b/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs index 2e0bdec..5aafeb5 100644 --- a/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Feeds; @@ -12,35 +13,35 @@ internal FeedsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(NuGetFeedEntity entity) + public async Task AddAsync(NuGetFeedEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(NuGetFeedEntity entity) + public async Task RemoveAsync(NuGetFeedEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(NuGetFeedEntity entity) + public async Task UpdateAsync(NuGetFeedEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/ISeqConnection.cs b/src/Seq.Api/ResourceGroups/ISeqConnection.cs index cbdcb0c..ca9d9e8 100644 --- a/src/Seq.Api/ResourceGroups/ISeqConnection.cs +++ b/src/Seq.Api/ResourceGroups/ISeqConnection.cs @@ -1,3 +1,4 @@ +using System.Threading; using System.Threading.Tasks; using Seq.Api.Client; using Seq.Api.Model; @@ -6,7 +7,7 @@ namespace Seq.Api.ResourceGroups { interface ISeqConnection { - Task LoadResourceGroupAsync(string name); + Task LoadResourceGroupAsync(string name, CancellationToken cancellationToken = default); SeqApiClient Client { get; } } } diff --git a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs index dee8d84..302ac93 100644 --- a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.License; @@ -12,30 +13,30 @@ internal LicensesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task FindCurrentAsync() + public async Task FindCurrentAsync(CancellationToken token = default) { - return await GroupGetAsync("Current").ConfigureAwait(false); + return await GroupGetAsync("Current", token: token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task UpdateAsync(LicenseEntity entity) + public async Task UpdateAsync(LicenseEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task DowngradeAsync() + public async Task DowngradeAsync(CancellationToken token = default) { - await GroupPostAsync("Downgrade", new object()).ConfigureAwait(false); + await GroupPostAsync("Downgrade", new object(), token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs b/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs index a280d71..3fc3fd5 100644 --- a/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Permalinks; @@ -14,8 +15,9 @@ internal PermalinksResourceGroup(ISeqConnection connection) public async Task FindAsync( string id, - bool includeEvent = false, - bool renderEvent = false) + bool includeEvent = false, + bool renderEvent = false, + CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); var parameters = new Dictionary @@ -24,12 +26,13 @@ public async Task FindAsync( {"includeEvent", includeEvent}, {"renderEvent", renderEvent} }; - return await GroupGetAsync("Item", parameters).ConfigureAwait(false); + return await GroupGetAsync("Item", parameters, token).ConfigureAwait(false); } public async Task> ListAsync( - bool includeEvent = false, - bool renderEvent = false) + bool includeEvent = false, + bool renderEvent = false, + CancellationToken token = default) { var parameters = new Dictionary { @@ -37,27 +40,27 @@ public async Task> ListAsync( {"renderEvent", renderEvent} }; - return await GroupListAsync("Items", parameters).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(PermalinkEntity entity) + public async Task AddAsync(PermalinkEntity entity, CancellationToken token = default) { - return await GroupCreateAsync(entity).ConfigureAwait(false); + return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(PermalinkEntity entity) + public async Task RemoveAsync(PermalinkEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(PermalinkEntity entity) + public async Task UpdateAsync(PermalinkEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs b/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs index e750e41..430fad8 100644 --- a/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Retention; @@ -12,35 +13,35 @@ internal RetentionPoliciesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(RetentionPolicyEntity entity) + public async Task AddAsync(RetentionPolicyEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(RetentionPolicyEntity entity) + public async Task RemoveAsync(RetentionPolicyEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(RetentionPolicyEntity entity) + public async Task UpdateAsync(RetentionPolicyEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs index 1ec5292..15537e0 100644 --- a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Settings; @@ -12,40 +13,40 @@ internal SettingsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task FindNamedAsync(SettingName name) + public async Task FindNamedAsync(SettingName name, CancellationToken token = default) { - return await GroupGetAsync(name.ToString()).ConfigureAwait(false); + return await GroupGetAsync(name.ToString(), token: token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(SettingEntity entity) + public async Task AddAsync(SettingEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(SettingEntity entity) + public async Task RemoveAsync(SettingEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(SettingEntity entity) + public async Task UpdateAsync(SettingEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs index cf68e2b..c6b340f 100644 --- a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Signals; @@ -12,35 +13,35 @@ internal SignalsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(SignalEntity entity) + public async Task AddAsync(SignalEntity entity, CancellationToken token = default) { - return await GroupCreateAsync(entity).ConfigureAwait(false); + return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(SignalEntity entity) + public async Task RemoveAsync(SignalEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(SignalEntity entity) + public async Task UpdateAsync(SignalEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs b/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs index 3b84725..3d3c074 100644 --- a/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.SqlQueries; @@ -12,35 +13,35 @@ internal SqlQueriesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(SqlQueryEntity entity) + public async Task AddAsync(SqlQueryEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(SqlQueryEntity entity) + public async Task RemoveAsync(SqlQueryEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(SqlQueryEntity entity) + public async Task UpdateAsync(SqlQueryEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs b/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs index 157adb5..61149aa 100644 --- a/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Model.Updates; @@ -11,9 +12,9 @@ internal UpdatesResourceGroup(ISeqConnection connection) { } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs index aa87ec1..e885083 100644 --- a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Seq.Api.Model.Users; using System.Linq; +using System.Threading; using Seq.Api.Client; namespace Seq.Api.ResourceGroups @@ -14,69 +15,69 @@ internal UsersResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + public async Task FindAsync(string id, CancellationToken token = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); } - public async Task FindCurrentAsync() + public async Task FindCurrentAsync(CancellationToken token = default) { - return await GroupGetAsync("Current").ConfigureAwait(false); + return await GroupGetAsync("Current", token: token).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken token = default) { - return await GroupListAsync("Items").ConfigureAwait(false); + return await GroupListAsync("Items", token: token).ConfigureAwait(false); } - public async Task TemplateAsync() + public async Task TemplateAsync(CancellationToken token = default) { - return await GroupGetAsync("Template").ConfigureAwait(false); + return await GroupGetAsync("Template", token: token).ConfigureAwait(false); } - public async Task AddAsync(UserEntity entity) + public async Task AddAsync(UserEntity entity, CancellationToken token = default) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); } - public async Task RemoveAsync(UserEntity entity) + public async Task RemoveAsync(UserEntity entity, CancellationToken token = default) { - await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task UpdateAsync(UserEntity entity) + public async Task UpdateAsync(UserEntity entity, CancellationToken token = default) { - await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); } - public async Task LoginAsync(string username, string password) + public async Task LoginAsync(string username, string password, CancellationToken token = default) { if (username == null) throw new ArgumentNullException(nameof(username)); if (password == null) throw new ArgumentNullException(nameof(password)); var credentials = new CredentialsPart {Username = username, Password = password}; - return await GroupPostAsync("Login", credentials).ConfigureAwait(false); + return await GroupPostAsync("Login", credentials, token: token).ConfigureAwait(false); } - public async Task LogoutAsync() + public async Task LogoutAsync(CancellationToken token = default) { - await GroupPostAsync("Logout", new object()).ConfigureAwait(false); + await GroupPostAsync("Logout", new object(), token: token).ConfigureAwait(false); } - public async Task GetSearchHistoryAsync(UserEntity entity) + public async Task GetSearchHistoryAsync(UserEntity entity, CancellationToken token = default) { - return await Client.GetAsync(entity, "SearchHistory").ConfigureAwait(false); + return await Client.GetAsync(entity, "SearchHistory", token: token).ConfigureAwait(false); } - public async Task LoginWindowsIntegratedAsync() + public async Task LoginWindowsIntegratedAsync(CancellationToken token = default) { - var providers = await GroupGetAsync("AuthenticationProviders").ConfigureAwait(false); + var providers = await GroupGetAsync("AuthenticationProviders", token: token).ConfigureAwait(false); var provider = providers.Providers.SingleOrDefault(p => p.Name == "Integrated Windows Authentication"); if (provider == null) throw new SeqApiException("The Integrated Windows Authentication provider is not available.", null); - var response = await Client.HttpClient.GetAsync(provider.Url).ConfigureAwait(false); + var response = await Client.HttpClient.GetAsync(provider.Url, token).ConfigureAwait(false); response.EnsureSuccessStatusCode(); - return await FindCurrentAsync().ConfigureAwait(false); + return await FindCurrentAsync(token).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index a1dddf3..3c1bd5b 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -4,7 +4,7 @@ 5.0.0 Datalust;Contributors netstandard1.3 - $(NoWarn);CS1591 + $(NoWarn);CS1591;CS1573 true true Seq.Api diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index a70c58b..cf90bde 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Threading; using System.Threading.Tasks; using Seq.Api.Client; using Seq.Api.Model; @@ -14,12 +15,12 @@ public class SeqConnection : ISeqConnection readonly ConcurrentDictionary> _resourceGroups = new ConcurrentDictionary>(); readonly Lazy> _root; - public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true) + public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true, CancellationToken token = default) { if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl)); _client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); - _root = new Lazy>(() => _client.GetRootAsync()); + _root = new Lazy>(() => _client.GetRootAsync(token)); } public ApiKeysResourceGroup ApiKeys => new ApiKeysResourceGroup(this); @@ -56,14 +57,14 @@ public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCred public UsersResourceGroup Users => new UsersResourceGroup(this); - public async Task LoadResourceGroupAsync(string name) + public async Task LoadResourceGroupAsync(string name, CancellationToken token = default) { - return await _resourceGroups.GetOrAdd(name, ResourceGroupFactory).ConfigureAwait(false); + return await _resourceGroups.GetOrAdd(name, s => ResourceGroupFactory(s, token)).ConfigureAwait(false); } - async Task ResourceGroupFactory(string name) + async Task ResourceGroupFactory(string name, CancellationToken token = default) { - return await _client.GetAsync(await _root.Value, name + "Resources").ConfigureAwait(false); + return await _client.GetAsync(await _root.Value, name + "Resources", token: token).ConfigureAwait(false); } public SeqApiClient Client => _client; From 95e0a80719dfc0e462819125aaf4c96f256f9e68 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 20 Apr 2018 22:16:55 +1000 Subject: [PATCH 5/5] remove lazy token --- src/Seq.Api/SeqConnection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index cf90bde..bd80f1f 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -15,12 +15,12 @@ public class SeqConnection : ISeqConnection readonly ConcurrentDictionary> _resourceGroups = new ConcurrentDictionary>(); readonly Lazy> _root; - public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true, CancellationToken token = default) + public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true) { if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl)); _client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); - _root = new Lazy>(() => _client.GetRootAsync(token)); + _root = new Lazy>(() => _client.GetRootAsync()); } public ApiKeysResourceGroup ApiKeys => new ApiKeysResourceGroup(this);