Skip to content

Commit 1910a54

Browse files
committed
Ignore alert activity when exporting templates
1 parent 4d3de24 commit 1910a54

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ static async Task WriteObjectAsync(JsonWriter jw, object o, TemplateValueMap tem
7676

7777
foreach (var (pi, v) in GetTemplateProperties(o))
7878
{
79+
if (templateValueMap.IsIgnored(pi))
80+
continue;
81+
7982
var pa = pi.GetCustomAttribute<JsonPropertyAttribute>();
8083
if (pa?.DefaultValueHandling == DefaultValueHandling.Ignore &&
8184
v == null || v as int? == 0 || v as decimal? == 0m || v as uint? == 0)

test/SeqCli.Tests/Templates/TemplateWriterTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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; }
1819
}
1920

2021
public class TemplateWriterTests
@@ -27,14 +28,16 @@ public async Task WritesTemplates()
2728
Id = "test-stuff",
2829
Name = "Test Stuff",
2930
ReferencedId = "test-ref",
30-
Numbers = new List<int> { 1, 2, 3 }
31+
Numbers = new List<int> { 1, 2, 3 },
32+
Strings = new List<string> { "test" }
3133
};
3234

3335
const string referencedTemplateName = "Referenced";
3436

3537
var tvm = new TemplateValueMap();
3638
tvm.AddReferencedTemplate(entity.ReferencedId, referencedTemplateName);
3739
tvm.MapAsReference<TestEntity>(nameof(TestEntity.ReferencedId));
40+
tvm.Ignore<TestEntity>(nameof(TestEntity.Strings));
3841

3942
var content = new StringWriter();
4043
await TemplateWriter.WriteTemplateAsync(content, entity, tvm);

0 commit comments

Comments
 (0)