/// <summary>
        /// Reads raw historical data
        /// </summary>
        /// <param name="items">List of Identity instances to read.</param>
        private static async Task ReadRawHistoricalData(List <Identity> items)
        {
            LogResult();

            DateTime startTime = _startTime;
            DateTime endTime   = startTime.AddMilliseconds(_numberOfSamples * _intervalInMilliseconds);

            RawHistoricalDataResponse readRawHistoricalDataResponse = await _client.ReadRawHistoricalDataAsync(items, startTime, endTime);

            if (readRawHistoricalDataResponse.Error != null)
            {
                Console.WriteLine(string.Format("An error has occurred : {0}", readRawHistoricalDataResponse.Error?.First().Message));
            }
            else if (readRawHistoricalDataResponse.Data != null)
            {
                // In this case we got raw historical data
                // Iterate through the result by using iterators (which make use of lazy loading) and output the itemValues.
                RawHistoricalData rawHistoricalData = readRawHistoricalDataResponse.Data;
                foreach (RawHistoricalDataQueryData queryData in rawHistoricalData.QueryDataIterator())
                {
                    foreach (RawHistoricalDataItemData item in queryData.ItemsIterator())
                    {
                        foreach (RawHistoricalDataItemValue itemValue in item.ItemValueIterator())
                        {
                            Console.WriteLine("ItemValue: {0}", itemValue);
                        }
                    }
                }
            }
            else if (readRawHistoricalDataResponse.Strategy != null)
            {
                // In case the size of the data exceeds the 'query_count_limit' a query strategy is returned to fetch the
                // historical data in multiple chunks.
                Console.WriteLine("A strategy is returned by the server, which will be described in an other example.");
            }

            Console.WriteLine();
        }
        /// <summary>
        /// Reads raw historical data and calculates a custom duration.
        /// </summary>
        /// <param name="items">List of Identity instances to read.</param>
        private static void ReadRawHistoricalData_MatchDuration(List <Identity> items)
        {
            Console.WriteLine("Result of {0}:", MethodBase.GetCurrentMethod().Name);

            DateTime startTime = _startTime;
            DateTime endTime   = startTime.AddMilliseconds(_numberOfSamples * _intervalInMilliseconds - 2);

            // Create an instance of a 'RawHistoryContext'.
            RawHistoryContext rawHistoryContext = new RawHistoryContext();

            string pathSecondItem = items.Skip(1).First().Path;

            long leadingBoundingTimespan           = _intervalInMilliseconds * 100;
            long trailingBoundingTimespan          = _intervalInMilliseconds * 100;
            long leadingBoundingNumberOfIntervals  = 10;
            long trailingBoundingNumberOfIntervals = 10;

            // Define a LINQ 'where' query and call the (extension) method 'AddMatchDuration'. This method requires the using 'inmation.api.history;'.
            rawHistoryContext.Where(
                n => (n.ValueAsDouble > 10)).AddMatchDuration("CustomDuration01", leadingBoundingTimespan, trailingBoundingTimespan, leadingBoundingNumberOfIntervals, trailingBoundingNumberOfIntervals);

            // Define the options
            ReadRawHistoricalDataOptions options = new ReadRawHistoricalDataOptions();

            options.Bounds = false;
            options.Fields = new List <string>()
            {
                "ALL"
            };

            // Fetch historical data by using the 'ReadRawHistoricalData' method of the RawHistoryContext class.
            // The filter will be applied on the raw historical data retrieved for the items within the provided interval.
            Task <RawHistoricalDataResponse> readRawHistoricalDataTask = rawHistoryContext.ReadRawHistoricalData(_client, items, startTime, endTime, options);

            readRawHistoricalDataTask.Wait();
            RawHistoricalDataResponse readRawHistoricalDataResponse = readRawHistoricalDataTask.Result;

            if (readRawHistoricalDataResponse.Error != null)
            {
                Console.WriteLine(string.Format("An error has occurred : {0}", readRawHistoricalDataResponse.Error?.First().Message));
            }
            else if (readRawHistoricalDataResponse.Data != null)
            {
                // In this case we got raw historical data
                // Iterate through the result by using iterators (which make use of lazy loading) and output the itemValues.
                RawHistoricalData rawHistoricalData = readRawHistoricalDataResponse.Data;
                foreach (RawHistoricalDataQueryData queryData in rawHistoricalData.QueryDataIterator())
                {
                    foreach (RawHistoricalDataItemData item in queryData.ItemsIterator())
                    {
                        foreach (RawHistoricalDataItemValue itemValue in item.ItemValueIterator())
                        {
                            Console.WriteLine("ItemValue: {0}", itemValue);
                        }
                    }
                }

                // Calculate the total duration for item with path <pathSecondItem>.
                long?totalDuration = rawHistoricalData.QueryData.Sum(n => n.Items.Where(i => i.Path.Equals(pathSecondItem)).Sum(o => o.SummarizeDuration()));
                Console.WriteLine("\nTotal duration for Item '{0}': {1}", pathSecondItem, totalDuration);
            }
            else if (readRawHistoricalDataResponse.Strategy != null)
            {
                // In case the size of the data exceeds the 'query_count_limit' a query strategy is returned to fetch the
                // historical data in multiple chunks.
                Console.WriteLine("A strategy is returned by the server, which will be described in an other example.");
            }

            Console.WriteLine();
        }