Skip to content

Commit 5cb8c2c

Browse files
authored
Merge pull request #259 from datalust/dev
2022.1 Maintenance Release
2 parents be7a637 + 5604711 commit 5cb8c2c

File tree

8 files changed

+51
-11
lines changed

8 files changed

+51
-11
lines changed

dockerfiles/seqcli/linux-arm64.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# based on: https://github.com/dotnet/dotnet-docker/blob/master/2.0/runtime-deps/jessie/amd64/Dockerfile
22

3-
FROM --platform=linux/arm64 ubuntu:20.04
3+
FROM --platform=linux/arm/v8 ubuntu:20.04
44

55
RUN apt-get update \
66
&& apt-get install -y --no-install-recommends \

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "6.0.301"
3+
"version": "6.0.402"
44
}
55
}

src/SeqCli/Templates/Export/TemplateSetExporter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public async Task ExportTemplateSet()
4343
templateValueMap.MapAsReferenceList<WorkspaceContentPart>(nameof(WorkspaceContentPart.DashboardIds));
4444
templateValueMap.MapAsReferenceList<WorkspaceContentPart>(nameof(WorkspaceContentPart.QueryIds));
4545
templateValueMap.MapAsReferenceList<WorkspaceContentPart>(nameof(WorkspaceContentPart.SignalIds));
46+
templateValueMap.Ignore<AlertEntity>(nameof(AlertEntity.Activity));
4647

4748
await ExportTemplates<SignalEntity>(
4849
id => _connection.Signals.FindAsync(id),

src/SeqCli/Templates/Export/TemplateValueMap.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TemplateValueMap
1414
readonly HashSet<PropertyInfo> _referenceProperties = new();
1515
readonly HashSet<PropertyInfo> _referenceListProperties = new();
1616
readonly Dictionary<PropertyInfo, string> _argProperties = new();
17+
readonly HashSet<PropertyInfo> _ignoredProperties = new();
1718

1819
static PropertyInfo GetProperty<T>(string propertyName) =>
1920
typeof(T).GetProperty(propertyName) ??
@@ -39,6 +40,11 @@ public void AddReferencedTemplate(string entityId, string name)
3940
_idToReferenceName.Add(entityId, name);
4041
}
4142

