Skip to content

Commit a4886ec

Browse files
author
Doug Schmidt
authored
Merge pull request #304 from DougSchmidt-AI/feature/PF-1421-FixObservationReportExporter
PF-1421 - ObservationReportExporter now works with AQTS 2021.2
2 parents 52e50c2 + 323510a commit a4886ec

File tree

3 files changed

+110
-4
lines changed

3 files changed

+110
-4
lines changed

Samples/DotNetSdk/ObservationReportExporter/Exporter.cs

+58-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using ApplyTagRequest = Aquarius.TimeSeries.Client.ServiceModels.Acquisition.ApplyTagRequest;
2323
using Attachment = Aquarius.TimeSeries.Client.ServiceModels.Publish.Attachment;
2424
using GetTags = Aquarius.TimeSeries.Client.ServiceModels.Provisioning.GetTags;
25+
using TagValueType = Aquarius.TimeSeries.Client.ServiceModels.Provisioning.TagValueType;
2526

2627
namespace ObservationReportExporter
2728
{
@@ -329,10 +330,7 @@ private void ValidateTimeSeriesConfiguration()
329330
if (!Context.AttachmentTags.Any())
330331
return;
331332

332-
var locationTags = TimeSeries
333-
.Provisioning
334-
.Get(new GetTags())
335-
.Results
333+
var locationTags = GetConfiguredTags()
336334
.Where(t => t.AppliesToAttachments)
337335
.ToDictionary(t => t.Key, t => t, StringComparer.InvariantCultureIgnoreCase);
338336

@@ -351,6 +349,62 @@ private void ValidateTimeSeriesConfiguration()
351349
}
352350
}
353351

352+
private List<Tag> GetConfiguredTags()
353+
{
354+
if (TimeSeries.ServerVersion.IsLessThan(MinimumUnifiedTagsAndExtendedAttributesVersion))
355+
{
356+
return TimeSeries
357+
.Provisioning
358+
.Get(new GetHackTags())
359+
.Results
360+
.Select(Convert)
361+
.ToList();
362+
}
363+
364+
return TimeSeries
365+
.Provisioning
366+
.Get(new GetTags())
367+
.Results;
368+
}
369+
370+
private static readonly AquariusServerVersion MinimumUnifiedTagsAndExtendedAttributesVersion = AquariusServerVersion.Create("21.3");
371+
372+
private static Tag Convert(HackTag hackValue)
373+
{
374+
return new Tag
375+
{
376+
Key = hackValue.Key,
377+
UniqueId = hackValue.UniqueId,
378+
AppliesToAttachments = hackValue.AppliesToAttachments,
379+
AppliesToLocationNotes = hackValue.AppliesToLocationNotes,
380+
AppliesToLocations = hackValue.AppliesToLocations,
381+
AppliesToReports = hackValue.AppliesToReports,
382+
AppliesToSensorsGauges = hackValue.AppliesToSensorsGauges,
383+
PickListValues = hackValue.PickListValues,
384+
ValueType = Convert(hackValue.ValueType),
385+
};
386+
}
387+
388+
private static TagValueType? Convert(HackTagValueType? hackValue)
389+
{
390+
if (!hackValue.HasValue || !SupportedTypes.TryGetValue(hackValue.Value, out var tagValue))
391+
return null;
392+
393+
return tagValue;
394+
}
395+
396+
private static readonly Dictionary<HackTagValueType, TagValueType> SupportedTypes =
397+
new Dictionary<HackTagValueType, TagValueType>
398+
{
399+
{ HackTagValueType.Unknown, TagValueType.Unknown },
400+
{ HackTagValueType.None, TagValueType.None },
401+
{ HackTagValueType.PickList, TagValueType.PickList },
402+
{ HackTagValueType.Text, TagValueType.String }, // This is reason for all this fudge code
403+
{ HackTagValueType.Number, TagValueType.Number },
404+
{ HackTagValueType.Boolean, TagValueType.Boolean },
405+
{ HackTagValueType.DateTime, TagValueType.DateTime }
406+
};
407+
354408
private void ExportAllLocations()
355409
{
356410
var exportedLocations = GetExportedLocations()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using ServiceStack;
4+
5+
namespace ObservationReportExporter.ExtraApis.TimeSeries
6+
{
7+
public enum HackTagValueType
8+
{
9+
Unknown,
10+
None,
11+
PickList,
12+
Text, // This changed from "Text" (before 2021.3) to "String" in 2021.3, breaking a bunch of serializations. Yuck.
13+
Number,
14+
Boolean,
15+
DateTime,
16+
}
17+
18+
[Route("/tags", HttpMethods.Get)]
19+
public class GetHackTags
20+
: IReturn<HackTagsResponse>
21+
{
22+
}
23+
24+
public class HackTagsResponse
25+
{
26+
public HackTagsResponse()
27+
{
28+
Results = new List<HackTag>();
29+
}
30+
31+
public List<HackTag> Results { get; set; }
32+
}
33+
34+
public class HackTag
35+
{
36+
public HackTag()
37+
{
38+
PickListValues = new List<string>();
39+
}
40+
41+
public Guid UniqueId { get; set; }
42+
public string Key { get; set; }
43+
public HackTagValueType? ValueType { get; set; } // This is why all the hacked Tag DTOs are required
44+
public List<string> PickListValues { get; set; }
45+
public bool AppliesToAttachments { get; set; }
46+
public bool AppliesToLocations { get; set; }
47+
public bool AppliesToLocationNotes { get; set; }
48+
public bool AppliesToReports { get; set; }
49+
public bool AppliesToSensorsGauges { get; set; }
50+
}
51+
}

Samples/DotNetSdk/ObservationReportExporter/ObservationReportExporter.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@
239239
</ItemGroup>
240240
<ItemGroup>
241241
<Compile Include="ExtraApis\TimeSeries\DeleteAttachmentById.cs" />
242+
<Compile Include="ExtraApis\TimeSeries\HackTags.cs" />
242243
<Compile Include="FilenameGenerator.cs" />
243244
<Compile Include="Context.cs" />
244245
<Compile Include="ExeHelper.cs" />

0 commit comments

Comments
 (0)