From 0934913978bcb1f12e3c1a80fb497c551c8e68f1 Mon Sep 17 00:00:00 2001 From: skadefro Date: Tue, 23 Apr 2024 22:14:33 +0200 Subject: [PATCH] Fix index/Total updates in BreakableLoop --- OpenRPA.Interfaces/BreakableLoop.cs | 92 +++++++++-------------------- OpenRPA/OpenRPA.csproj | 2 +- 2 files changed, 30 insertions(+), 64 deletions(-) diff --git a/OpenRPA.Interfaces/BreakableLoop.cs b/OpenRPA.Interfaces/BreakableLoop.cs index a43d27ab..9df418e5 100644 --- a/OpenRPA.Interfaces/BreakableLoop.cs +++ b/OpenRPA.Interfaces/BreakableLoop.cs @@ -41,93 +41,59 @@ private void OnContinue(NativeActivityContext context, Bookmark bookmark, object context.ResumeBookmark(_bookmark, value); } } + public void SetTotal(NativeActivityContext context, int Value) + { + var input = GetDescriptor(context, "Total"); + if (input == null) return; + input.SetValue(context.DataContext, Value); + } public void IncIndex(NativeActivityContext context) { - var input = GetTotalDescriptor(context); + var input = GetDescriptor(context, "Index"); if (input == null) return; - if (input != null) + try { - try + var _index = 0; + var value = input.GetValue(context.DataContext); + if (value != null) { - var _index = 0; - var value = input.GetValue(context.DataContext); - if (value != null) + if (value is int wfview) { - if (value is int wfview) - { - _index = (int)value; - } - else if(int.TryParse(value.ToString(), out int current)) - { - _index = current; - } + _index = (int)value; } - _index++; - input.SetValue(context.DataContext, _index); - } - catch (Exception ex) - { - Log.Warning("Updating loop Index failed with " + ex.ToString()); - } - } - } - public Variable GetTotalVariable(NativeActivityContext context) - { - if (Variables.Count < 1) return null; - for (var i = 0; i < Variables.Count; i++) - { - var variable = Variables[i]; - if (variable.Name == "Total" && variable.Type == typeof(int)) - { - return variable; + else if(int.TryParse(value.ToString(), out int current)) + { + _index = current; + } } + _index++; + input.SetValue(context.DataContext, _index); } - return null; - } - public PropertyDescriptor GetTotalDescriptor(NativeActivityContext context) - { - if (Variables.Count < 1) return null; - for (var i = 0; i < Variables.Count; i++) + catch (Exception ex) { - var variable = Variables[i]; - if (variable.Name == "Total" && variable.Type == typeof(int)) - { - return context.DataContext.GetProperties()[variable.Name]; - } + Log.Warning("Updating loop Index failed with " + ex.ToString()); } - return null; } - public Variable GetIndexVariable(NativeActivityContext context) + public Variable GetVariable(NativeActivityContext context, string Name) { if (Variables.Count < 1) return null; + if(context == null) return null; + if (string.IsNullOrEmpty(Name)) return null; for (var i = 0; i < Variables.Count; i++) { var variable = Variables[i]; - if (variable.Name == "Index" && variable.Type == typeof(int)) + if (variable.Name.ToLower() == Name.ToLower() && variable.Type == typeof(T)) { return variable; } } return null; } - public PropertyDescriptor GetIndexDescriptor(NativeActivityContext context) - { - if (Variables.Count < 1) return null; - for (var i = 0; i < Variables.Count; i++) - { - var variable = Variables[i]; - if (variable.Name == "Index" && variable.Type == typeof(int)) - { - return context.DataContext.GetProperties()[variable.Name]; - } - } - return null; - } - public void SetTotal(NativeActivityContext context, int Value) + public PropertyDescriptor GetDescriptor(NativeActivityContext context, string Name) { - var input = GetTotalDescriptor(context); - if (input == null) return; - input.SetValue(context.DataContext, Value); + var v = GetVariable(context, Name); + if(v == null) return null; + return context.DataContext.GetProperties()[v.Name]; } [System.ComponentModel.Browsable(false)] public System.Collections.ObjectModel.Collection Variables { get; set; } = new System.Collections.ObjectModel.Collection(); diff --git a/OpenRPA/OpenRPA.csproj b/OpenRPA/OpenRPA.csproj index 9169222f..a75f264d 100644 --- a/OpenRPA/OpenRPA.csproj +++ b/OpenRPA/OpenRPA.csproj @@ -11,7 +11,7 @@ Base UI of OpenRPA, used as part of OpenRPA robot MPL-2.0 https://github.com/open-rpa/openrpa - 1.4.57.3 + 1.4.57.4 openrpa.png Debug;Release;ReleaseNuget;PrepInstaller