Пример #1
0
        private List <TimeSeriesDescription> FetchChangedTimeSeriesDescriptions(TimeSeriesUniqueIdListServiceResponse response)
        {
            var timeSeriesUniqueIdsToFetch = response.TimeSeriesUniqueIds
                                             .Where(ts => !(ts.IsDeleted ?? false))
                                             .Select(ts => ts.UniqueId)
                                             .ToList();

            Log.Info($"Fetching descriptions of {timeSeriesUniqueIdsToFetch.Count} changed time-series ...");

            var timeSeriesDescriptions = new List <TimeSeriesDescription>();

            using (var batchClient = CreatePublishClientWithPostMethodOverride())
            {
                while (timeSeriesUniqueIdsToFetch.Any())
                {
                    const int batchSize = 400;

                    var batchList = timeSeriesUniqueIdsToFetch.Take(batchSize).ToList();
                    timeSeriesUniqueIdsToFetch = timeSeriesUniqueIdsToFetch.Skip(batchSize).ToList();

                    var request = new TimeSeriesDescriptionListByUniqueIdServiceRequest();

                    // We need to resolve the URL without any unique IDs on the GET command line
                    var requestUrl = RemoveQueryFromUrl(request.ToGetUrl());

                    request.TimeSeriesUniqueIds = batchList;

                    var batchResponse =
                        batchClient.Send <TimeSeriesDescriptionListByUniqueIdServiceResponse>(HttpMethods.Post,
                                                                                              requestUrl, request);

                    timeSeriesDescriptions.AddRange(batchResponse.TimeSeriesDescriptions);
                }
            }

            return(timeSeriesDescriptions
                   .OrderBy(ts => ts.LocationIdentifier)
                   .ThenBy(ts => ts.Identifier)
                   .ToList());
        }
Пример #2
0
        private void FetchAllUnknownSeriesDescriptions(IEnumerable <Guid> uniqueIds)
        {
            var unknownTimeSeriesUniqueIds = uniqueIds
                                             .Where(id => !_knownTimeSeries.ContainsKey(id))
                                             .ToList();

            // A regular `GET /Publish/v2/GetTimeSeriesDescriptionListByUniqueId` request is limited by the IIS max query string length of 2048 bytes.
            // That means about 61 unique IDs per request before IIS refuses the request.
            // Instead, we use a ServiceStack override method that allows use to send the request parameters as a JSON payload.
            // This allows us to request up to 400 time-series per request, the maximum allowed by the API.
            using (var batchClient = CreatePublishClientWithPostMethodOverride())
            {
                while (unknownTimeSeriesUniqueIds.Any())
                {
                    const int batchSize = 400;

                    var batchList = unknownTimeSeriesUniqueIds.Take(batchSize).ToList();
                    unknownTimeSeriesUniqueIds = unknownTimeSeriesUniqueIds.Skip(batchSize).ToList();

                    var request = new TimeSeriesDescriptionListByUniqueIdServiceRequest();

                    // We need to resolve the URL without any unique IDs on the GET command line
                    var requestUrl = RemoveQueryFromUrl(request.ToGetUrl());

                    request.TimeSeriesUniqueIds = batchList;

                    var batchResponse =
                        batchClient.Send <TimeSeriesDescriptionListByUniqueIdServiceResponse>(HttpMethods.Post, requestUrl, request);

                    foreach (var timeSeriesDescription in batchResponse.TimeSeriesDescriptions)
                    {
                        _knownTimeSeries.Add(timeSeriesDescription.UniqueId, timeSeriesDescription);
                    }
                }
            }
        }