43+
public void Ignore<T>(string propertyName)
44+
{
45+
_ignoredProperties.Add(GetProperty<T>(propertyName));
46+
}
47+
4248
public bool TryGetRawValue(PropertyInfo pi, object? value, [MaybeNullWhen(false)] out string raw)
4349
{
4450
if (value is string s && _referenceProperties.Contains(pi) &&
@@ -72,6 +78,8 @@ public bool TryGetRawElement(PropertyInfo pi, object? elementValue, [MaybeNullWh
7278
return false;
7379
}
7480

81+
public bool IsIgnored(PropertyInfo pi) => _ignoredProperties.Contains(pi);
82+
7583
static string FormatReference(string name)
7684
{
7785
var jsonStringName = JsonConvert.SerializeObject(name);

src/SeqCli/Templates/Export/TemplateWriter.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ public static async Task WriteTemplateAsync(TextWriter writer, Entity entity, Te
3030
await WriteObjectAsync(jw, entity, templateValueMap, annotateAsResource: true);
3131
}
3232

33-
static async Task WriteValueAsync(JsonWriter jw, object? v, TemplateValueMap templateValueMap)
33+
static async Task WriteValueAsync(JsonWriter jw, object? v, TemplateValueMap templateValueMap, PropertyInfo? enclosingProperty = null)
3434
{
3535
await (v switch
3636
{
3737
null => jw.WriteNullAsync(),
3838
string s => jw.WriteValueAsync(s),
39-
IEnumerable a => WriteArrayAsync(jw, a, templateValueMap),
39+
IReadOnlyDictionary<string, string> ds => WriteDictionaryAsync(jw, ds, templateValueMap, enclosingProperty),
40+
IEnumerable a => WriteArrayAsync(jw, a, templateValueMap, enclosingProperty),
4041
var o when o.GetType().IsClass => WriteObjectAsync(jw, o, templateValueMap),
4142
var e when e.GetType().IsEnum => jw.WriteValueAsync(e.ToString()),
4243
_ => jw.WriteValueAsync(v)
@@ -63,10 +64,31 @@ static async Task WriteArrayAsync(JsonWriter jw, object a, TemplateValueMap temp
6364
await jw.WriteEndArrayAsync();
6465
}
6566

66-
static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap templateValueMap, bool annotateAsResource = false)
67+
static async Task WriteDictionaryAsync(JsonWriter jw, IReadOnlyDictionary<string, string> ds, TemplateValueMap templateValueMap, PropertyInfo? enclosingProperty = null)
6768
{
6869
await jw.WriteStartObjectAsync();
6970

71+
foreach (var (k, v) in ds)
72+
{
73+
await jw.WritePropertyNameAsync(k);
74+
75+
if (enclosingProperty != null &&
76+
templateValueMap.TryGetRawElement(enclosingProperty, v, out var raw))
77+
{
78+
await jw.WriteRawValueAsync(raw);
79+
}
80+
else
81+
{
82+
await WriteValueAsync(jw, v, templateValueMap);
83+
}
84+
}
85+
86+
await jw.WriteEndObjectAsync();
87+
}
88+
89+
static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap templateValueMap, bool annotateAsResource = false)
90+
{
91+
await jw.WriteStartObjectAsync();
7092

7193
if (annotateAsResource)
7294
{
@@ -76,6 +98,9 @@ static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap tem
7698

7799
foreach (var (pi, v) in GetTemplateProperties(o))
78100
{
101+
if (templateValueMap.IsIgnored(pi))
102+
continue;
103+
79104
var pa = pi.GetCustomAttribute<JsonPropertyAttribute>();
80105
if (pa?.DefaultValueHandling == DefaultValueHandling.Ignore &&
81106
v == null || v as int? == 0 || v as decimal? == 0m || v as uint? == 0)
@@ -87,10 +112,8 @@ static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap tem
87112

88113
if (templateValueMap.TryGetRawValue(pi, v, out var raw))
89114
await jw.WriteRawValueAsync(raw);
90-
else if (v is not string && v is IEnumerable)
91-
await WriteArrayAsync(jw, v, templateValueMap, pi);
92115
else
93-
await WriteValueAsync(jw, v, templateValueMap);
116+
await WriteValueAsync(jw, v, templateValueMap, pi);
94117
}
95118

96119
await jw.WriteEndObjectAsync();

src/SeqCli/Templates/Import/TemplateSetImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static class TemplateSetImporter
4141
bool merge)
4242
{
4343
var ordering = new[] {"users", "signals", "apps", "appinstances",
44-
"dashboards", "sqlqueries", "workspaces", "retentionpolicies"}.ToList();
44+
"dashboards", "sqlqueries", "workspaces", "retentionpolicies", "alerts"}.ToList();
4545

4646
var sorted = templates.OrderBy(t => ordering.IndexOf(t.ResourceGroup));
4747

test/SeqCli.Tests/Templates/TemplateWriterTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class TestEntity : Entity
1515
public string Name { get; set; }
1616
public string ReferencedId { get; set; }
1717
public List<int> Numbers { get; set; }
18+
public List<string> Strings { get; set; }
19+
public Dictionary<string, string> Dictionary { get; set; }
1820
}
1921

2022
public class TemplateWriterTests
@@ -27,14 +29,17 @@ public async Task WritesTemplates()
2729
Id = "test-stuff",
2830
Name = "Test Stuff",
2931
ReferencedId = "test-ref",
30-
Numbers = new List<int> { 1, 2, 3 }
32+
Numbers = new List<int> { 1, 2, 3 },
33+
Strings = new List<string> { "test" },
34+
Dictionary = new Dictionary<string, string>{ ["First"] = "a" }
3135
};
3236

3337
const string referencedTemplateName = "Referenced";
3438

3539
var tvm = new TemplateValueMap();
3640
tvm.AddReferencedTemplate(entity.ReferencedId, referencedTemplateName);
3741
tvm.MapAsReference<TestEntity>(nameof(TestEntity.ReferencedId));
42+
tvm.Ignore<TestEntity>(nameof(TestEntity.Strings));
3843

3944
var content = new StringWriter();
4045
await TemplateWriter.WriteTemplateAsync(content, entity, tvm);

test/SeqCli.Tests/Templates/test-Expected.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
1,
77
2,
88
3
9-
]
9+
],
10+
"Dictionary": {
11+
"First": "a"
12+
}
1013
}

0 commit comments

Comments
 (0)