/// <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)); }
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()}"); } }
private Data <T> GetObjectsRaw <T>(Parameters.Parameters parameters) { var response = requestEngine.ExecuteRequest(XmlFunction.TableData, parameters); return(Data <T> .DeserializeList(response)); }
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)); }
private async Task <List <T> > GetObjectsAsync <T>(Parameters.Parameters parameters) { return((await GetObjectsRawAsync <T>(parameters).ConfigureAwait(false)).Items); }