From ed41f2967a343e6ce1a999bf6e743d0dbdba205e Mon Sep 17 00:00:00 2001 From: Dimitrie Stefanescu Date: Wed, 14 Oct 2020 13:31:29 +0100 Subject: [PATCH] feat(progress display): makes the progress display function overridable --- .../Base/GH_AsyncComponent.cs | 49 ++++++++++--------- .../GrasshopperAsyncComponent.csproj | 3 +- .../Properties/AssemblyInfo.cs | 2 +- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/GrasshopperAsyncComponent/Base/GH_AsyncComponent.cs b/GrasshopperAsyncComponent/Base/GH_AsyncComponent.cs index 3eee2bb..6af661d 100644 --- a/GrasshopperAsyncComponent/Base/GH_AsyncComponent.cs +++ b/GrasshopperAsyncComponent/Base/GH_AsyncComponent.cs @@ -56,29 +56,7 @@ namespace GrasshopperAsyncComponent { DisplayProgressTimer = new Timer(333) { AutoReset = false }; - DisplayProgressTimer.Elapsed += (s, e) => - { - if (Workers.Count == 0) return; - if (Workers.Count == 1) - { - Message = ProgressReports.Values.Last().ToString("0.00%"); - } - else - { - double total = 0; - foreach (var kvp in ProgressReports) - { - total += kvp.Value; - } - - Message = (total / Workers.Count).ToString("0.00%"); - } - - Rhino.RhinoApp.InvokeOnUiThread((Action)delegate - { - OnDisplayExpired(true); - }); - }; + DisplayProgressTimer.Elapsed += DisplayProgress; ReportProgress = (id, value) => { @@ -113,6 +91,31 @@ namespace GrasshopperAsyncComponent Tasks = new List(); } + public virtual void DisplayProgress(object sender, System.Timers.ElapsedEventArgs e) + { + if (Workers.Count == 0) return; + if (Workers.Count == 1) + { + Message = ProgressReports.Values.Last().ToString("0.00%"); + } + else + { + double total = 0; + foreach (var kvp in ProgressReports) + { + total += kvp.Value; + } + + Message = (total / Workers.Count).ToString("0.00%"); + } + + Rhino.RhinoApp.InvokeOnUiThread((Action)delegate + { + OnDisplayExpired(true); + }); + } + + protected override void BeforeSolveInstance() { if (State != 0 && SetData) return; diff --git a/GrasshopperAsyncComponent/GrasshopperAsyncComponent.csproj b/GrasshopperAsyncComponent/GrasshopperAsyncComponent.csproj index 30e8f2c..9b3b252 100644 --- a/GrasshopperAsyncComponent/GrasshopperAsyncComponent.csproj +++ b/GrasshopperAsyncComponent/GrasshopperAsyncComponent.csproj @@ -78,8 +78,7 @@ --> - Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha" -Erase "$(TargetPath)" + Copy "$(TargetPath)" "$(TargetDir)$(ProjectName).gha" en-US diff --git a/GrasshopperAsyncComponent/Properties/AssemblyInfo.cs b/GrasshopperAsyncComponent/Properties/AssemblyInfo.cs index 3764cb5..bc7322f 100644 --- a/GrasshopperAsyncComponent/Properties/AssemblyInfo.cs +++ b/GrasshopperAsyncComponent/Properties/AssemblyInfo.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyTitle("GrasshopperAsyncComponent")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] +[assembly: AssemblyCompany("Aec systems")] [assembly: AssemblyProduct("GrasshopperAsyncComponent")] [assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyTrademark("")]