Esempio n. 1
0
        /// <summary>
        /// Asynchronously calcualte the total number of objects of a given type present on a PRTG Server.
        /// </summary>
        /// <param name="content">The type of object to total.</param>
        /// <returns>The total number of objects of a given type.</returns>
        public async Task <int> GetTotalObjectsAsync(Content content)
        {
            var parameters = new Parameters.Parameters()
            {
                [Parameter.Count]   = 0,
                [Parameter.Content] = content
            };

            return(Convert.ToInt32((await GetObjectsRawAsync <PrtgObject>(parameters).ConfigureAwait(false)).TotalCount));
        }
Esempio n. 2
0
        private async Task AddObjectWithExcessiveValueAsync(List <KeyValuePair <Parameter, object> > lengthLimit, Parameters.Parameters internalParams, CommandFunction function)
        {
            var limitParam = lengthLimit.First();

            var limit = limitParam.Key.GetEnumAttribute <LengthLimitAttribute>().Length;

            if (limitParam.Value is IEnumerable)
            {
                var list = ((IEnumerable)limitParam.Value).Cast <object>().ToList();

                var count = list.Count();

                if (count > limit)
                {
                    for (int i = 0; i < count; i += limit)
                    {
                        var thisRequest = list.Skip(i).Take(limit);

                        internalParams[limitParam.Key] = thisRequest;

                        await requestEngine.ExecuteRequestAsync(function, internalParams).ConfigureAwait(false);
                    }
                }
                else
                {
                    await requestEngine.ExecuteRequestAsync(function, internalParams).ConfigureAwait(false);
                }
            }
            else
            {
                throw new NotImplementedException($"Don't know how to handle {nameof(LengthLimitAttribute)} applied to value of type {limitParam.Value.GetType()}");
            }
        }
Esempio n. 3
0
        private Data <T> GetObjectsRaw <T>(Parameters.Parameters parameters)
        {
            var response = requestEngine.ExecuteRequest(XmlFunction.TableData, parameters);

            return(Data <T> .DeserializeList(response));
        }
Esempio n. 4
0
        private async Task <Data <T> > GetObjectsRawAsync <T>(Parameters.Parameters parameters)
        {
            var response = await requestEngine.ExecuteRequestAsync(XmlFunction.TableData, parameters).ConfigureAwait(false);

            return(Data <T> .DeserializeList(response));
        }
Esempio n. 5
0
 private async Task <List <T> > GetObjectsAsync <T>(Parameters.Parameters parameters)
 {
     return((await GetObjectsRawAsync <T>(parameters).ConfigureAwait(false)).Items);
 }