Esempio n. 1
0
 private static string ExportSamplingLocation(SamplingLocation location, Sending sending)
 {
     if (location == SamplingLocation.Other)
     {
         return(sending.OtherSamplingLocation);
     }
     return(ExportToString(location));
 }
Esempio n. 2
0
        public void DataTable_ContainsSamplingLocation(SamplingLocation location, string expectedValue)
        {
            var sut = CreateExportDefinition();

            Sending.SamplingLocation = location;

            var export = sut.ToDataTable(Sendings);

            export.Rows[0]["source"].Should().Be(expectedValue);
        }
Esempio n. 3
0
        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);
        }