From 414f71706aad6b7ba7d090836b15cb931969a19b Mon Sep 17 00:00:00 2001 From: PointStar Date: Mon, 11 May 2026 18:57:13 +0300 Subject: [PATCH] fix: restore PNG embed entries + handle numeric Case.number from EspoCRM Two issues surfaced from the addin log: 1) The four Klear ribbon PNGs were not in the assembly manifest (Available resources listed only the XMLs and Properties.Resources). The EmbeddedResource entries for Images got dropped from OutlookAddin.csproj during a previous rebase. Re-add them in the same spot they had before. 2) MatchingService failed for one of the contacts with: System.Text.Json.JsonException at $.list[0].number Cannot get the value of a token type Number as a string. EspoCRM emits Case.number as a JSON number on installs that use auto-increment, and as a string when a custom case-code format is configured. Add a small FlexibleStringConverter that reads either token type into the same string field, and attach it to CaseEntity.Number. Tests: 39 passing. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../Json/FlexibleStringConverter.cs | 46 +++++++++++++++++++ src/OutlookAddin.Core/Models/CaseEntity.cs | 5 ++ src/OutlookAddin/OutlookAddin.csproj | 16 ++++++- 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/OutlookAddin.Core/Json/FlexibleStringConverter.cs diff --git a/src/OutlookAddin.Core/Json/FlexibleStringConverter.cs b/src/OutlookAddin.Core/Json/FlexibleStringConverter.cs new file mode 100644 index 0000000..9428007 --- /dev/null +++ b/src/OutlookAddin.Core/Json/FlexibleStringConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MarcusLaw.OutlookAddin.Core.Json +{ + /// + /// Reads a JSON value as when the source might be + /// either a string OR a number (or null). EspoCRM exposes fields such + /// as Case.number sometimes as JSON numbers (auto-increment) and + /// sometimes as JSON strings (custom case codes) depending on field + /// configuration; with a plain string? property the deserializer + /// would throw on the numeric form. + /// + public sealed class FlexibleStringConverter : JsonConverter + { + public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + switch (reader.TokenType) + { + case JsonTokenType.Null: + return null; + case JsonTokenType.String: + return reader.GetString(); + case JsonTokenType.Number: + if (reader.TryGetInt64(out var l)) return l.ToString(CultureInfo.InvariantCulture); + if (reader.TryGetDouble(out var d)) return d.ToString("R", CultureInfo.InvariantCulture); + return reader.GetDecimal().ToString(CultureInfo.InvariantCulture); + case JsonTokenType.True: + return "true"; + case JsonTokenType.False: + return "false"; + default: + reader.Skip(); + return null; + } + } + + public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) + { + if (value == null) writer.WriteNullValue(); + else writer.WriteStringValue(value); + } + } +} diff --git a/src/OutlookAddin.Core/Models/CaseEntity.cs b/src/OutlookAddin.Core/Models/CaseEntity.cs index 220f1f2..80f014c 100644 --- a/src/OutlookAddin.Core/Models/CaseEntity.cs +++ b/src/OutlookAddin.Core/Models/CaseEntity.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text.Json.Serialization; +using MarcusLaw.OutlookAddin.Core.Json; namespace MarcusLaw.OutlookAddin.Core.Models { @@ -12,7 +13,11 @@ namespace MarcusLaw.OutlookAddin.Core.Models [JsonPropertyName("name")] public string? Name { get; set; } + // EspoCRM serializes the case number as a JSON number on some + // installs (auto-increment column) and as a string on others + // (custom case-code formatter). Accept both. [JsonPropertyName("number")] + [JsonConverter(typeof(FlexibleStringConverter))] public string? Number { get; set; } [JsonPropertyName("status")] diff --git a/src/OutlookAddin/OutlookAddin.csproj b/src/OutlookAddin/OutlookAddin.csproj index 4567767..a287928 100644 --- a/src/OutlookAddin/OutlookAddin.csproj +++ b/src/OutlookAddin/OutlookAddin.csproj @@ -36,7 +36,7 @@ C:\Users\Chaim\source\repos\OutlookAddin\Publish\ \\192.168.10.97\Projects\LegalCRM\Add-in\ en - 1.0.0.2 + 1.0.0.4 true true 7 @@ -258,6 +258,18 @@ OutlookAddin.Ribbon.InspectorRibbon.xml + + OutlookAddin.Images.klear-file.png + + + OutlookAddin.Images.klear-sidebar.png + + + OutlookAddin.Images.klear-settings.png + + + OutlookAddin.Images.klear-compose.png + Code @@ -347,7 +359,7 @@ - +