From e8288c83bbc5c04838f425d9bb3da330743e79ab Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Wed, 10 Jan 2018 11:31:45 +1000 Subject: [PATCH] Update to match latest Seq 4.2 preview API --- src/Seq.Api/Client/SeqApiClient.cs | 8 ++++---- .../Model/AppInstances/AppInstanceEntity.cs | 6 ++++++ src/Seq.Api/Model/Monitoring/AlertPart.cs | 9 +++++++++ .../Model/Monitoring/MeasurementDisplayType.cs | 3 ++- .../InternalErrorReportingSettingsPart.cs | 8 ++++++++ .../ResourceGroups/AppInstancesResourceGroup.cs | 14 +++++++++++++- src/Seq.Api/ResourceGroups/DataResourceGroup.cs | 17 +++++++++++++---- src/Seq.Api/Seq.Api.csproj | 2 +- 8 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/Seq.Api/Model/Settings/InternalErrorReportingSettingsPart.cs diff --git a/src/Seq.Api/Client/SeqApiClient.cs b/src/Seq.Api/Client/SeqApiClient.cs index 2963a58..b684fbf 100644 --- a/src/Seq.Api/Client/SeqApiClient.cs +++ b/src/Seq.Api/Client/SeqApiClient.cs @@ -204,7 +204,7 @@ static string ResolveLink(ILinked entity, string link, IDictionary p.Key).Except(template.GetParameterNames()).ToArray(); if (missing.Any()) - throw new ArgumentException("The URI template '" + expression + "' does not contain parameter: " + string.Join(",", missing)); + throw new ArgumentException($"The URI template `{expression}` does not contain parameter: `{string.Join("`, `", missing)}`."); foreach (var parameter in parameters) { - var value = parameter.Value is DateTime - ? ((DateTime) parameter.Value).ToString("O") + var value = parameter.Value is DateTime time + ? time.ToString("O") : parameter.Value; template.SetParameter(parameter.Key, value); diff --git a/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs b/src/Seq.Api/Model/AppInstances/AppInstanceEntity.cs index 67ae606..f4921c5 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 Seq.Api.Model.Apps; using Seq.Api.Model.Signals; namespace Seq.Api.Model.AppInstances @@ -9,6 +10,8 @@ public class AppInstanceEntity : Entity public AppInstanceEntity() { Settings = new Dictionary(); + InvocationOverridableSettings = new List(); + InvocationOverridableSettingDefinitions = new List(); EventsPerSuppressionWindow = 1; #pragma warning disable 618 SignalIds = new List(); @@ -19,6 +22,7 @@ public AppInstanceEntity() public bool IsManualInputOnly { get; set; } public string AppId { get; set; } public Dictionary Settings { get; set; } + public List InvocationOverridableSettings { get; set; } public TimeSpan? ArrivalWindow { get; set; } public SignalExpressionPart InputSignalExpression { get; set; } public bool DisallowManualInput { get; set; } @@ -29,5 +33,7 @@ public AppInstanceEntity() [Obsolete("Replaced by InputSignalExpression.")] public List SignalIds { get; set; } + + public List InvocationOverridableSettingDefinitions { get; set; } } } diff --git a/src/Seq.Api/Model/Monitoring/AlertPart.cs b/src/Seq.Api/Model/Monitoring/AlertPart.cs index 36cd15d..6e3b8c0 100644 --- a/src/Seq.Api/Model/Monitoring/AlertPart.cs +++ b/src/Seq.Api/Model/Monitoring/AlertPart.cs @@ -1,10 +1,13 @@ using Seq.Api.Model.LogEvents; using System; +using System.Collections.Generic; namespace Seq.Api.Model.Monitoring { public class AlertPart { + Dictionary _notificationAppSettingOverrides = new Dictionary(); + public string Id { get; set; } public string Condition { get; set; } public TimeSpan MeasurementWindow { get; set; } @@ -12,5 +15,11 @@ public class AlertPart public TimeSpan SuppressionTime { get; set; } public LogEventLevel Level { get; set; } = LogEventLevel.Warning; public string NotificationAppInstanceId { get; set; } + + public Dictionary NotificationAppSettingOverrides + { + get => _notificationAppSettingOverrides; + set => _notificationAppSettingOverrides = value ?? new Dictionary(); + } } } diff --git a/src/Seq.Api/Model/Monitoring/MeasurementDisplayType.cs b/src/Seq.Api/Model/Monitoring/MeasurementDisplayType.cs index 12f5a59..cc7e0d0 100644 --- a/src/Seq.Api/Model/Monitoring/MeasurementDisplayType.cs +++ b/src/Seq.Api/Model/Monitoring/MeasurementDisplayType.cs @@ -5,6 +5,7 @@ public enum MeasurementDisplayType Line, Bar, Point, - Value + Value, + Pie } } diff --git a/src/Seq.Api/Model/Settings/InternalErrorReportingSettingsPart.cs b/src/Seq.Api/Model/Settings/InternalErrorReportingSettingsPart.cs new file mode 100644 index 0000000..deaf7bf --- /dev/null +++ b/src/Seq.Api/Model/Settings/InternalErrorReportingSettingsPart.cs @@ -0,0 +1,8 @@ +namespace Seq.Api.Model.Settings +{ + public class InternalErrorReportingSettingsPart + { + public bool InternalErrorReportingEnabled { get; set; } + public string ReplyEmail { get; set; } + } +} diff --git a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs index ca0c303..fe64248 100644 --- a/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/AppInstancesResourceGroup.cs @@ -31,17 +31,29 @@ public async Task TemplateAsync(string appId) public async Task AddAsync(AppInstanceEntity entity, bool runOnExisting = false) { + if (entity == null) throw new ArgumentNullException(nameof(entity)); return await Client.PostAsync(entity, "Create", entity, new Dictionary { { "runOnExisting", runOnExisting } }).ConfigureAwait(false); } public async Task RemoveAsync(AppInstanceEntity entity) { + if (entity == null) throw new ArgumentNullException(nameof(entity)); await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false); } public async Task UpdateAsync(AppInstanceEntity entity) { + if (entity == null) throw new ArgumentNullException(nameof(entity)); await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false); } + + public async Task InvokeAsync(AppInstanceEntity entity, string eventId, IReadOnlyDictionary settingOverrides) + { + 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}}); + } } -} \ No newline at end of file +} diff --git a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs index c046d9b..08ab59a 100644 --- a/src/Seq.Api/ResourceGroups/DataResourceGroup.cs +++ b/src/Seq.Api/ResourceGroups/DataResourceGroup.cs @@ -22,15 +22,17 @@ internal DataResourceGroup(ISeqConnection connection) /// A signal expression over which the query will be executed. /// 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. /// A structured result set. public async Task QueryAsync( string query, DateTime rangeStartUtc, DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, - SignalEntity unsavedSignal = null) + SignalEntity unsavedSignal = null, + TimeSpan? timeout = null) { - MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, out var body, out var parameters); + MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters); return await GroupPostAsync("Query", body, parameters).ConfigureAwait(false); } @@ -43,15 +45,17 @@ public async Task QueryAsync( /// A signal expression over which the query will be executed. /// 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. /// A CSV result set. public async Task QueryCsvAsync( string query, DateTime rangeStartUtc, DateTime? rangeEndUtc = null, SignalExpressionPart signal = null, - SignalEntity unsavedSignal = null) + SignalEntity unsavedSignal = null, + TimeSpan? timeout = null) { - MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, out var body, out var parameters); + 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); } @@ -62,6 +66,7 @@ static void MakeParameters( DateTime? rangeEndUtc, SignalExpressionPart signal, SignalEntity unsavedSignal, + TimeSpan? timeout, out SignalEntity body, out Dictionary parameters) { @@ -79,6 +84,10 @@ static void MakeParameters( { 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/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index 03a7adc..f28982b 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -34,4 +34,4 @@ - + \ No newline at end of file