public IActionResult TriggerTest([FromBody] TriggerParameters parameters) { return(Ok()); }
internal static List <NotificationTrigger> ExceptTrigger(List <NotificationTrigger> before, List <NotificationTrigger> after, TriggerParameters parameters) { return(after.Where(a => !before.Any(b => a.ObjectId == b.ObjectId && a.SubId == b.SubId) && a.OnNotificationAction.Id == parameters.OnNotificationAction.Id).ToList()); }
private void SetNotificationTriggerInternal(TriggerParameters parameters, CancellationToken token) { ValidateTriggerParameters(parameters, token); RequestEngine.ExecuteRequest(parameters, token: token); }
private async Task SetNotificationTriggerInternalAsync(TriggerParameters parameters, CancellationToken token) { await ValidateTriggerParametersAsync(parameters, token).ConfigureAwait(false); await RequestEngine.ExecuteRequestAsync(parameters, token : token).ConfigureAwait(false); }
private TriggerParameters CreateDynamicParameters() { UpdateDynamicParameters(); return(TriggerParameters.Create(Type, Object.Id, dynamicParameters)); }
internal async Task <List <NotificationTrigger> > AddNotificationTriggerInternalAsync(TriggerParameters parameters, bool resolve, Action <Type, int> errorCallback = null, Func <bool> shouldStop = null) { if (resolve) { Func <Task> addTrigger = async() => await SetNotificationTriggerAsync(parameters).ConfigureAwait(false); Func <Task <List <NotificationTrigger> > > getTrigger = async() => (await GetNotificationTriggersAsync(parameters.ObjectId).ConfigureAwait(false)).Where(t => !t.Inherited).ToList(); var objs = await ResolveWithDiffAsync(addTrigger, getTrigger, (b, a) => ResponseParser.ExceptTrigger(b, a, parameters), errorCallback, shouldStop).ConfigureAwait(false); return(objs); } else { SetNotificationTrigger(parameters); return(null); } }
private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters) { foreach (var paramProp in parameters.GetType().GetProperties2()) { bool found = false; foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") || (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") || (paramProp.Name == triggerProp.Name)) { found = true; Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null"); } } if (!found) { Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'"); } } }
private void ValidateNewTrigger(TriggerParameters parameters, NotificationTrigger trigger, bool empty, Func <object, object, string, bool> validator = null) { if (validator == null) { validator = (o, t, n) => false; } foreach (var paramProp in parameters.GetType().GetNormalProperties()) { bool found = false; foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") || (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") || (paramProp.Name == triggerProp.Name)) { found = true; var paramValue = paramProp.GetValue(parameters)?.ToString(); var triggerValue = triggerProp.GetValue(trigger)?.ToString(); if (empty && paramValue == null) { switch (triggerProp.Name) { case nameof(NotificationTrigger.Latency): paramValue = "60"; break; case nameof(NotificationTrigger.EscalationLatency): paramValue = "300"; break; case nameof(NotificationTrigger.DisplayThreshold): paramValue = "0"; break; case nameof(NotificationTrigger.RepeatInterval): paramValue = "0"; break; } } if (!validator(paramProp.GetValue(parameters), triggerProp.GetValue(trigger), triggerProp.Name)) { AssertEx.AreEqual(paramValue, triggerValue, triggerProp.Name); } //when we create a trigger without customization, some fields get default values //we should have verification of those values, but ONLY when we're doing //verification without customization. maybe we should have a bool on validatenewtrigger //that indicates whether this is without customization, and ONLY THEN do we say ok //paramValue can be null but triggerValue can be <something> } } if (!found) { AssertEx.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'"); } } }
private void TriggerParameters_Create_FromExistingTrigger(NotificationTrigger trigger, TriggerParameters parameters) { //shouldnt we _actually_ be checking that the values are the same? //and, shouldnt we be populating _all_ properties of the trigger first? //then, we need to make sure we can clone a trigger into some new parameters and add them successfully //and THEN, we need to write some tests for that foreach (var paramProp in PrtgAPIHelpers.GetNormalProperties(parameters.GetType())) { bool found = false; foreach (var triggerProp in trigger.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if ((paramProp.Name == "TriggerInternal" && triggerProp.Name == "Trigger") || (paramProp.Name == "State" && triggerProp.Name == "StateTrigger") || (paramProp.Name == triggerProp.Name)) { found = true; Assert.IsTrue(paramProp.GetValue(parameters) != null, $"Parameter '{paramProp}' was null"); } } if (!found) { Assert.Fail($"Couldn't find notification trigger property that corresponded to parameter property '{paramProp.Name}'"); } } }
public abstract void Run(IBaseDatabaseService db, TriggerParameters e);
public static void ProcessRecordEx(PrtgOperationCmdlet cmdlet, Action <Action, string> executeOperation, TriggerParameters parameters, Action executeAndResolve = null, string whatIfAction = null, string whatIfTarget = null) { if (whatIfAction == null) { whatIfAction = cmdlet.MyInvocation.MyCommand.Name; } if (whatIfTarget == null) { whatIfTarget = $"Object ID: {parameters.ObjectId} (Type: {parameters.Type}, Action: {parameters.OnNotificationAction})"; } if (cmdlet.ShouldProcess(whatIfTarget, whatIfAction)) { if (cmdlet is AddNotificationTrigger) { executeOperation(() => { if (executeAndResolve == null) { PrtgSessionState.Client.AddNotificationTrigger(parameters, false); } else { executeAndResolve(); } }, $"Adding notification trigger '{parameters.OnNotificationAction?.Name ?? "None"}' to object ID {parameters.ObjectId}"); } else { executeOperation(() => PrtgSessionState.Client.SetNotificationTrigger(parameters), $"Updating notification trigger with ID {parameters.ObjectId} (Sub ID: {parameters.SubId})"); } } }