From 7a09f5756577b2046e6b1ec7b59369fcabf885d8 Mon Sep 17 00:00:00 2001 From: Felipe Baltazar Date: Thu, 17 Oct 2024 12:58:27 -0300 Subject: [PATCH] Force retry --- Maui.ServerDrivenUI/Models/ServerUIElement.cs | 4 +++- .../Services/XamlConverterService.cs | 1 - .../Views/ServerDrivenVisualElement.cs | 13 ++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Maui.ServerDrivenUI/Models/ServerUIElement.cs b/Maui.ServerDrivenUI/Models/ServerUIElement.cs index 4fa2bb1..3250f75 100644 --- a/Maui.ServerDrivenUI/Models/ServerUIElement.cs +++ b/Maui.ServerDrivenUI/Models/ServerUIElement.cs @@ -112,7 +112,9 @@ public string ToXaml(IList? customNamespaces = null) } } - return XamlConverterService.ConvertToXml(this); + var xaml = XamlConverterService.ConvertToXml(this); + return $"\n" + + $"{xaml}"; } #endregion diff --git a/Maui.ServerDrivenUI/Services/XamlConverterService.cs b/Maui.ServerDrivenUI/Services/XamlConverterService.cs index 3676a9b..3dbc30b 100644 --- a/Maui.ServerDrivenUI/Services/XamlConverterService.cs +++ b/Maui.ServerDrivenUI/Services/XamlConverterService.cs @@ -12,7 +12,6 @@ internal static class XamlConverterService public static string ConvertToXml(ServerUIElement element) { var strBuilder = new StringBuilder(); - strBuilder.AppendLine(""); strBuilder.Append($"<{element.Type}"); strBuilder.AppendLine(); diff --git a/Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs b/Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs index e981cf8..9b75927 100644 --- a/Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs +++ b/Maui.ServerDrivenUI/Views/ServerDrivenVisualElement.cs @@ -31,6 +31,7 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e var onLoaded = element.OnLoaded; var visualElement = (element as VisualElement); var currentBindingContext = visualElement?.BindingContext; + var forceRetry = false; try { @@ -51,11 +52,11 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e catch (Exception ex) { var xamlException = new UnableToLoadXamlException(XAML_LOAD_ERROR_MESSAGE, xaml, ex); - errorMessage = xamlException.Message; element.OnError(xamlException); + forceRetry = true; } - if (!IsXamlLoaded(element, attempt)) + if (!IsXamlLoaded(element, attempt, forceRetry)) return; if (visualElement != null) @@ -90,8 +91,14 @@ internal static async Task InitializeComponentAsync(IServerDrivenVisualElement e } } - private static bool IsXamlLoaded(IServerDrivenVisualElement element, int attempt) + private static bool IsXamlLoaded(IServerDrivenVisualElement element, int attempt, bool forceRetry = false) { + if (attempt < MAX_RETRIES && forceRetry) + { + _ = Task.Run(() => InitializeComponentAsync(element, attempt++)); + return false; + } + switch (element) { case ServerDrivenContentPage page when page.Content is null: