private List <NotificationTrigger> GetNotificationTriggersInternal(Either <IPrtgObject, int> objectOrId, CancellationToken token) { var xmlResponse = ObjectEngine.GetObjectsXml(new NotificationTriggerParameters(objectOrId), token: token); var typed = ResponseParser.ParseNotificationTriggerResponse(objectOrId, xmlResponse); if (!IsEnglish) { var helper = new NotificationTriggerTranslator(typed, objectOrId.GetId()); NotificationTriggerDataTrigger[] raw = null; int parentId; while (helper.TranslateTriggers(raw, out parentId)) { raw = GetNotificationTriggerData(parentId, token).Triggers; } } UpdateTriggerChannels(objectOrId, typed, token); UpdateTriggerActions(typed, token); return(typed); }
private List <NotificationTrigger> GetNotificationTriggersInternal(int objectId, CancellationToken token) { var xmlResponse = ObjectEngine.GetObjectsXml(new NotificationTriggerParameters(objectId), token: token); var parsed = ResponseParser.ParseNotificationTriggerResponse(objectId, xmlResponse); UpdateTriggerChannels(parsed, token); UpdateTriggerActions(parsed, token); return(parsed); }
private string GetObjectPropertyRawInternal(GetObjectPropertyRawParameters parameters, string property) { var response = ObjectEngine.GetObjectsXml( parameters, responseParser: m => ResponseParser.ParseGetObjectPropertyResponse( m.Content.ReadAsStringAsync().Result, property ) ); return(ResponseParser.ValidateRawObjectProperty(response, parameters)); }
private void UpdateTriggerActions(List <NotificationTrigger> triggers, CancellationToken token) { //Group all actions from all triggers together based on their object ID var actions = ResponseParser.GroupTriggerActions(triggers); //Retrieve the XML required to construct "proper" notification actions for all unique actions //specified in the triggers var actionParameters = new NotificationActionParameters(actions.Select(a => a.Key).ToArray()); var normalActions = new Lazy <XDocument>(() => ObjectEngine.GetObjectsXml(actionParameters, token: token), LazyThreadSafetyMode.PublicationOnly); foreach (var group in actions) { //As soon as a notification with a specified ID is accessed on any one of the triggers, retrieve //the "supported" properties of ALL of the notification actions, and then retrieve the "unsupported" //properties of JUST the notification action object ID that was accessed. var lazyAction = new Lazy <XDocument>( () => RequestParser.ExtractActionXml(normalActions.Value, GetNotificationActionProperties(group.Key, token), @group.Key), LazyThreadSafetyMode.PublicationOnly ); Logger.Log("Setting lazy action to retrieve notification actions"); foreach (var action in group) { action.LazyXml = lazyAction; Logger.Log("Setting lazy action to retrieve notification schedule"); action.schedule = new Lazy <Schedule>( () => { if (action.lazyScheduleStr != null && PrtgObject.GetId(action.lazyScheduleStr) != -1) { Logger.Log($"Resolving schedule {action.lazyScheduleStr} to schedule"); return(GetSchedule(new Schedule(action.lazyScheduleStr).Id, token)); } return(action.lazyScheduleStr == null ? null : new Schedule(action.lazyScheduleStr)); }, LazyThreadSafetyMode.PublicationOnly); } } }