Beispiel #1
0
        public async Task <Endpoint[]> GetEndpointsAsync(EndpointGetModes loadMode = EndpointGetModes.IncludeEndpointInfoOnly, bool allowCache = true)
        {
            if (loadMode == EndpointGetModes.None)
            {
                return(null);
            }

            if (allowCache && _cachedEndpointsList != null)
            {
                return(_cachedEndpointsList);
            }

            var request = new RestRequest("endpoints", HttpMethod.Get);

            var endpoints = await _httpClient.ExecuteWithPolicyAsync <Endpoint[]>(this, request);

            if (loadMode == EndpointGetModes.IncludeFullAttributes ||
                loadMode == EndpointGetModes.IncludeFullAttributesWithValues)
            {
                var attributes = await GetAttributesFullAsync(allowCache);

                var         attributesWithEndpoint = attributes.Where(a => a.Endpoint != null && a.Endpoint.Uuid != Guid.Empty);
                Attribute[] attributeValues        = null;

                if (loadMode == EndpointGetModes.IncludeFullAttributesWithValues)
                {
                    attributeValues = await GetAttributeValuesAsync();
                }

                foreach (var attribute in attributesWithEndpoint)
                {
                    var endpoint = endpoints.FirstOrDefault(e => e.Uuid.Equals(attribute.Endpoint.Uuid));
                    if (endpoint != null)
                    {
                        if (endpoint.Attributes == null)
                        {
                            endpoint.Attributes = new List <Attribute>();
                        }

                        if (attributeValues != null)
                        {
                            var attributeWithValue =
                                attributeValues.FirstOrDefault(a => a.Uuid.Equals(attribute.Uuid) && a.Value != null);
                            if (attributeWithValue != null)
                            {
                                attribute.Value = attributeWithValue.Value;
                            }
                        }

                        endpoint.Attributes.Add(attribute);
                    }
                }
            }

            if (allowCache)
            {
                _cachedEndpointsList = endpoints;
            }
            return(endpoints);
        }
        public async Task<Endpoint[]> GetEndpointsAsync(EndpointGetModes loadMode = EndpointGetModes.IncludeEndpointInfoOnly, bool allowCache = true)
        {
            if (loadMode == EndpointGetModes.None)
                return null;

            if (allowCache && _cachedEndpointsList != null)
                return _cachedEndpointsList;

            var request = new RestRequest("endpoints", HttpMethod.Get);
            
            var endpoints = await _httpClient.ExecuteWithPolicyAsync<Endpoint[]>(this, request);

            if (loadMode == EndpointGetModes.IncludeFullAttributes ||
                loadMode == EndpointGetModes.IncludeFullAttributesWithValues)
            {
                var attributes = await GetAttributesFullAsync(allowCache);
                var attributesWithEndpoint = attributes.Where(a=>a.Endpoint != null && a.Endpoint.Uuid != Guid.Empty);
                Attribute[] attributeValues = null;

                if (loadMode == EndpointGetModes.IncludeFullAttributesWithValues)
                {
                    attributeValues = await GetAttributeValuesAsync();
                }

                foreach (var attribute in attributesWithEndpoint)
                {
                    var endpoint = endpoints.FirstOrDefault(e => e.Uuid.Equals(attribute.Endpoint.Uuid));
                    if (endpoint != null)
                    {
                        if (endpoint.Attributes == null)
                            endpoint.Attributes = new List<Attribute>();

                        if (attributeValues != null)
                        {
                            var attributeWithValue =
                                attributeValues.FirstOrDefault(a => a.Uuid.Equals(attribute.Uuid) && a.Value != null);
                            if (attributeWithValue != null)
                                attribute.Value = attributeWithValue.Value;
                        }

                        endpoint.Attributes.Add(attribute);
                    }
                }
            }

            if (allowCache)
                _cachedEndpointsList = endpoints;
            return endpoints;
        }