private void LoadExchangeConfiguration() { var exchangeConfiguration = Samples .Get(new GetExchangeConfigurations()) .DomainObjects .FirstOrDefault(e => e.Type == "AQUARIUS_TIMESERIES"); if (exchangeConfiguration == null) { return; } TimeSeriesLocationAliases.Clear(); foreach (var mapping in exchangeConfiguration.SamplingLocationMappings) { if (mapping.SamplingLocation.CustomId.Equals(mapping.ExternalLocation, StringComparison.InvariantCultureIgnoreCase)) { break; } TimeSeriesLocationAliases.Add(mapping.SamplingLocation.CustomId, mapping.ExternalLocation); } }
private void ExportLocation(SamplingLocation location) { if (!TimeSeriesLocationAliases.TryGetValue(location.CustomId, out var aqtsLocationIdentifier)) { aqtsLocationIdentifier = location.CustomId; } var locationDescriptions = TimeSeries.Publish.Get(new LocationDescriptionListServiceRequest { LocationIdentifier = aqtsLocationIdentifier }) .LocationDescriptions; if (!locationDescriptions.Any()) { Log.Warn($"AQTS Location '{aqtsLocationIdentifier}' does not exist. Skipping this location's export."); ++SkippedLocations; return; } if (locationDescriptions.Count != 1) { throw new ExpectedException( $"'{aqtsLocationIdentifier}' is an ambiguous AQTS location identifier for {locationDescriptions.Count} locations: '{string.Join("', '", locationDescriptions.Select(l => l.Identifier))}'"); } var locationDescription = locationDescriptions.Single(); var locationData = TimeSeries.Publish.Get(new LocationDataServiceRequest { LocationIdentifier = locationDescription.Identifier, IncludeLocationAttachments = true }); var attachmentFilename = GetAttachmentFilename(locationDescription.Identifier); var existingAttachments = locationData .Attachments .Where(a => a.FileName.Equals(attachmentFilename, StringComparison.InvariantCultureIgnoreCase)) .ToList(); foreach (var existingAttachment in existingAttachments) { DeleteExistingAttachment(locationData, existingAttachment); } var exportRequest = new GetExportObservations { EndObservedTime = FromDateTimeOffset(Context.EndTime), StartObservedTime = FromDateTimeOffset(Context.StartTime), SamplingLocationIds = new List <string> { location.Id }, ObservedPropertyIds = ObservedPropertyIds, AnalyticalGroupIds = AnalyticalGroupIds, }; var exportedObservationCount = Samples.Get(new GetObservationsV2 { EndObservedTime = exportRequest.EndObservedTime, StartObservedTime = exportRequest.StartObservedTime, SamplingLocationIds = exportRequest.SamplingLocationIds, ObservedPropertyIds = exportRequest.ObservedPropertyIds, AnalyticalGroupIds = exportRequest.AnalyticalGroupIds }).TotalCount; LogAction($"Exporting {"observation".ToQuantity(exportedObservationCount)} from '{location.CustomId}' ..."); ++ExportedLocations; ExportedObservations += exportedObservationCount; // Need to hack the URL until WI-4928 is fixed var url = $"{(Samples.Client as JsonServiceClient)?.BaseUri}{exportRequest.ToGetUrl()}&observationTemplateAttachmentId={ExportTemplate.Attachments.Single().Id}&format=xlsx"; if (Context.DryRun) { return; } var contentBytes = ExportObservationsFromTemplate(url); Log.Info($"Uploading '{attachmentFilename}' ({contentBytes.Length.Bytes().Humanize("#.#")}) to '{locationData.Identifier}' ..."); UploadLocationAttachment(locationData.UniqueId, contentBytes, attachmentFilename); }