Example #1
0
        private async Task <List <NotificationTrigger> > GetNotificationTriggersInternalAsync(Either <IPrtgObject, int> objectOrId, CancellationToken token)
        {
            var xmlResponse = await ObjectEngine.GetObjectsXmlAsync(new NotificationTriggerParameters(objectOrId), token : token).ConfigureAwait(false);

            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 = (await GetNotificationTriggerDataAsync(parentId, token).ConfigureAwait(false)).Triggers;
                }
            }

            var updateTriggerChannels = UpdateTriggerChannelsAsync(objectOrId, typed, token);
            var updateTriggerActions  = UpdateTriggerActionsAsync(typed, token);

            await Task.WhenAll(updateTriggerChannels, updateTriggerActions).ConfigureAwait(false);

            return(typed);
        }
Example #2
0
        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));
                    }
                }
            }
        }
Example #3
0
        private async Task <string> GetObjectPropertyRawInternalAsync(GetObjectPropertyRawParameters parameters, string property, CancellationToken token)
        {
            var response = await ObjectEngine.GetObjectsXmlAsync(
                parameters,
                responseParser : async m => ResponseParser.ParseGetObjectPropertyResponse(
                    await m.Content.ReadAsStringAsync().ConfigureAwait(false),
                    property
                    ),
                token : token
                ).ConfigureAwait(false);

            return(ResponseParser.ValidateRawObjectProperty(response, parameters));
        }
Example #4
0
        private async Task <List <NotificationTrigger> > GetNotificationTriggersInternalAsync(int objectId, CancellationToken token)
        {
            var xmlResponse = await ObjectEngine.GetObjectsXmlAsync(new NotificationTriggerParameters(objectId), token : token).ConfigureAwait(false);

            var parsed = ResponseParser.ParseNotificationTriggerResponse(objectId, xmlResponse);

            var updateTriggerChannels = UpdateTriggerChannelsAsync(parsed, token);
            var updateTriggerActions  = UpdateTriggerActionsAsync(parsed, token);

            await Task.WhenAll(updateTriggerChannels, updateTriggerActions).ConfigureAwait(false);

            return(parsed);
        }