From e2e7ba20e0521b521da0828c32739b470bff59a5 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 16 Jan 2018 14:55:15 +1000 Subject: [PATCH 01/13] Dev version bump [Skip CI] --- src/Seq.Api/Seq.Api.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 0b4a849..ec9dff6 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -1,7 +1,7 @@ Client library for the Seq HTTP API. - 4.2.2 + 4.2.3 Datalust;Contributors netstandard1.3;net452 $(NoWarn);CS1591 From 5400d7536f31f52382541fbd1a374b448dc2b531 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 8 Feb 2018 19:50:32 +1000 Subject: [PATCH 02/13] Since query ranges can now be specified using @Timestamp constraints, the angeStartUtc argument to QueryAsync() and QueryCsvAsync() should be optional. Breaking change. --- src/Seq.Api/ResourceGroups/DataResourceGroup.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs index 08ab59a..d8034f4 100644 --- a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs @@ -26,7 +26,7 @@ internal DataResourceGroup(ISeqConnection connection) /// A structured result set. public async Task QueryAsync( string query, - DateTime rangeStartUtc, + DateTime? rangeStartUtc = null, DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, @@ -49,7 +49,7 @@ public async Task QueryAsync( /// A CSV result set. public async Task QueryCsvAsync( string query, - DateTime rangeStartUtc, + DateTime? rangeStartUtc = null, DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, @@ -62,7 +62,7 @@ public async Task QueryCsvAsync( static void MakeParameters( string query, - DateTime rangeStartUtc, + DateTime? rangeStartUtc, DateTime? rangeEndUtc, SignalExpressionPart signal, SignalEntity unsavedSignal, @@ -72,10 +72,13 @@ static void MakeParameters( { parameters = new Dictionary { - {"q", query}, - {nameof(rangeStartUtc), rangeStartUtc} + {"q", query} }; + if (rangeStartUtc != null) + { + parameters.Add(nameof(rangeStartUtc), rangeStartUtc); + } if (rangeEndUtc != null) { parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value); From e815a97383ddb1cd306403415d63844182b18c31 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Tue, 17 Apr 2018 11:09:46 +1000 Subject: [PATCH 03/13] Update to match the newest (soon-to-be published) Seq 5 preview --- example/SeqTail/SeqTail.csproj | 1 - example/SignalCopy/Program.cs | 7 +-- src/Seq.Api/Client/SeqApiClient.cs | 26 ++++++--- src/Seq.Api/Client/SeqApiException.cs | 17 +++++- src/Seq.Api/Model/Inputs/ApiKeyEntity.cs | 18 +++--- .../Model/Permalinks/PermalinkEntity.cs | 6 ++ src/Seq.Api/Model/Security/Permission.cs | 41 ++++++++++++++ src/Seq.Api/Model/Security/RoleEntity.cs | 10 ++++ src/Seq.Api/Model/Security/WellKnownRole.cs | 8 +++ src/Seq.Api/Model/Shared/ErrorPart.cs | 7 +++ src/Seq.Api/Model/Signals/SignalEntity.cs | 9 ++- src/Seq.Api/Model/Users/UserEntity.cs | 2 +- .../ResourceGroups/ApiKeysResourceGroup.cs | 7 ++- .../ResourceGroups/ApiResourceGroup.cs | 27 +++++++++ .../ResourceGroups/BackupsResourceGroup.cs | 6 ++ .../ResourceGroups/DataResourceGroup.cs | 11 +--- .../ResourceGroups/EntityResourceGroup.cs | 33 ----------- .../ResourceGroups/EventsResourceGroup.cs | 55 +++++++++++++++++-- .../ResourceGroups/PermalinksResourceGroup.cs | 16 ++---- .../ResourceGroups/SignalsResourceGroup.cs | 2 +- .../ResourceGroups/UsersResourceGroup.cs | 2 +- src/Seq.Api/Seq.Api.csproj | 25 +++------ src/Seq.Api/SeqConnection.cs | 4 +- src/Seq.Api/Streams/ObservableStream.cs | 8 ++- 24 files changed, 238 insertions(+), 110 deletions(-) create mode 100644 src/Seq.Api/Model/Security/Permission.cs create mode 100644 src/Seq.Api/Model/Security/RoleEntity.cs create mode 100644 src/Seq.Api/Model/Security/WellKnownRole.cs create mode 100644 src/Seq.Api/Model/Shared/ErrorPart.cs delete mode 100644 src/Seq.Api/ResourceGroups/EntityResourceGroup.cs diff --git a/example/SeqTail/SeqTail.csproj b/example/SeqTail/SeqTail.csproj index c5676ab..7dc54c5 100644 --- a/example/SeqTail/SeqTail.csproj +++ b/example/SeqTail/SeqTail.csproj @@ -24,7 +24,6 @@ - diff --git a/example/SignalCopy/Program.cs b/example/SignalCopy/Program.cs index b831266..539afe6 100644 --- a/example/SignalCopy/Program.cs +++ b/example/SignalCopy/Program.cs @@ -5,7 +5,7 @@ using Seq.Api.Model.Signals; using System.Collections.Generic; -namespace SeqQuery +namespace SignalCopy { class Program { @@ -76,10 +76,9 @@ static async Task Run(string src, string srcKey, string dst, string dstKey) foreach (var signal in await srcConnection.Signals.ListAsync()) { - SignalEntity target; - if (dstSignals.TryGetValue(signal.Title, out target)) + if (dstSignals.TryGetValue(signal.Title, out var target)) { - if (target.IsRestricted) + if (target.IsProtected) { Console.WriteLine($"Skipping restricted signal '{signal.Title}' ({target.Id})"); continue; diff --git a/src/Seq.Api/Client/SeqApiClient.cs b/src/Seq.Api/Client/SeqApiClient.cs index b684fbf..bb5abfc 100644 --- a/src/Seq.Api/Client/SeqApiClient.cs +++ b/src/Seq.Api/Client/SeqApiClient.cs @@ -26,7 +26,7 @@ public class SeqApiClient : IDisposable // Future versions of Seq may not completely support v1 features, however // providing this as an Accept header will ensure what compatibility is available // can be utilised. - const string SeqApiV5MediaType = "application/vnd.datalust.seq.v5+json"; + const string SeqApiV6MediaType = "application/vnd.datalust.seq.v6+json"; readonly HttpClient _httpClient; readonly CookieContainer _cookies = new CookieContainer(); @@ -36,14 +36,18 @@ public class SeqApiClient : IDisposable Converters = { new StringEnumConverter(), new LinkCollectionConverter() } }); - public SeqApiClient(string serverUrl, string apiKey = null) + public SeqApiClient(string serverUrl, string apiKey = null, bool useDefaultCredentials = true) { ServerUrl = serverUrl ?? throw new ArgumentNullException(nameof(serverUrl)); if (!string.IsNullOrEmpty(apiKey)) _apiKey = apiKey; - var handler = new HttpClientHandler { CookieContainer = _cookies, UseDefaultCredentials = true }; + var handler = new HttpClientHandler + { + CookieContainer = _cookies, + UseDefaultCredentials = useDefaultCredentials + }; var baseAddress = serverUrl; if (!baseAddress.EndsWith("/")) @@ -103,6 +107,13 @@ public async Task PostReadStringAsync(ILinked entity, string li return await new StreamReader(stream).ReadToEndAsync(); } + public async Task PostReadStreamAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) + { + var linkUri = ResolveLink(entity, link, parameters); + var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; + return await HttpSendAsync(request).ConfigureAwait(false); + } + public async Task PutAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null) { var linkUri = ResolveLink(entity, link, parameters); @@ -170,7 +181,7 @@ async Task HttpSendAsync(HttpRequestMessage request) if (_apiKey != null) request.Headers.Add("X-Seq-ApiKey", _apiKey); - request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(SeqApiV5MediaType)); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(SeqApiV6MediaType)); var response = await _httpClient.SendAsync(request).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); @@ -186,11 +197,10 @@ async Task HttpSendAsync(HttpRequestMessage request) // ReSharper disable once EmptyGeneralCatchClause catch { } - object error; - if (payload != null && payload.TryGetValue("Error", out error) && error != null) - throw new SeqApiException($"{(int)response.StatusCode} - {error}"); + if (payload != null && payload.TryGetValue("Error", out var error) && error != null) + throw new SeqApiException($"{(int)response.StatusCode} - {error}", response.StatusCode); - throw new SeqApiException($"The Seq request failed ({(int)response.StatusCode})."); + throw new SeqApiException($"The Seq request failed ({(int)response.StatusCode}).", response.StatusCode); } HttpContent MakeJsonContent(object content) diff --git a/src/Seq.Api/Client/SeqApiException.cs b/src/Seq.Api/Client/SeqApiException.cs index 18a9e31..71d5966 100644 --- a/src/Seq.Api/Client/SeqApiException.cs +++ b/src/Seq.Api/Client/SeqApiException.cs @@ -1,12 +1,27 @@ using System; +using System.Net; namespace Seq.Api.Client { + /// + /// Thrown when an action cannot be performed. + /// public class SeqApiException : Exception { - public SeqApiException(string message) + /// + /// Construct a with the given message and status code. + /// + /// A message describing the error. + /// The corresponding status code returned from Seq, if available. + public SeqApiException(string message, HttpStatusCode? statusCode) : base(message) { + StatusCode = statusCode; } + + /// + /// The status code returned from Seq, if available. + /// + public HttpStatusCode? StatusCode { get; } } } \ No newline at end of file diff --git a/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs b/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs index 4032d9e..3ce4b36 100644 --- a/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs +++ b/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs @@ -1,28 +1,24 @@ using System.Collections.Generic; using Seq.Api.Model.LogEvents; +using Seq.Api.Model.Security; using Seq.Api.Model.Signals; namespace Seq.Api.Model.Inputs { public class ApiKeyEntity : Entity { - public ApiKeyEntity() - { - AppliedProperties = new List(); - InputFilter = new SignalFilterPart(); - Metrics = new ApiKeyMetricsPart(); - } - public string Title { get; set; } public string Token { get; set; } - public List AppliedProperties { get; set; } - public SignalFilterPart InputFilter { get; set; } - public bool CanActAsPrincipal { get; set; } + public string TokenPrefix { get; set; } + public List AppliedProperties { get; set; } = new List(); + public SignalFilterPart InputFilter { get; set; } = new SignalFilterPart(); public LogEventLevel? MinimumLevel { get; set; } public bool UseServerTimestamps { get; set; } public int InfluxPerMinute { get; set; } public int ArrivalsPerMinute { get; set; } - public ApiKeyMetricsPart Metrics { get; set; } + public ApiKeyMetricsPart Metrics { get; set; } = new ApiKeyMetricsPart(); public bool IsDefault { get; set; } + public string OwnerId { get; set; } + public HashSet AssignedPermissions { get; set; } = new HashSet(); } } diff --git a/src/Seq.Api/Model/Permalinks/PermalinkEntity.cs b/src/Seq.Api/Model/Permalinks/PermalinkEntity.cs index 74ac2c9..4111112 100644 --- a/src/Seq.Api/Model/Permalinks/PermalinkEntity.cs +++ b/src/Seq.Api/Model/Permalinks/PermalinkEntity.cs @@ -6,6 +6,12 @@ namespace Seq.Api.Model.Permalinks { public class PermalinkEntity : Entity { + /// + /// When retrieving an event that _may_ be permalinked (backwards compatibility), + /// this hint is given by specifiying `permalinkId=unknown` in the API call. + /// + public const string UnknownId = "unknown"; + public string OwnerId { get; set; } public string EventId { get; set; } public DateTime CreatedUtc { get; set; } diff --git a/src/Seq.Api/Model/Security/Permission.cs b/src/Seq.Api/Model/Security/Permission.cs new file mode 100644 index 0000000..88486a0 --- /dev/null +++ b/src/Seq.Api/Model/Security/Permission.cs @@ -0,0 +1,41 @@ +namespace Seq.Api.Model.Security +{ + /// + /// A permission is an access right 1) held by a principal, and 2) demanded by an endpoint. Permissions + /// may be broad, such as the permission to modify administrative settings, or narrow (e.g. currently the + /// permission to ingest events). + /// + public enum Permission + { + /// + /// A sentinel value to detect uninitialized permissions. + /// + Undefined, + + /// + /// Access to publicly-visible assets - the API root/metadata, HTML, JavaScript, CSS, information necessary + /// to initiate the login process, and so-on. + /// + Public, + + /// + /// Add events to the event store. + /// + Ingest, + + /// + /// Query events, dashboards, signals, app instances. + /// + Read, + + /// + /// Write-access to signals, alerts, preferences etc. + /// + Write, + + /// + /// Access to administrative features of Seq, management of other users, app installation, backups. + /// + Setup, + } +} diff --git a/src/Seq.Api/Model/Security/RoleEntity.cs b/src/Seq.Api/Model/Security/RoleEntity.cs new file mode 100644 index 0000000..2d88ce2 --- /dev/null +++ b/src/Seq.Api/Model/Security/RoleEntity.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Seq.Api.Model.Security +{ + public class RoleEntity : Entity + { + public string Title { get; set; } + public HashSet Permissions { get; set; } = new HashSet(); + } +} diff --git a/src/Seq.Api/Model/Security/WellKnownRole.cs b/src/Seq.Api/Model/Security/WellKnownRole.cs new file mode 100644 index 0000000..19678c6 --- /dev/null +++ b/src/Seq.Api/Model/Security/WellKnownRole.cs @@ -0,0 +1,8 @@ +namespace Seq.Api.Model.Security +{ + public static class WellKnownRole + { + public const string AdministratorRoleId = "role-administrator"; + public const string UserRoleId = "role-user"; + } +} diff --git a/src/Seq.Api/Model/Shared/ErrorPart.cs b/src/Seq.Api/Model/Shared/ErrorPart.cs new file mode 100644 index 0000000..b16328f --- /dev/null +++ b/src/Seq.Api/Model/Shared/ErrorPart.cs @@ -0,0 +1,7 @@ +namespace Seq.Api.Model.Shared +{ + public class ErrorPart + { + public string Error { get; set; } + } +} diff --git a/src/Seq.Api/Model/Signals/SignalEntity.cs b/src/Seq.Api/Model/Signals/SignalEntity.cs index d8c4004..c7aa3c4 100644 --- a/src/Seq.Api/Model/Signals/SignalEntity.cs +++ b/src/Seq.Api/Model/Signals/SignalEntity.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Seq.Api.Model.Signals { @@ -21,7 +22,11 @@ public SignalEntity() public bool IsWatched { get; set; } - public bool IsRestricted { get; set; } + [Obsolete("This member has been renamed `IsProtected` to better reflect its purpose.")] + // ReSharper disable once UnusedMember.Global + public bool? IsRestricted { get; set; } + + public bool IsProtected { get; set; } public SignalGrouping Grouping { get; set; } diff --git a/src/Seq.Api/Model/Users/UserEntity.cs b/src/Seq.Api/Model/Users/UserEntity.cs index 2c186f2..4481e61 100644 --- a/src/Seq.Api/Model/Users/UserEntity.cs +++ b/src/Seq.Api/Model/Users/UserEntity.cs @@ -9,9 +9,9 @@ public class UserEntity : Entity public string DisplayName { get; set; } public string EmailAddress { get; set; } public Dictionary Preferences { get; set; } - public bool IsAdministrator { get; set; } public string NewPassword { get; set; } public SignalFilterPart ViewFilter { get; set; } public bool MustChangePassword { get; set; } + public HashSet RoleIds { get; set; } = new HashSet(); } } diff --git a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs index cc52a1a..6047ff2 100644 --- a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs @@ -18,9 +18,10 @@ public async Task FindAsync(string id) return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(string ownerId = null) { - return await GroupListAsync("Items").ConfigureAwait(false); + var parameters = new Dictionary { { "ownerId", ownerId } }; + return await GroupListAsync("Items", parameters).ConfigureAwait(false); } public async Task TemplateAsync() @@ -30,7 +31,7 @@ public async Task TemplateAsync() public async Task AddAsync(ApiKeyEntity entity) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await GroupCreateAsync(entity).ConfigureAwait(false); } public async Task RemoveAsync(ApiKeyEntity entity) diff --git a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs index 42cc2e9..23cf62b 100644 --- a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Threading.Tasks; using Seq.Api.Client; using Seq.Api.Model; @@ -55,6 +56,12 @@ protected async Task GroupPostReadStringAsync(string link, TEnt return await Client.PostReadStringAsync(group, link, content, parameters).ConfigureAwait(false); } + protected async Task GroupPostReadBytesAsync(string link, TEntity content, IDictionary parameters = null) + { + var group = await LoadGroupAsync().ConfigureAwait(false); + return await Client.PostReadStreamAsync(group, link, content, parameters).ConfigureAwait(false); + } + protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null) { var group = await LoadGroupAsync().ConfigureAwait(false); @@ -83,5 +90,25 @@ protected string GetLink(TEntity entity, string link, string orElse) wh { return entity.Links.ContainsKey(link) ? link : orElse; } + + protected async Task GroupCreateAsync(TEntity entity, + IDictionary parameters = null) where TEntity : ILinked + { + ILinked resource; + string link; + + if (entity.Links.ContainsKey("Create")) + { + resource = entity; + link = "Create"; + } + else + { + resource = await LoadGroupAsync().ConfigureAwait(false); + link = "Items"; + } + + return await Client.PostAsync(resource, link, entity, parameters).ConfigureAwait(false); + } } } diff --git a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs index 3740359..734d983 100644 --- a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Threading.Tasks; using Seq.Api.Model.Backups; @@ -22,5 +23,10 @@ public async Task> ListAsync() { return await GroupListAsync("Items").ConfigureAwait(false); } + + public async Task DownloadImmediateAsync() + { + return await GroupPostReadBytesAsync("Immediate", new object()).ConfigureAwait(false); + } } } diff --git a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs index d8034f4..6a464f9 100644 --- a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs @@ -76,21 +76,16 @@ static void MakeParameters( }; if (rangeStartUtc != null) - { parameters.Add(nameof(rangeStartUtc), rangeStartUtc); - } + if (rangeEndUtc != null) - { parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value); - } + if (signal != null) - { parameters.Add(nameof(signal), signal.ToString()); - } + if (timeout != null) - { parameters.Add("timeoutMS", timeout.Value.TotalMilliseconds.ToString("0")); - } body = unsavedSignal ?? new SignalEntity(); } diff --git a/src/Seq.Api/ResourceGroups/EntityResourceGroup.cs b/src/Seq.Api/ResourceGroups/EntityResourceGroup.cs deleted file mode 100644 index 6bee541..0000000 --- a/src/Seq.Api/ResourceGroups/EntityResourceGroup.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Seq.Api.Model; - -namespace Seq.Api.ResourceGroups -{ - public class EntityResourceGroup : ApiResourceGroup - { - internal EntityResourceGroup(string name, ISeqConnection connection) : base(name, connection) - { - } - - protected async Task GroupCreateAsync(TEntity entity, - IDictionary parameters = null) where TEntity : ILinked - { - ILinked resource; - string link; - - if (entity.Links.ContainsKey("Create")) - { - resource = entity; - link = "Create"; - } - else - { - resource = await LoadGroupAsync().ConfigureAwait(false); - link = "Items"; - } - - return await Client.PostAsync(resource, link, entity, parameters).ConfigureAwait(false); - } - } -} diff --git a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs index 8468974..42d6862 100644 --- a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs @@ -16,10 +16,23 @@ internal EventsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id) + /// Find an event, given its id. + /// The id of the event to retrieve. + /// If specified, the event's message template and properties will be rendered into its RenderedMessage property. + /// If the request is for a permalinked event, specifying the id of the permalink here will + /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility + /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// The event. + public async Task FindAsync( + string id, + bool render = false, + string permalinkId = null) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + + var parameters = new Dictionary {{"id", id}}; + + return await GroupGetAsync("Item", parameters).ConfigureAwait(false); } /// @@ -38,6 +51,9 @@ public async Task FindAsync(string id) /// If specified, the number of events after the first match to keep searching before a partial /// result set is returned. Used to improve responsiveness when the result is displayed in a user interface, not typically used in /// batch processing scenarios. + /// If the request is for a permalinked event, specifying the id of the permalink here will + /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility + /// with versions prior to 5.0, which did not mark permalinks explicitly. /// The complete list of events, ordered from least to most recent. public async Task> ListAsync( SignalExpressionPart signal = null, @@ -48,7 +64,8 @@ public async Task> ListAsync( bool render = false, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, - int? shortCircuitAfter = null) + int? shortCircuitAfter = null, + string permalinkId = null) { var parameters = new Dictionary { { "count", count } }; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -59,6 +76,7 @@ public async Task> ListAsync( if (fromDateUtc != null) { parameters.Add("fromDateUtc", fromDateUtc.Value); } if (toDateUtc != null) { parameters.Add("toDateUtc", toDateUtc.Value); } if (shortCircuitAfter != null) { parameters.Add("shortCircuitAfter", shortCircuitAfter.Value); } + if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } var chunks = new List>(); var remaining = count; @@ -104,6 +122,9 @@ public async Task> ListAsync( /// If specified, the number of events after the first match to keep searching before a partial /// result set is returned. Used to improve responsiveness when the result is displayed in a user interface, not typically used in /// batch processing scenarios. + /// If the request is for a permalinked event, specifying the id of the permalink here will + /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility + /// with versions prior to 5.0, which did not mark permalinks explicitly. /// The complete list of events, ordered from least to most recent. public async Task InSignalAsync( SignalEntity unsavedSignal = null, @@ -115,7 +136,8 @@ public async Task InSignalAsync( bool render = false, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, - int? shortCircuitAfter = null) + int? shortCircuitAfter = null, + string permalinkId = null) { var parameters = new Dictionary{{ "count", count }}; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -126,11 +148,32 @@ public async Task InSignalAsync( if (fromDateUtc != null) { parameters.Add("fromDateUtc", fromDateUtc.Value); } if (toDateUtc != null) { parameters.Add("toDateUtc", toDateUtc.Value); } if (shortCircuitAfter != null) { parameters.Add("shortCircuitAfter", shortCircuitAfter.Value); } + if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } var body = unsavedSignal ?? new SignalEntity(); return await GroupPostAsync("InSignal", body, parameters).ConfigureAwait(false); } + /// + /// Retrieve a list of events that match a set of conditions. The complete result is buffered into memory, + /// so if a large result set is expected, use InSignalAsync() and lastReadEventId to page the results. + /// + /// If provided, a signal expression describing the set of events that will be filtered for the result. + /// A strict Seq filter expression to match (text expressions must be in double quotes). To + /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync(). + /// The number of events to retrieve. If not specified will default to 30. + /// An event id from which to start searching (inclusively). + /// An event id to search after (exclusively). + /// If specified, the event's message template and properties will be rendered into its RenderedMessage property. + /// Earliest (inclusive) date/time from which to search. + /// Latest (exclusive) date/time from which to search. + /// If specified, the number of events after the first match to keep searching before a partial + /// result set is returned. Used to improve responsiveness when the result is displayed in a user interface, not typically used in + /// batch processing scenarios. + /// If the request is for a permalinked event, specifying the id of the permalink here will + /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility + /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// The complete list of events, ordered from least to most recent. public async Task InSignalAsync( SignalExpressionPart signal, string filter = null, @@ -140,7 +183,8 @@ public async Task InSignalAsync( bool render = false, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, - int? shortCircuitAfter = null) + int? shortCircuitAfter = null, + string permalinkId = null) { if (signal == null) throw new ArgumentNullException(nameof(signal)); @@ -156,6 +200,7 @@ public async Task InSignalAsync( if (fromDateUtc != null) { parameters.Add("fromDateUtc", fromDateUtc.Value); } if (toDateUtc != null) { parameters.Add("toDateUtc", toDateUtc.Value); } if (shortCircuitAfter != null) { parameters.Add("shortCircuitAfter", shortCircuitAfter.Value); } + if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } return await GroupGetAsync("InSignal", parameters).ConfigureAwait(false); } diff --git a/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs b/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs index a98c098..a280d71 100644 --- a/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs @@ -15,30 +15,26 @@ internal PermalinksResourceGroup(ISeqConnection connection) public async Task FindAsync( string id, bool includeEvent = false, - bool renderEvent = false, - bool includeUser = false) + bool renderEvent = false) { if (id == null) throw new ArgumentNullException(nameof(id)); var parameters = new Dictionary { {"id", id}, {"includeEvent", includeEvent}, - {"renderEvent", renderEvent}, - {"includeUser", includeUser} + {"renderEvent", renderEvent} }; return await GroupGetAsync("Item", parameters).ConfigureAwait(false); } public async Task> ListAsync( bool includeEvent = false, - bool renderEvent = false, - bool includeUser = false) + bool renderEvent = false) { var parameters = new Dictionary { {"includeEvent", includeEvent}, - {"renderEvent", renderEvent}, - {"includeUser", includeUser} + {"renderEvent", renderEvent} }; return await GroupListAsync("Items", parameters).ConfigureAwait(false); @@ -51,7 +47,7 @@ public async Task TemplateAsync() public async Task AddAsync(PermalinkEntity entity) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await GroupCreateAsync(entity).ConfigureAwait(false); } public async Task RemoveAsync(PermalinkEntity entity) @@ -64,4 +60,4 @@ public async Task UpdateAsync(PermalinkEntity entity) await Client.PutAsync(entity, "Self", entity).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 9a4f178..cf68e2b 100644 --- a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs @@ -5,7 +5,7 @@ namespace Seq.Api.ResourceGroups { - public class SignalsResourceGroup : EntityResourceGroup + public class SignalsResourceGroup : ApiResourceGroup { internal SignalsResourceGroup(ISeqConnection connection) : base("Signals", connection) diff --git a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs index 83baf25..aa87ec1 100644 --- a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs @@ -73,7 +73,7 @@ public async Task LoginWindowsIntegratedAsync() var providers = await GroupGetAsync("AuthenticationProviders").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."); + throw new SeqApiException("The Integrated Windows Authentication provider is not available.", null); var response = await Client.HttpClient.GetAsync(provider.Url).ConfigureAwait(false); response.EnsureSuccessStatusCode(); return await FindCurrentAsync().ConfigureAwait(false); diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index ec9dff6..a1dddf3 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -1,37 +1,26 @@ - + Client library for the Seq HTTP API. - 4.2.3 + 5.0.0 Datalust;Contributors - netstandard1.3;net452 + netstandard1.3 $(NoWarn);CS1591 true true Seq.Api Seq.Api seq - Copyright © 2014-2017 Datalust Pty Ltd and Contributors + Copyright © 2014-2018 Datalust Pty Ltd and Contributors https://getseq.net/images/seq-nuget.png https://github.com/datalust/seq-api http://www.apache.org/licenses/LICENSE-2.0 Seq.Api - - true - - + + - - - - - - - - - - + \ No newline at end of file diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index 5d611b2..9789aa5 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -14,10 +14,10 @@ public class SeqConnection : ISeqConnection readonly ConcurrentDictionary> _resourceGroups = new ConcurrentDictionary>(); readonly Lazy> _root; - public SeqConnection(string serverUrl, string apiKey = null) + public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true) { if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl)); - _client = new SeqApiClient(serverUrl, apiKey); + _client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); _root = new Lazy>(() => _client.GetRootAsync()); } diff --git a/src/Seq.Api/Streams/ObservableStream.cs b/src/Seq.Api/Streams/ObservableStream.cs index ac96d4d..983c65c 100644 --- a/src/Seq.Api/Streams/ObservableStream.cs +++ b/src/Seq.Api/Streams/ObservableStream.cs @@ -208,7 +208,13 @@ public void Dispose() catch { } if (_run != null) - _run.ConfigureAwait(false).GetAwaiter().GetResult(); + { + try + { + _run.ConfigureAwait(false).GetAwaiter().GetResult(); + } + catch (TaskCanceledException) { } + } _socket.Dispose(); } From 9021d838366b20b906dbbd64b3096a44afc8e3f2 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 19 Apr 2018 11:09:19 +1000 Subject: [PATCH 04/13] 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 05/13] 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 06/13] 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 07/13] 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 08/13] 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); From f24d2812fd37b9df6440262f00bb9ca1f27a7ecf Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 26 Apr 2018 15:15:08 +1000 Subject: [PATCH 09/13] Fixed mention of Login() -> LoginAsync() [Skip CI] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index baaff62..c4c2adf 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Navigate the "resource groups" exposed as properties of the `connnection`: var installedApps = await connection.Apps.ListAsync(); ``` -**To authenticate**, the `SeqConnection` constructor accepts an `apiKey` parameter (make sure the API key permits _user-level access_) or, if you want to log in with personal credentials you can `await connection.Users.Login(username, password)`. +**To authenticate**, the `SeqConnection` constructor accepts an `apiKey` parameter (make sure the API key permits _user-level access_) or, if you want to log in with personal credentials you can `await connection.Users.LoginAsync(username, password)`. For a more complete example, see the [seq-tail app included in the source](https://github.com/datalust/seq-api/blob/master/example/SeqTail/Program.cs). From 3f728fd32541f2b6119c8788c544e4ee8078bdd9 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Thu, 17 May 2018 10:02:11 +1000 Subject: [PATCH 10/13] Ignore un-populated --- src/Seq.Api/Model/Signals/SignalEntity.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Seq.Api/Model/Signals/SignalEntity.cs b/src/Seq.Api/Model/Signals/SignalEntity.cs index c7aa3c4..d850d04 100644 --- a/src/Seq.Api/Model/Signals/SignalEntity.cs +++ b/src/Seq.Api/Model/Signals/SignalEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; namespace Seq.Api.Model.Signals { @@ -22,8 +23,9 @@ public SignalEntity() public bool IsWatched { get; set; } - [Obsolete("This member has been renamed `IsProtected` to better reflect its purpose.")] // ReSharper disable once UnusedMember.Global + [Obsolete("This member has been renamed `IsProtected` to better reflect its purpose.")] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public bool? IsRestricted { get; set; } public bool IsProtected { get; set; } From d89c85fec55db11b0cc5ce515e83f286758ee09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Pa=C5=BEourek?= Date: Thu, 18 Oct 2018 17:13:27 +0200 Subject: [PATCH 11/13] Fixed samples in README.md I noticed some of the code in README was a bit out of date, so I updated it. Just a tiny tweak really. Thanks. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c4c2adf..dbcb791 100644 --- a/README.md +++ b/README.md @@ -128,13 +128,13 @@ var events = await client.GetAsync(root, "EventsResources"); Use the client to navigate links from entity to entity: ```csharp -var matched = await client.List( +var matched = await client.ListAsync( events, "Items", new Dictionary{{"count", 10}, {"render", true}}); foreach (var match in matched) - Console.WriteLine(matched.RenderedMessage); + Console.WriteLine(match.RenderedMessage); ``` ### Package versioning From b2eb01cf2813790f66861168dd0aaf9b4ca77f00 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 29 Oct 2018 15:57:24 +1000 Subject: [PATCH 12/13] Merge latest Seq 5 API changes --- .../Model/AppInstances/AppInstanceEntity.cs | 12 ++--- .../AppInstances/AppInstanceMetricsPart.cs | 10 ++++ src/Seq.Api/Model/Events/DeleteResultPart.cs | 1 - src/Seq.Api/Model/Inputs/ApiKeyEntity.cs | 7 +-- src/Seq.Api/Model/Inputs/ApiKeyMetricsPart.cs | 1 + src/Seq.Api/Model/Monitoring/AlertPart.cs | 1 + .../Model/Monitoring/DashboardEntity.cs | 2 + .../Monitoring/MeasurementDisplayStylePart.cs | 1 + src/Seq.Api/Model/Settings/SettingName.cs | 5 +- src/Seq.Api/Model/Signals/SignalEntity.cs | 6 ++- .../Model/SqlQueries/SqlQueryEntity.cs | 7 ++- .../Model/Workspaces/WorkspaceContentPart.cs | 11 +++++ .../Model/Workspaces/WorkspaceEntity.cs | 12 +++++ .../ResourceGroups/ApiResourceGroup.cs | 2 +- .../ResourceGroups/AppsResourceGroup.cs | 11 ++++- .../ResourceGroups/DashboardsResourceGroup.cs | 2 +- .../ResourceGroups/SettingsResourceGroup.cs | 12 ++++- .../ResourceGroups/SignalsResourceGroup.cs | 5 +- .../ResourceGroups/SqlQueriesResourceGroup.cs | 7 +-- .../ResourceGroups/WorkspacesResourceGroup.cs | 47 +++++++++++++++++++ src/Seq.Api/Seq.Api.csproj | 2 +- src/Seq.Api/SeqConnection.cs | 4 ++ test/Seq.Api.Tests/Seq.Api.Tests.csproj | 2 +- 23 files changed, 143 insertions(+), 27 deletions(-) create mode 100644 src/Seq.Api/Model/AppInstances/AppInstanceMetricsPart.cs create mode 100644 src/Seq.Api/Model/Workspaces/WorkspaceContentPart.cs create mode 100644 src/Seq.Api/Model/Workspaces/WorkspaceEntity.cs create mode 100644 src/Seq.Api/ResourceGroups/WorkspacesResourceGroup.cs diff --git a/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs b/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs index f4921c5..cbae7ef 100644 --- a/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs +++ b/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; using Seq.Api.Model.Apps; using Seq.Api.Model.Signals; @@ -13,9 +14,7 @@ public AppInstanceEntity() InvocationOverridableSettings = new List(); InvocationOverridableSettingDefinitions = new List(); EventsPerSuppressionWindow = 1; -#pragma warning disable 618 - SignalIds = new List(); -#pragma warning restore 618 + Metrics = new AppInstanceMetricsPart(); } public string Title { get; set; } @@ -29,11 +28,10 @@ public AppInstanceEntity() public int ChannelCapacity { get; set; } public TimeSpan SuppressionTime { get; set; } public int EventsPerSuppressionWindow { get; set; } - public int? ProcessedEventsPerMinute { get; set; } - - [Obsolete("Replaced by InputSignalExpression.")] - public List SignalIds { get; set; } public List InvocationOverridableSettingDefinitions { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public AppInstanceMetricsPart Metrics { get; set; } } } diff --git a/src/Seq.Api/Model/AppInstances/AppInstanceMetricsPart.cs b/src/Seq.Api/Model/AppInstances/AppInstanceMetricsPart.cs new file mode 100644 index 0000000..0f94b74 --- /dev/null +++ b/src/Seq.Api/Model/AppInstances/AppInstanceMetricsPart.cs @@ -0,0 +1,10 @@ +namespace Seq.Api.Model.AppInstances +{ + public class AppInstanceMetricsPart + { + public int ReceivedEventsPerMinute { get; set; } + public int EmittedEventsPerMinute { get; set; } + public long ProcessWorkingSetBytes { get; set; } + public bool IsRunning { get; set; } + } +} diff --git a/src/Seq.Api/Model/Events/DeleteResultPart.cs b/src/Seq.Api/Model/Events/DeleteResultPart.cs index f9e6e43..ebab4f2 100644 --- a/src/Seq.Api/Model/Events/DeleteResultPart.cs +++ b/src/Seq.Api/Model/Events/DeleteResultPart.cs @@ -2,6 +2,5 @@ { public class DeleteResultPart { - public long DeletedEventCount { get; set; } } } diff --git a/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs b/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs index 3ce4b36..058ffd3 100644 --- a/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs +++ b/src/Seq.Api/Model/Inputs/ApiKeyEntity.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Newtonsoft.Json; using Seq.Api.Model.LogEvents; using Seq.Api.Model.Security; using Seq.Api.Model.Signals; @@ -14,11 +15,11 @@ public class ApiKeyEntity : Entity public SignalFilterPart InputFilter { get; set; } = new SignalFilterPart(); public LogEventLevel? MinimumLevel { get; set; } public bool UseServerTimestamps { get; set; } - public int InfluxPerMinute { get; set; } - public int ArrivalsPerMinute { get; set; } - public ApiKeyMetricsPart Metrics { get; set; } = new ApiKeyMetricsPart(); public bool IsDefault { get; set; } public string OwnerId { get; set; } public HashSet AssignedPermissions { get; set; } = new HashSet(); + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public ApiKeyMetricsPart Metrics { get; set; } = new ApiKeyMetricsPart(); } } diff --git a/src/Seq.Api/Model/Inputs/ApiKeyMetricsPart.cs b/src/Seq.Api/Model/Inputs/ApiKeyMetricsPart.cs index b0c3dfd..5ac3870 100644 --- a/src/Seq.Api/Model/Inputs/ApiKeyMetricsPart.cs +++ b/src/Seq.Api/Model/Inputs/ApiKeyMetricsPart.cs @@ -4,5 +4,6 @@ public class ApiKeyMetricsPart { public int ArrivalsPerMinute { get; set; } public int InfluxPerMinute { get; set; } + public long IngestedBytesPerMinute { get; set; } } } \ No newline at end of file diff --git a/src/Seq.Api/Model/Monitoring/AlertPart.cs b/src/Seq.Api/Model/Monitoring/AlertPart.cs index 6e3b8c0..cb3a9fe 100644 --- a/src/Seq.Api/Model/Monitoring/AlertPart.cs +++ b/src/Seq.Api/Model/Monitoring/AlertPart.cs @@ -10,6 +10,7 @@ public class AlertPart public string Id { get; set; } public string Condition { get; set; } + public string Title { get; set; } public TimeSpan MeasurementWindow { get; set; } public TimeSpan StabilizationWindow { get; set; } = TimeSpan.FromSeconds(30); public TimeSpan SuppressionTime { get; set; } diff --git a/src/Seq.Api/Model/Monitoring/DashboardEntity.cs b/src/Seq.Api/Model/Monitoring/DashboardEntity.cs index a94b268..0e932ea 100644 --- a/src/Seq.Api/Model/Monitoring/DashboardEntity.cs +++ b/src/Seq.Api/Model/Monitoring/DashboardEntity.cs @@ -9,6 +9,8 @@ public class DashboardEntity : Entity public string Title { get; set; } + public bool IsProtected { get; set; } + public SignalExpressionPart SignalExpression { get; set; } public List Charts { get; set; } = new List(); diff --git a/src/Seq.Api/Model/Monitoring/MeasurementDisplayStylePart.cs b/src/Seq.Api/Model/Monitoring/MeasurementDisplayStylePart.cs index 4c47411..75209f4 100644 --- a/src/Seq.Api/Model/Monitoring/MeasurementDisplayStylePart.cs +++ b/src/Seq.Api/Model/Monitoring/MeasurementDisplayStylePart.cs @@ -6,6 +6,7 @@ public class MeasurementDisplayStylePart public bool LineFillToZeroY { get; set; } public bool LineShowMarkers { get; set; } = true; public bool BarOverlaySum { get; set; } + public bool SuppressLegend { get; set; } public MeasurementDisplayPalette Palette { get; set; } = MeasurementDisplayPalette.Default; } } diff --git a/src/Seq.Api/Model/Settings/SettingName.cs b/src/Seq.Api/Model/Settings/SettingName.cs index d5cb31d..f9ab369 100644 --- a/src/Seq.Api/Model/Settings/SettingName.cs +++ b/src/Seq.Api/Model/Settings/SettingName.cs @@ -18,9 +18,12 @@ public enum SettingName LazilyFlushEventWrites, MasterKeyIsBackedUp, MinimumFreeStorageSpace, + NewUserShowSignalIds, + NewUserShowQueryIds, + NewUserShowDashboardIds, RequireApiKeyForWritingEvents, RawEventMaximumContentLength, RawPayloadMaximumContentLength, ThemeStyles } -} \ No newline at end of file +} diff --git a/src/Seq.Api/Model/Signals/SignalEntity.cs b/src/Seq.Api/Model/Signals/SignalEntity.cs index c7aa3c4..a755264 100644 --- a/src/Seq.Api/Model/Signals/SignalEntity.cs +++ b/src/Seq.Api/Model/Signals/SignalEntity.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Newtonsoft.Json; namespace Seq.Api.Model.Signals { @@ -20,9 +21,8 @@ public SignalEntity() public List TaggedProperties { get; set; } - public bool IsWatched { get; set; } - [Obsolete("This member has been renamed `IsProtected` to better reflect its purpose.")] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] // ReSharper disable once UnusedMember.Global public bool? IsRestricted { get; set; } @@ -31,5 +31,7 @@ public SignalEntity() public SignalGrouping Grouping { get; set; } public string ExplicitGroupName { get; set; } + + public string OwnerId { get; set; } } } diff --git a/src/Seq.Api/Model/SqlQueries/SqlQueryEntity.cs b/src/Seq.Api/Model/SqlQueries/SqlQueryEntity.cs index a09112a..289d4c1 100644 --- a/src/Seq.Api/Model/SqlQueries/SqlQueryEntity.cs +++ b/src/Seq.Api/Model/SqlQueries/SqlQueryEntity.cs @@ -14,6 +14,9 @@ public SqlQueryEntity() public string Sql { get; set; } - public bool Show { get; set; } + public bool IsProtected { get; set; } + + public string OwnerId { get; set; } + } -} \ No newline at end of file +} diff --git a/src/Seq.Api/Model/Workspaces/WorkspaceContentPart.cs b/src/Seq.Api/Model/Workspaces/WorkspaceContentPart.cs new file mode 100644 index 0000000..bc32a5d --- /dev/null +++ b/src/Seq.Api/Model/Workspaces/WorkspaceContentPart.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Seq.Api.Model.Workspaces +{ + public class WorkspaceContentPart + { + public List SignalIds { get; set; } = new List(); + public List QueryIds { get; set; } = new List(); + public List DashboardIds { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/src/Seq.Api/Model/Workspaces/WorkspaceEntity.cs b/src/Seq.Api/Model/Workspaces/WorkspaceEntity.cs new file mode 100644 index 0000000..27ed398 --- /dev/null +++ b/src/Seq.Api/Model/Workspaces/WorkspaceEntity.cs @@ -0,0 +1,12 @@ +namespace Seq.Api.Model.Workspaces +{ + public class WorkspaceEntity : Entity + { + public string Title { get; set; } + public string Description { get; set; } + public string OwnerId { get; set; } + public bool IsProtected { get; set; } + + public WorkspaceContentPart Content { get; set; } = new WorkspaceContentPart(); + } +} diff --git a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs index 23cf62b..9aa77a2 100644 --- a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs @@ -19,7 +19,7 @@ internal ApiResourceGroup(string name, ISeqConnection connection) _connection = connection; } - protected SeqApiClient Client { get { return _connection.Client; } } + protected SeqApiClient Client => _connection.Client; protected Task LoadGroupAsync() { diff --git a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs index 6488b3b..b46e543 100644 --- a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs @@ -47,9 +47,18 @@ public async Task InstallPackageAsync(string feedId, string packageId { if (feedId == null) throw new ArgumentNullException(nameof(feedId)); if (packageId == null) throw new ArgumentNullException(nameof(packageId)); - var parameters = new Dictionary{{ "feedId", feedId}, {"packageId", 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); } + + public async Task UpdatePackageAsync(AppEntity entity, string version = null, bool force = false) + { + if (entity == null) throw new ArgumentNullException(nameof(entity)); + var parameters = new Dictionary(); + if (force) parameters.Add("force", true); + if (version != null) parameters.Add("version", version); + return await Client.PostAsync(entity, "UpdatePackage", new object(), parameters).ConfigureAwait(false); + } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs index 39eee61..6fbbf79 100644 --- a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs @@ -31,7 +31,7 @@ public async Task TemplateAsync() public async Task AddAsync(DashboardEntity entity) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await GroupCreateAsync(entity).ConfigureAwait(false); } public async Task RemoveAsync(DashboardEntity entity) diff --git a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs index 1ec5292..36a88ec 100644 --- a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs @@ -47,5 +47,15 @@ public async Task UpdateAsync(SettingEntity entity) { await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); } + + public async Task GetInternalErrorReportingAsync() + { + return await GroupGetAsync("InternalErrorReporting").ConfigureAwait(false); + } + + public async Task UpdateInternalErrorReportingAsync(InternalErrorReportingSettingsPart internalErrorReporting) + { + await GroupPutAsync("InternalErrorReporting", internalErrorReporting).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..ce0aab2 100644 --- a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs @@ -18,9 +18,10 @@ public async Task FindAsync(string id) return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(string ownerId = null, bool shared = false) { - return await GroupListAsync("Items").ConfigureAwait(false); + var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; + return await GroupListAsync("Items", parameters).ConfigureAwait(false); } public async Task TemplateAsync() diff --git a/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs b/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs index 3b84725..3279188 100644 --- a/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs @@ -18,9 +18,10 @@ public async Task FindAsync(string id) return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); } - public async Task> ListAsync() + public async Task> ListAsync(string ownerId = null, bool shared = false) { - return await GroupListAsync("Items").ConfigureAwait(false); + var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; + return await GroupListAsync("Items", parameters).ConfigureAwait(false); } public async Task TemplateAsync() @@ -30,7 +31,7 @@ public async Task TemplateAsync() public async Task AddAsync(SqlQueryEntity entity) { - return await Client.PostAsync(entity, "Create", entity).ConfigureAwait(false); + return await GroupCreateAsync(entity).ConfigureAwait(false); } public async Task RemoveAsync(SqlQueryEntity entity) diff --git a/src/Seq.Api/ResourceGroups/WorkspacesResourceGroup.cs b/src/Seq.Api/ResourceGroups/WorkspacesResourceGroup.cs new file mode 100644 index 0000000..2dd6109 --- /dev/null +++ b/src/Seq.Api/ResourceGroups/WorkspacesResourceGroup.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Seq.Api.Model.Workspaces; + +namespace Seq.Api.ResourceGroups +{ + public class WorkspacesResourceGroup : ApiResourceGroup + { + internal WorkspacesResourceGroup(ISeqConnection connection) + : base("Workspaces", connection) + { + } + + public async Task FindAsync(string id) + { + if (id == null) throw new ArgumentNullException(nameof(id)); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }).ConfigureAwait(false); + } + + public async Task> ListAsync(string ownerId = null, bool shared = false) + { + var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; + return await GroupListAsync("Items", parameters).ConfigureAwait(false); + } + + public async Task TemplateAsync() + { + return await GroupGetAsync("Template").ConfigureAwait(false); + } + + public async Task AddAsync(WorkspaceEntity entity) + { + return await GroupCreateAsync(entity).ConfigureAwait(false); + } + + public async Task RemoveAsync(WorkspaceEntity entity) + { + await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); + } + + public async Task UpdateAsync(WorkspaceEntity entity) + { + await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); + } + } +} diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index a1dddf3..9cef215 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -3,7 +3,7 @@ Client library for the Seq HTTP API. 5.0.0 Datalust;Contributors - netstandard1.3 + netstandard1.3;net46;netstandard2.0 $(NoWarn);CS1591 true true diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index 9789aa5..976ce13 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -52,10 +52,14 @@ public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCred public SignalsResourceGroup Signals => new SignalsResourceGroup(this); + public SqlQueriesResourceGroup SqlQueries => new SqlQueriesResourceGroup(this); + public UpdatesResourceGroup Updates => new UpdatesResourceGroup(this); public UsersResourceGroup Users => new UsersResourceGroup(this); + public WorkspacesResourceGroup Workspaces => new WorkspacesResourceGroup(this); + public async Task LoadResourceGroupAsync(string name) { return await _resourceGroups.GetOrAdd(name, ResourceGroupFactory).ConfigureAwait(false); diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 397fd34..b7980fb 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp1.0;net46 + net46;netcoreapp2.0 Seq.Api.Tests Seq.Api.Tests true From 4976ce0f75e63eef5ba88d15e60c7406b52fbb20 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Mon, 29 Oct 2018 16:18:03 +1000 Subject: [PATCH 13/13] Use the name cancellationToken for cancellation toke parameters in line with BCL conventions --- src/Seq.Api/Client/SeqApiClient.cs | 68 +++++++++--------- src/Seq.Api/Model/Signals/SignalEntity.cs | 1 - .../ResourceGroups/ApiKeysResourceGroup.cs | 24 +++---- .../ResourceGroups/ApiResourceGroup.cs | 70 +++++++++---------- .../AppInstancesResourceGroup.cs | 28 ++++---- .../ResourceGroups/AppsResourceGroup.cs | 28 ++++---- .../ResourceGroups/BackupsResourceGroup.cs | 12 ++-- .../ResourceGroups/DashboardsResourceGroup.cs | 24 +++---- .../ResourceGroups/DataResourceGroup.cs | 10 +-- .../DiagnosticsResourceGroup.cs | 12 ++-- .../ResourceGroups/EventsResourceGroup.cs | 39 ++++++----- .../ExpressionsResourceGroup.cs | 8 +-- .../ResourceGroups/FeedsResourceGroup.cs | 24 +++---- .../ResourceGroups/LicensesResourceGroup.cs | 20 +++--- .../ResourceGroups/PermalinksResourceGroup.cs | 24 +++---- .../RetentionPoliciesResourceGroup.cs | 24 +++---- .../ResourceGroups/SettingsResourceGroup.cs | 28 ++++---- .../ResourceGroups/SignalsResourceGroup.cs | 24 +++---- .../ResourceGroups/SqlQueriesResourceGroup.cs | 24 +++---- .../ResourceGroups/UpdatesResourceGroup.cs | 4 +- .../ResourceGroups/UsersResourceGroup.cs | 48 ++++++------- src/Seq.Api/Seq.Api.csproj | 1 + src/Seq.Api/SeqConnection.cs | 15 ++-- src/Seq.Api/Streams/ObservableStream.cs | 18 ++--- test/Seq.Api.Tests/Seq.Api.Tests.csproj | 7 -- 25 files changed, 294 insertions(+), 291 deletions(-) diff --git a/src/Seq.Api/Client/SeqApiClient.cs b/src/Seq.Api/Client/SeqApiClient.cs index fb097a6..d5256c4 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(CancellationToken token = default) + public Task GetRootAsync(CancellationToken cancellationToken = default) { - return HttpGetAsync("api", token); + return HttpGetAsync("api", cancellationToken); } - public Task GetAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) + public Task GetAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetAsync(linkUri, token); + return HttpGetAsync(linkUri, cancellationToken); } - public Task GetStringAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) + public Task GetStringAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetStringAsync(linkUri, token); + return HttpGetStringAsync(linkUri, cancellationToken); } - public Task> ListAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) + public Task> ListAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); - return HttpGetAsync>(linkUri, token); + return HttpGetAsync>(linkUri, cancellationToken); } - public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task PostAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - public async Task PostReadStringAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task PostReadStringAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); return await new StreamReader(stream).ReadToEndAsync(); } - public async Task PostReadStreamAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task PostReadStreamAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Post, linkUri) { Content = MakeJsonContent(content) }; - return await HttpSendAsync(request, token).ConfigureAwait(false); + return await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); } - public async Task PutAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task PutAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Put, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Delete, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); new StreamReader(stream).ReadToEnd(); } - public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + public async Task DeleteAsync(ILinked entity, string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); var request = new HttpRequestMessage(HttpMethod.Delete, linkUri) { Content = MakeJsonContent(content) }; - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - public async Task> StreamAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) + public async Task> StreamAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { - return await WebSocketStreamAsync(entity, link, parameters, reader => _serializer.Deserialize(new JsonTextReader(reader)), token); + return await WebSocketStreamAsync(entity, link, parameters, reader => _serializer.Deserialize(new JsonTextReader(reader)), cancellationToken); } - public async Task> StreamTextAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken token = default) + public async Task> StreamTextAsync(ILinked entity, string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { - return await WebSocketStreamAsync(entity, link, parameters, reader => reader.ReadToEnd(), token); + return await WebSocketStreamAsync(entity, link, parameters, reader => reader.ReadToEnd(), cancellationToken); } - async Task> WebSocketStreamAsync(ILinked entity, string link, IDictionary parameters, Func deserialize, CancellationToken token = default) + async Task> WebSocketStreamAsync(ILinked entity, string link, IDictionary parameters, Func deserialize, CancellationToken cancellationToken = default) { var linkUri = ResolveLink(entity, link, parameters); @@ -157,33 +157,33 @@ async Task> WebSocketStreamAsync(ILinked entity, string l if (_apiKey != null) socket.Options.SetRequestHeader("X-Seq-ApiKey", _apiKey); - await socket.ConnectAsync(new Uri(linkUri), token); + await socket.ConnectAsync(new Uri(linkUri), cancellationToken); return new ObservableStream(socket, deserialize); } - async Task HttpGetAsync(string url, CancellationToken token = default) + async Task HttpGetAsync(string url, CancellationToken cancellationToken = default) { var request = new HttpRequestMessage(HttpMethod.Get, url); - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); return _serializer.Deserialize(new JsonTextReader(new StreamReader(stream))); } - async Task HttpGetStringAsync(string url, CancellationToken token = default) + async Task HttpGetStringAsync(string url, CancellationToken cancellationToken = default) { var request = new HttpRequestMessage(HttpMethod.Get, url); - var stream = await HttpSendAsync(request, token).ConfigureAwait(false); + var stream = await HttpSendAsync(request, cancellationToken).ConfigureAwait(false); return await new StreamReader(stream).ReadToEndAsync(); } - async Task HttpSendAsync(HttpRequestMessage request, CancellationToken token = default) + async Task HttpSendAsync(HttpRequestMessage request, CancellationToken cancellationToken = default) { if (_apiKey != null) request.Headers.Add("X-Seq-ApiKey", _apiKey); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(SeqApiV6MediaType)); - var response = await _httpClient.SendAsync(request, token).ConfigureAwait(false); + var response = await _httpClient.SendAsync(request, cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); if (response.IsSuccessStatusCode) diff --git a/src/Seq.Api/Model/Signals/SignalEntity.cs b/src/Seq.Api/Model/Signals/SignalEntity.cs index a8c5ed6..cab6ddd 100644 --- a/src/Seq.Api/Model/Signals/SignalEntity.cs +++ b/src/Seq.Api/Model/Signals/SignalEntity.cs @@ -21,7 +21,6 @@ public SignalEntity() public List TaggedProperties { get; set; } - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] // ReSharper disable once UnusedMember.Global [Obsolete("This member has been renamed `IsProtected` to better reflect its purpose.")] [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] diff --git a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs index f46b805..0771ced 100644 --- a/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiKeysResourceGroup.cs @@ -13,36 +13,36 @@ internal ApiKeysResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null, CancellationToken token = default) + public async Task> ListAsync(string ownerId = null, CancellationToken cancellationToken = default) { var parameters = new Dictionary { { "ownerId", ownerId } }; - return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(ApiKeyEntity entity, CancellationToken token = default) + public async Task AddAsync(ApiKeyEntity entity, CancellationToken cancellationToken = default) { - return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); + return await GroupCreateAsync(entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(ApiKeyEntity entity, CancellationToken token = default) + public async Task RemoveAsync(ApiKeyEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(ApiKeyEntity entity, CancellationToken token = default) + public async Task UpdateAsync(ApiKeyEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs index 778f3a3..9c3ef4d 100644 --- a/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ApiResourceGroup.cs @@ -22,69 +22,69 @@ internal ApiResourceGroup(string name, ISeqConnection connection) protected SeqApiClient Client => _connection.Client; - protected Task LoadGroupAsync(CancellationToken token = default) + protected Task LoadGroupAsync(CancellationToken cancellationToken = default) { - return _connection.LoadResourceGroupAsync(_name, token); + return _connection.LoadResourceGroupAsync(_name, cancellationToken); } - protected async Task GroupGetAsync(string link, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupGetAsync(string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.GetAsync(group, link, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.GetAsync(group, link, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupGetStringAsync(string link, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupGetStringAsync(string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.GetStringAsync(group, link, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.GetStringAsync(group, link, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task> GroupListAsync(string link, IDictionary parameters = null, CancellationToken token = default) + protected async Task> GroupListAsync(string link, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.ListAsync(group, link, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.ListAsync(group, link, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - await Client.PostAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + await Client.PostAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupPostReadStringAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupPostReadStringAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.PostReadStringAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.PostReadStringAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupPostReadBytesAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupPostReadBytesAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.PostReadStreamAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.PostReadStreamAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupPostAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.PostAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.PostAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupPutAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupPutAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - await Client.PutAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + await Client.PutAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - await Client.DeleteAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + await Client.DeleteAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } - protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken token = default) + protected async Task GroupDeleteAsync(string link, TEntity content, IDictionary parameters = null, CancellationToken cancellationToken = default) { - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.DeleteAsync(group, link, content, parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.DeleteAsync(group, link, content, parameters, cancellationToken).ConfigureAwait(false); } protected string GetLink(TEntity entity, string link, string orElse) where TEntity : ILinked @@ -93,7 +93,7 @@ protected string GetLink(TEntity entity, string link, string orElse) wh } protected async Task GroupCreateAsync(TEntity entity, - IDictionary parameters = null, CancellationToken token = default) + IDictionary parameters = null, CancellationToken cancellationToken = default) where TEntity : ILinked { ILinked resource; @@ -106,11 +106,11 @@ protected async Task GroupCreateAsync(TEntity ent } else { - resource = await LoadGroupAsync(token).ConfigureAwait(false); + resource = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); link = "Items"; } - return await Client.PostAsync(resource, link, entity, parameters, token).ConfigureAwait(false); + return await Client.PostAsync(resource, link, entity, parameters, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs index 7672744..32327a9 100644 --- a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs @@ -13,49 +13,49 @@ internal AppInstancesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(string appId, CancellationToken token = default) + public async Task TemplateAsync(string appId, CancellationToken cancellationToken = default) { if (appId == null) throw new ArgumentNullException(nameof(appId)); - return await GroupGetAsync("Template", new Dictionary { { "appId", appId } }, token).ConfigureAwait(false); + return await GroupGetAsync("Template", new Dictionary { { "appId", appId } }, cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(AppInstanceEntity entity, bool runOnExisting = false, CancellationToken token = default) + public async Task AddAsync(AppInstanceEntity entity, bool runOnExisting = false, CancellationToken cancellationToken = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - return await Client.PostAsync(entity, "Create", entity, new Dictionary { { "runOnExisting", runOnExisting } }, token) + return await Client.PostAsync(entity, "Create", entity, new Dictionary { { "runOnExisting", runOnExisting } }, cancellationToken) .ConfigureAwait(false); } - public async Task RemoveAsync(AppInstanceEntity entity, CancellationToken token = default) + public async Task RemoveAsync(AppInstanceEntity entity, CancellationToken cancellationToken = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(AppInstanceEntity entity, CancellationToken token = default) + public async Task UpdateAsync(AppInstanceEntity entity, CancellationToken cancellationToken = default) { if (entity == null) throw new ArgumentNullException(nameof(entity)); - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task InvokeAsync(AppInstanceEntity entity, string eventId, IReadOnlyDictionary settingOverrides, CancellationToken token = default) + public async Task InvokeAsync(AppInstanceEntity entity, string eventId, IReadOnlyDictionary settingOverrides, CancellationToken cancellationToken = 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}}, token); + await Client.PostAsync(entity, "Invoke", postedSettings, new Dictionary{{"eventId", eventId}}, cancellationToken); } } } diff --git a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs index 437b96c..751d2ea 100644 --- a/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppsResourceGroup.cs @@ -13,44 +13,44 @@ internal AppsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(AppEntity entity, CancellationToken token = default) + public async Task AddAsync(AppEntity entity, CancellationToken cancellationToken = default) { - return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(AppEntity entity, CancellationToken token = default) + public async Task RemoveAsync(AppEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(AppEntity entity, CancellationToken token = default) + public async Task UpdateAsync(AppEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task InstallPackageAsync(string feedId, string packageId, string version = null, CancellationToken token = default) + public async Task InstallPackageAsync(string feedId, string packageId, string version = null, CancellationToken cancellationToken = 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, token).ConfigureAwait(false); + return await GroupPostAsync("InstallPackage", new object(), parameters, cancellationToken).ConfigureAwait(false); } public async Task UpdatePackageAsync(AppEntity entity, string version = null, bool force = false) diff --git a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs index 2b54591..08398d4 100644 --- a/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/BackupsResourceGroup.cs @@ -14,20 +14,20 @@ internal BackupsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task DownloadImmediateAsync(CancellationToken token = default) + public async Task DownloadImmediateAsync(CancellationToken cancellationToken = default) { - return await GroupPostReadBytesAsync("Immediate", new object(), token: token).ConfigureAwait(false); + return await GroupPostReadBytesAsync("Immediate", new object(), cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs index a9d3bc6..5b63e9b 100644 --- a/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DashboardsResourceGroup.cs @@ -13,36 +13,36 @@ internal DashboardsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken token = default) + public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken cancellationToken = default) { var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; - return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(DashboardEntity entity, CancellationToken token = default) + public async Task AddAsync(DashboardEntity entity, CancellationToken cancellationToken = default) { - return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); + return await GroupCreateAsync(entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(DashboardEntity entity, CancellationToken token = default) + public async Task RemoveAsync(DashboardEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(DashboardEntity entity, CancellationToken token = default) + public async Task UpdateAsync(DashboardEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).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 398e130..c06f518 100644 --- a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs @@ -24,6 +24,7 @@ internal DataResourceGroup(ISeqConnection connection) /// A constructed signal that may not appear on the server, for example, a that has been /// created but not saved, a signal from another server, or the modified representation of an entity already persisted. /// The query timeout; if not specified, the query will run until completion. + /// Token through which the operation can be cancelled. /// A structured result set. public async Task QueryAsync( string query, @@ -32,10 +33,10 @@ public async Task QueryAsync( SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, TimeSpan? timeout = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters); - return await GroupPostAsync("Query", body, parameters, token).ConfigureAwait(false); + return await GroupPostAsync("Query", body, parameters, cancellationToken).ConfigureAwait(false); } /// @@ -48,6 +49,7 @@ public async Task QueryAsync( /// A constructed signal that may not appear on the server, for example, a that has been /// created but not saved, a signal from another server, or the modified representation of an entity already persisted. /// The query timeout; if not specified, the query will run until completion. + /// Token through which the operation can be cancelled. /// A CSV result set. public async Task QueryCsvAsync( string query, @@ -56,11 +58,11 @@ public async Task QueryCsvAsync( SignalExpressionPart signal = null, SignalEntity unsavedSignal = null, TimeSpan? timeout = null, - CancellationToken token = default) + CancellationToken cancellationToken = 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, token).ConfigureAwait(false); + return await GroupPostReadStringAsync("Query", body, parameters, cancellationToken).ConfigureAwait(false); } static void MakeParameters( diff --git a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs index 9844dfd..4ae8e7c 100644 --- a/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DiagnosticsResourceGroup.cs @@ -11,19 +11,19 @@ internal DiagnosticsResourceGroup(ISeqConnection connection) { } - public async Task GetServerMetricsAsync(CancellationToken token = default) + public async Task GetServerMetricsAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("ServerMetrics", token: token).ConfigureAwait(false); + return await GroupGetAsync("ServerMetrics", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetServerStatusAsync(CancellationToken token = default) + public async Task GetServerStatusAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("ServerStatus", token: token).ConfigureAwait(false); + return await GroupGetAsync("ServerStatus", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetIngestionLogAsync(CancellationToken token = default) + public async Task GetIngestionLogAsync(CancellationToken cancellationToken = default) { - return await GroupGetStringAsync("IngestionLog", token: token).ConfigureAwait(false); + return await GroupGetStringAsync("IngestionLog", cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs index db4d529..cca68e7 100644 --- a/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/EventsResourceGroup.cs @@ -23,18 +23,19 @@ internal EventsResourceGroup(ISeqConnection connection) /// If the request is for a permalinked event, specifying the id of the permalink here will /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// Token through which the operation can be cancelled. /// The event. public async Task FindAsync( string id, bool render = false, string permalinkId = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); var parameters = new Dictionary {{"id", id}}; - return await GroupGetAsync("Item", parameters, token).ConfigureAwait(false); + return await GroupGetAsync("Item", parameters, cancellationToken).ConfigureAwait(false); } /// @@ -56,6 +57,7 @@ public async Task FindAsync( /// If the request is for a permalinked event, specifying the id of the permalink here will /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// Token through which the operation can be cancelled. /// The complete list of events, ordered from least to most recent. public async Task> ListAsync( SignalExpressionPart signal = null, @@ -68,7 +70,7 @@ public async Task> ListAsync( DateTime? toDateUtc = null, int? shortCircuitAfter = null, string permalinkId = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary { { "count", count } }; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -86,7 +88,7 @@ public async Task> ListAsync( while (true) { - var resultSet = await GroupGetAsync("InSignal", parameters, token).ConfigureAwait(false); + var resultSet = await GroupGetAsync("InSignal", parameters, cancellationToken).ConfigureAwait(false); chunks.Add(resultSet.Events); remaining -= resultSet.Events.Count; @@ -128,6 +130,7 @@ public async Task> ListAsync( /// If the request is for a permalinked event, specifying the id of the permalink here will /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// Token through which the operation can be cancelled. /// The complete list of events, ordered from least to most recent. public async Task InSignalAsync( SignalEntity unsavedSignal = null, @@ -141,7 +144,7 @@ public async Task InSignalAsync( DateTime? toDateUtc = null, int? shortCircuitAfter = null, string permalinkId = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary{{ "count", count }}; if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -155,7 +158,7 @@ public async Task InSignalAsync( if (permalinkId != null) { parameters.Add("permalinkId", permalinkId); } var body = unsavedSignal ?? new SignalEntity(); - return await GroupPostAsync("InSignal", body, parameters, token).ConfigureAwait(false); + return await GroupPostAsync("InSignal", body, parameters, cancellationToken).ConfigureAwait(false); } /// @@ -177,6 +180,7 @@ public async Task InSignalAsync( /// If the request is for a permalinked event, specifying the id of the permalink here will /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility /// with versions prior to 5.0, which did not mark permalinks explicitly. + /// Token through which the operation can be cancelled. /// The complete list of events, ordered from least to most recent. public async Task InSignalAsync( SignalExpressionPart signal, @@ -189,7 +193,7 @@ public async Task InSignalAsync( DateTime? toDateUtc = null, int? shortCircuitAfter = null, string permalinkId = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { if (signal == null) throw new ArgumentNullException(nameof(signal)); @@ -207,7 +211,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, token).ConfigureAwait(false); + return await GroupGetAsync("InSignal", parameters, cancellationToken).ConfigureAwait(false); } /// @@ -220,6 +224,7 @@ public async Task InSignalAsync( /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync(). /// Earliest (inclusive) date/time from which to delete. /// Latest (exclusive) date/time from which to delete. + /// Token through which the operation can be cancelled. /// A result carrying the count of events deleted. public async Task DeleteInSignalAsync( SignalEntity unsavedSignal = null, @@ -227,7 +232,7 @@ public async Task DeleteInSignalAsync( string filter = null, DateTime? fromDateUtc = null, DateTime? toDateUtc = null, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } @@ -236,7 +241,7 @@ public async Task DeleteInSignalAsync( if (toDateUtc != null) { parameters.Add("toDateUtc", toDateUtc.Value); } var body = unsavedSignal ?? new SignalEntity(); - return await GroupDeleteAsync("DeleteInSignal", body, parameters, token).ConfigureAwait(false); + return await GroupDeleteAsync("DeleteInSignal", body, parameters, cancellationToken).ConfigureAwait(false); } /// @@ -246,19 +251,20 @@ public async Task DeleteInSignalAsync( /// If provided, a signal expression describing the set of events that will be filtered for the result. /// A strict Seq filter expression to match (text expressions must be in double quotes). To /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync(). + /// Token through which the operation can be cancelled. /// An observable that will stream events from the server to subscribers. Events will be buffered server-side until the first /// 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, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } if (filter != null) { parameters.Add("filter", filter); } - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.StreamAsync(group, "Stream", parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.StreamAsync(group, "Stream", parameters, cancellationToken).ConfigureAwait(false); } /// @@ -268,19 +274,20 @@ public async Task> StreamAsync( /// If provided, a signal expression describing the set of events that will be filtered for the result. /// A strict Seq filter expression to match (text expressions must be in double quotes). To /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync(). + /// Token through which the operation can be cancelled. /// An observable that will stream events from the server to subscribers. Events will be buffered server-side until the first /// 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, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary(); if (signal != null) { parameters.Add("signal", signal.ToString()); } if (filter != null) { parameters.Add("filter", filter); } - var group = await LoadGroupAsync(token).ConfigureAwait(false); - return await Client.StreamTextAsync(group, "Stream", parameters, token).ConfigureAwait(false); + var group = await LoadGroupAsync(cancellationToken).ConfigureAwait(false); + return await Client.StreamTextAsync(group, "Stream", parameters, cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs b/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs index b39c23e..1088f8b 100644 --- a/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/ExpressionsResourceGroup.cs @@ -12,20 +12,20 @@ internal ExpressionsResourceGroup(ISeqConnection connection) { } - public Task ToStrictAsync(string fuzzy, CancellationToken token = default) + public Task ToStrictAsync(string fuzzy, CancellationToken cancellationToken = default) { return GroupGetAsync("ToStrict", new Dictionary { {"fuzzy", fuzzy} - }, token); + }, cancellationToken); } - public Task ToSqlAsync(string fuzzy, CancellationToken token = default) + public Task ToSqlAsync(string fuzzy, CancellationToken cancellationToken = default) { return GroupGetAsync("ToSql", new Dictionary { {"fuzzy", fuzzy} - }, token); + }, cancellationToken); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs b/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs index 5aafeb5..3e0e1bb 100644 --- a/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/FeedsResourceGroup.cs @@ -13,35 +13,35 @@ internal FeedsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(NuGetFeedEntity entity, CancellationToken token = default) + public async Task AddAsync(NuGetFeedEntity entity, CancellationToken cancellationToken = default) { - return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(NuGetFeedEntity entity, CancellationToken token = default) + public async Task RemoveAsync(NuGetFeedEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(NuGetFeedEntity entity, CancellationToken token = default) + public async Task UpdateAsync(NuGetFeedEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs index 302ac93..af40301 100644 --- a/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/LicensesResourceGroup.cs @@ -13,30 +13,30 @@ internal LicensesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task FindCurrentAsync(CancellationToken token = default) + public async Task FindCurrentAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Current", token: token).ConfigureAwait(false); + return await GroupGetAsync("Current", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(LicenseEntity entity, CancellationToken token = default) + public async Task UpdateAsync(LicenseEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task DowngradeAsync(CancellationToken token = default) + public async Task DowngradeAsync(CancellationToken cancellationToken = default) { - await GroupPostAsync("Downgrade", new object(), token: token).ConfigureAwait(false); + await GroupPostAsync("Downgrade", new object(), cancellationToken: cancellationToken).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 3fc3fd5..a899911 100644 --- a/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/PermalinksResourceGroup.cs @@ -17,7 +17,7 @@ public async Task FindAsync( string id, bool includeEvent = false, bool renderEvent = false, - CancellationToken token = default) + CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); var parameters = new Dictionary @@ -26,13 +26,13 @@ public async Task FindAsync( {"includeEvent", includeEvent}, {"renderEvent", renderEvent} }; - return await GroupGetAsync("Item", parameters, token).ConfigureAwait(false); + return await GroupGetAsync("Item", parameters, cancellationToken).ConfigureAwait(false); } public async Task> ListAsync( bool includeEvent = false, bool renderEvent = false, - CancellationToken token = default) + CancellationToken cancellationToken = default) { var parameters = new Dictionary { @@ -40,27 +40,27 @@ public async Task> ListAsync( {"renderEvent", renderEvent} }; - return await GroupListAsync("Items", parameters, token).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(PermalinkEntity entity, CancellationToken token = default) + public async Task AddAsync(PermalinkEntity entity, CancellationToken cancellationToken = default) { - return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); + return await GroupCreateAsync(entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(PermalinkEntity entity, CancellationToken token = default) + public async Task RemoveAsync(PermalinkEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(PermalinkEntity entity, CancellationToken token = default) + public async Task UpdateAsync(PermalinkEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs b/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs index 430fad8..1e3ac18 100644 --- a/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/RetentionPoliciesResourceGroup.cs @@ -13,35 +13,35 @@ internal RetentionPoliciesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(RetentionPolicyEntity entity, CancellationToken token = default) + public async Task AddAsync(RetentionPolicyEntity entity, CancellationToken cancellationToken = default) { - return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(RetentionPolicyEntity entity, CancellationToken token = default) + public async Task RemoveAsync(RetentionPolicyEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(RetentionPolicyEntity entity, CancellationToken token = default) + public async Task UpdateAsync(RetentionPolicyEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).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 53375e8..9968d1c 100644 --- a/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SettingsResourceGroup.cs @@ -13,40 +13,40 @@ internal SettingsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task FindNamedAsync(SettingName name, CancellationToken token = default) + public async Task FindNamedAsync(SettingName name, CancellationToken cancellationToken = default) { - return await GroupGetAsync(name.ToString(), token: token).ConfigureAwait(false); + return await GroupGetAsync(name.ToString(), cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(SettingEntity entity, CancellationToken token = default) + public async Task AddAsync(SettingEntity entity, CancellationToken cancellationToken = default) { - return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(SettingEntity entity, CancellationToken token = default) + public async Task RemoveAsync(SettingEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(SettingEntity entity, CancellationToken token = default) + public async Task UpdateAsync(SettingEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } public async Task GetInternalErrorReportingAsync() diff --git a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs index c210678..594143c 100644 --- a/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SignalsResourceGroup.cs @@ -13,36 +13,36 @@ internal SignalsResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken token) + public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken cancellationToken = default) { var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; - return await GroupListAsync("Items", parameters, token: token).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(SignalEntity entity, CancellationToken token = default) + public async Task AddAsync(SignalEntity entity, CancellationToken cancellationToken = default) { - return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); + return await GroupCreateAsync(entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(SignalEntity entity, CancellationToken token = default) + public async Task RemoveAsync(SignalEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(SignalEntity entity, CancellationToken token = default) + public async Task UpdateAsync(SignalEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).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 1f36192..7d5aac3 100644 --- a/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/SqlQueriesResourceGroup.cs @@ -13,36 +13,36 @@ internal SqlQueriesResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken token) + public async Task> ListAsync(string ownerId = null, bool shared = false, CancellationToken cancellationToken = default) { var parameters = new Dictionary { { "ownerId", ownerId }, { "shared", shared } }; - return await GroupListAsync("Items", parameters, token: token).ConfigureAwait(false); + return await GroupListAsync("Items", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(SqlQueryEntity entity, CancellationToken token = default) + public async Task AddAsync(SqlQueryEntity entity, CancellationToken cancellationToken = default) { - return await GroupCreateAsync(entity, token: token).ConfigureAwait(false); + return await GroupCreateAsync(entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(SqlQueryEntity entity, CancellationToken token = default) + public async Task RemoveAsync(SqlQueryEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(SqlQueryEntity entity, CancellationToken token = default) + public async Task UpdateAsync(SqlQueryEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs b/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs index 61149aa..953d136 100644 --- a/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UpdatesResourceGroup.cs @@ -12,9 +12,9 @@ internal UpdatesResourceGroup(ISeqConnection connection) { } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs index e885083..2f94120 100644 --- a/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/UsersResourceGroup.cs @@ -15,69 +15,69 @@ internal UsersResourceGroup(ISeqConnection connection) { } - public async Task FindAsync(string id, CancellationToken token = default) + public async Task FindAsync(string id, CancellationToken cancellationToken = default) { if (id == null) throw new ArgumentNullException(nameof(id)); - return await GroupGetAsync("Item", new Dictionary { { "id", id } }, token).ConfigureAwait(false); + return await GroupGetAsync("Item", new Dictionary { { "id", id } }, cancellationToken).ConfigureAwait(false); } - public async Task FindCurrentAsync(CancellationToken token = default) + public async Task FindCurrentAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Current", token: token).ConfigureAwait(false); + return await GroupGetAsync("Current", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task> ListAsync(CancellationToken token = default) + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await GroupListAsync("Items", token: token).ConfigureAwait(false); + return await GroupListAsync("Items", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task TemplateAsync(CancellationToken token = default) + public async Task TemplateAsync(CancellationToken cancellationToken = default) { - return await GroupGetAsync("Template", token: token).ConfigureAwait(false); + return await GroupGetAsync("Template", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task AddAsync(UserEntity entity, CancellationToken token = default) + public async Task AddAsync(UserEntity entity, CancellationToken cancellationToken = default) { - return await Client.PostAsync(entity, "Create", entity, token: token).ConfigureAwait(false); + return await Client.PostAsync(entity, "Create", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task RemoveAsync(UserEntity entity, CancellationToken token = default) + public async Task RemoveAsync(UserEntity entity, CancellationToken cancellationToken = default) { - await Client.DeleteAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.DeleteAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task UpdateAsync(UserEntity entity, CancellationToken token = default) + public async Task UpdateAsync(UserEntity entity, CancellationToken cancellationToken = default) { - await Client.PutAsync(entity, "Self", entity, token: token).ConfigureAwait(false); + await Client.PutAsync(entity, "Self", entity, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task LoginAsync(string username, string password, CancellationToken token = default) + public async Task LoginAsync(string username, string password, CancellationToken cancellationToken = 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, token: token).ConfigureAwait(false); + return await GroupPostAsync("Login", credentials, cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task LogoutAsync(CancellationToken token = default) + public async Task LogoutAsync(CancellationToken cancellationToken = default) { - await GroupPostAsync("Logout", new object(), token: token).ConfigureAwait(false); + await GroupPostAsync("Logout", new object(), cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task GetSearchHistoryAsync(UserEntity entity, CancellationToken token = default) + public async Task GetSearchHistoryAsync(UserEntity entity, CancellationToken cancellationToken = default) { - return await Client.GetAsync(entity, "SearchHistory", token: token).ConfigureAwait(false); + return await Client.GetAsync(entity, "SearchHistory", cancellationToken: cancellationToken).ConfigureAwait(false); } - public async Task LoginWindowsIntegratedAsync(CancellationToken token = default) + public async Task LoginWindowsIntegratedAsync(CancellationToken cancellationToken = default) { - var providers = await GroupGetAsync("AuthenticationProviders", token: token).ConfigureAwait(false); + var providers = await GroupGetAsync("AuthenticationProviders", cancellationToken: cancellationToken).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, token).ConfigureAwait(false); + var response = await Client.HttpClient.GetAsync(provider.Url, cancellationToken).ConfigureAwait(false); response.EnsureSuccessStatusCode(); - return await FindCurrentAsync(token).ConfigureAwait(false); + return await FindCurrentAsync(cancellationToken).ConfigureAwait(false); } } } diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 455e49a..e8b24b0 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -15,6 +15,7 @@ https://github.com/datalust/seq-api http://www.apache.org/licenses/LICENSE-2.0 Seq.Api + 7.1 diff --git a/src/Seq.Api/SeqConnection.cs b/src/Seq.Api/SeqConnection.cs index bcf5fb9..6d3e722 100644 --- a/src/Seq.Api/SeqConnection.cs +++ b/src/Seq.Api/SeqConnection.cs @@ -11,16 +11,15 @@ namespace Seq.Api { public class SeqConnection : ISeqConnection { - readonly SeqApiClient _client; readonly ConcurrentDictionary> _resourceGroups = new ConcurrentDictionary>(); readonly Lazy> _root; public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true) { if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl)); - _client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); + Client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials); - _root = new Lazy>(() => _client.GetRootAsync()); + _root = new Lazy>(() => Client.GetRootAsync()); } public ApiKeysResourceGroup ApiKeys => new ApiKeysResourceGroup(this); @@ -61,16 +60,16 @@ public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCred public WorkspacesResourceGroup Workspaces => new WorkspacesResourceGroup(this); - public async Task LoadResourceGroupAsync(string name, CancellationToken token = default) + public async Task LoadResourceGroupAsync(string name, CancellationToken cancellationToken = default) { - return await _resourceGroups.GetOrAdd(name, s => ResourceGroupFactory(s, token)).ConfigureAwait(false); + return await _resourceGroups.GetOrAdd(name, s => ResourceGroupFactory(s, cancellationToken)).ConfigureAwait(false); } - async Task ResourceGroupFactory(string name, CancellationToken token = default) + async Task ResourceGroupFactory(string name, CancellationToken cancellationToken = default) { - return await _client.GetAsync(await _root.Value, name + "Resources", token: token).ConfigureAwait(false); + return await Client.GetAsync(await _root.Value, name + "Resources", cancellationToken: cancellationToken).ConfigureAwait(false); } - public SeqApiClient Client => _client; + public SeqApiClient Client { get; } } } diff --git a/src/Seq.Api/Streams/ObservableStream.cs b/src/Seq.Api/Streams/ObservableStream.cs index 983c65c..0ddc419 100644 --- a/src/Seq.Api/Streams/ObservableStream.cs +++ b/src/Seq.Api/Streams/ObservableStream.cs @@ -38,11 +38,8 @@ public sealed partial class ObservableStream : IObservable, IDisposable internal ObservableStream(ClientWebSocket socket, Func deserialize) { - if (socket == null) throw new ArgumentNullException(nameof(socket)); - if (deserialize == null) throw new ArgumentNullException(nameof(deserialize)); - - _deserialize = deserialize; - _socket = socket; + _deserialize = deserialize ?? throw new ArgumentNullException(nameof(deserialize)); + _socket = socket ?? throw new ArgumentNullException(nameof(socket)); } public IDisposable Subscribe(IObserver observer) @@ -179,7 +176,7 @@ void End() OnError(exceptions); } - void OnError(IList exceptions) + static void OnError(IEnumerable exceptions) { // This will hit TaskScheduler.UnobservedTaskException throw new AggregateException("At least one observer failed to accept the event", exceptions); @@ -205,7 +202,10 @@ public void Dispose() } } } - catch { } + catch + { + // Don't mask exceptions by throwing here during unwinding + } if (_run != null) { @@ -213,7 +213,9 @@ public void Dispose() { _run.ConfigureAwait(false).GetAwaiter().GetResult(); } - catch (TaskCanceledException) { } + catch (TaskCanceledException) + { + } } _socket.Dispose(); diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 9445e64..b573d26 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -2,14 +2,7 @@ net46;netcoreapp2.0 - Seq.Api.Tests - Seq.Api.Tests true - $(PackageTargetFallback);dnxcore50;portable-net45+win8 - 1.0.4 - false - false - false