private async Task <T> GetObjectPropertiesAsync <T>(int objectId, ObjectType objectType, ObjectProperty mandatoryProperty, CancellationToken token) { var response = await GetObjectPropertiesRawInternalAsync(objectId, objectType, token).ConfigureAwait(false); var data = ResponseParser.GetObjectProperties <T>(response, ObjectEngine.XmlEngine, mandatoryProperty); if (data is TableSettings) { var table = (TableSettings)(object)data; if (table.scheduleStr == null || PrtgObject.GetId(table.scheduleStr) == -1) { table.schedule = new LazyValue <Schedule>(table.scheduleStr, () => new Schedule(table.scheduleStr)); } else { var schedule = await GetScheduleAsync(PrtgObject.GetId(table.scheduleStr), token).ConfigureAwait(false); table.schedule = new LazyValue <Schedule>(table.scheduleStr, () => schedule); } } ValidateTypedProperties(objectId, objectType, data); return(data); }
private T GetObjectProperties <T>(int objectId, ObjectType objectType, ObjectProperty mandatoryProperty) { var response = GetObjectPropertiesRawInternal(objectId, objectType); var data = ResponseParser.GetObjectProperties <T>(response, ObjectEngine.XmlEngine, mandatoryProperty); if (data is TableSettings) { var table = (TableSettings)(object)data; if (table.scheduleStr == null || PrtgObject.GetId(table.scheduleStr) == -1) { table.schedule = new LazyValue <Schedule>(table.scheduleStr, () => new Schedule(table.scheduleStr)); } else { table.schedule = new LazyValue <Schedule>( table.scheduleStr, () => GetSchedule(PrtgObject.GetId(table.scheduleStr)), LazyThreadSafetyMode.PublicationOnly ); } } ValidateTypedProperties(objectId, objectType, data); return(data); }
private async Task UpdateTriggerActionsAsync(List <NotificationTrigger> triggers, CancellationToken token) { var actions = ResponseParser.GroupTriggerActions(triggers); var parameters = new NotificationActionParameters(actions.Select(a => a.Key).ToArray()); var tasks = actions.Select(g => GetNotificationActionPropertiesAsync(g.Key, token)); var normal = await ObjectEngine.GetObjectsXmlAsync(parameters, token : token).ConfigureAwait(false); //All the properties of all desired notifications var results = await Task.WhenAll(tasks).ConfigureAwait(false); //For each different notification action for (int i = 0; i < actions.Count; i++) { var xDoc = RequestParser.ExtractActionXml(normal, results[i], actions[i].Key); //Foreach notification action with the same ID foreach (var action in actions[i]) { action.LazyXml = new Lazy <XDocument>(() => xDoc); } } var list = ResponseParser.GroupActionSchedules(actions.SelectMany(g => g).ToList()).ToList(); List <Schedule> schedules = new List <Schedule>(); if (list.Count > 0) { schedules = await GetSchedulesAsync(Property.Id, list.Select(l => l.Key).ToArray(), token).ConfigureAwait(false); } foreach (var group in actions) { foreach (var action in group) { if (action.lazyScheduleStr != null) { var id = PrtgObject.GetId(action.lazyScheduleStr); if (id != -1) { action.schedule = new Lazy <Schedule>(() => schedules.First(s => s.Id == id)); } else { action.schedule = new Lazy <Schedule>(() => new Schedule(action.lazyScheduleStr)); } } else { action.schedule = new Lazy <Schedule>(() => new Schedule(action.lazyScheduleStr)); } } } }
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); } } }