diff --git a/src/AasxIntegrationBase/AasxMenu.cs b/src/AasxIntegrationBase/AasxMenu.cs index 5729db47..5aa0c309 100644 --- a/src/AasxIntegrationBase/AasxMenu.cs +++ b/src/AasxIntegrationBase/AasxMenu.cs @@ -622,7 +622,7 @@ public AasxMenu AddLambda( // Operate // - public async Task ActivateAction(AasxMenuItemBase mi, AasxMenuActionTicket ticket) + public async Task ActivateAction(AasxMenuItemBase mi, AasxMenuActionTicket ticket, Action lambdaDone = null) { var name = mi?.Name?.Trim()?.ToLower(); @@ -634,6 +634,8 @@ public async Task ActivateAction(AasxMenuItemBase mi, AasxMenuActionTicket ticke await this.DefaultActionAsync(name, mi, ticket); else if (this.DefaultAction != null) this.DefaultAction(name, mi, ticket); + + lambdaDone?.Invoke(this); } // diff --git a/src/AasxPackageExplorer/debug.MIHO.script b/src/AasxPackageExplorer/debug.MIHO.script index 89f89f87..943bf9a6 100644 --- a/src/AasxPackageExplorer/debug.MIHO.script +++ b/src/AasxPackageExplorer/debug.MIHO.script @@ -48,25 +48,25 @@ // WriteLine(GetLastLogLine()); // TakeScreenShot("Test123"); -Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\00_FestoDemoBox-Module-2.aasx"); -Select("AAS", "First"); -Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); -Sleep(6000); +//Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\00_FestoDemoBox-Module-2.aasx"); +//Select("AAS", "First"); +//Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); +//Sleep(1000); -Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\12_article-dpdm-32-instance_1.aasx"); -Select("AAS", "First"); -Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); -Sleep(6000); +//Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\12_article-dpdm-32-instance_1.aasx"); +//Select("AAS", "First"); +//Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); +//Sleep(1000); -Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\13_article-dpdm-32-instance_2.aasx"); -Select("AAS", "First"); -Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); -Sleep(6000); +//Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\13_article-dpdm-32-instance_2.aasx"); +//Select("AAS", "First"); +//Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); +//Sleep(1000); //Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\16_article-ovel-10.aasx"); //Select("AAS", "First"); //Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); -//Sleep(6000); +//Sleep(1000); //Tool("Open", "File", "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\17_article-spau.aasx"); //Select("AAS", "First"); @@ -108,3 +108,26 @@ Sleep(6000); //Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); //Sleep(1000); + +var fns = [ + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\00_FestoDemoBox-Module-2.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\\12_article-dpdm-32-instance_1.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\13_article-dpdm-32-instance_2.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\16_article-ovel-10.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\17_article-spau.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\18_article-vuvg-l14_1.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\18_article-vuvg-l14_2.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\20_Festo_579071_SMT-8M-A-PS-24V-E-0.3-M12_proximity_switch.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\21_article-elgs-45-200.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\22_article-CPX-E-CEC-M1-PN.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\30_Festo_SPAU_VR3.aasx", + "C:\\HOMI\\Develop\\Aasx\\repo_Festo_demo_case_V3\31_HMI22_Festo_CMMT.aasx" +]; + +foreach (fn in fns) +{ + Tool("Open", "File", fn); + Select("AAS", "First"); + Tool("apiuploadassistant", "BaseAddress", "http://localhost:5001/api/v3.0/", "IncludeSubmodels", true, "IncludeCDs", true, "IncludeSupplFiles", true, "OverwriteIfExist", true); + Sleep(1000); +} \ No newline at end of file diff --git a/src/AasxPackageLogic/AasxScript.cs b/src/AasxPackageLogic/AasxScript.cs index d38fbbbf..7856da49 100644 --- a/src/AasxPackageLogic/AasxScript.cs +++ b/src/AasxPackageLogic/AasxScript.cs @@ -31,7 +31,7 @@ namespace AasxPackageExplorer /// public interface IAasxScriptRemoteInterface { - Task Tool(object[] args); + Task Tool(object[] args, Action lambdaDone); Aas.IReferable Select(object[] args); Aas.IReferable[] SelectAll(object[] args); Task Location(object[] args); @@ -95,7 +95,82 @@ public virtual object Invoke(IScriptContext context, object[] args) } } - public class Script_WriteLine : ScriptInvokableBase + public class ScriptInvokableBaseAsync : ScriptInvokableBase + { + protected static int _mutex = 0; + + public ScriptInvokableBaseAsync(AasxScript script) : base(script) + { + } + + public virtual async Task InnerInvoke(IScriptContext context, object[] args) + { + await Task.Yield(); + return 0; + } + + public override object Invoke(IScriptContext context, object[] args) + { + // debug + if (_script._logLevel >= 2) + Log.Singleton.Info($"Execute {this.GetType().Name} " + string.Join(",", args)); + + // for the outer script loop, wait for any invocation the Task to be completed! + int n = 0; + while (_mutex > 0) + { + n++; + Thread.Sleep(100); + } + if (_script._logLevel >= 2 && n > 0) + Log.Singleton.Info($"Waiting for mutex = {_mutex} the time of {n} x 100ms."); + + // inner + object res = 0; + if (Application.Current != null) + { + // WPF case + Task x = null; + x = Application.Current.Dispatcher.Invoke(async () => + { + if (_script?.Remote == null) + return -1; + + lock (_script) + { + _mutex = 1 + (new Random()).Next(98); + } + + if (_script._logLevel >= 2) + Log.Singleton.Info($"Started new mutex = {_mutex} and going to invocation of script function .."); + + res = await InnerInvoke(context, args); + + if (_script._logLevel >= 2) + Log.Singleton.Info($".. done with result = {res}."); + + return res; + }); + if (x != null) + Log.Singleton.Silent("" + x + " "); + res = x.Result; + } + else + { + // Blazor?? case + res = _script.Remote?.Select(args); + } + + // debug + if (_script._logLevel >= 2) + Log.Singleton.Info($"Finalized execute {this.GetType().Name} " + string.Join(",", args)); + + // end + return res; + } + } + + public class Script_WriteLine : ScriptInvokableBaseAsync { public Script_WriteLine(AasxScript script) : base(script) { @@ -105,14 +180,21 @@ public Script_WriteLine(AasxScript script) : base(script) .Add("", "All arguments are writen to the scriot log.")); } - public override object Invoke(IScriptContext context, object[] args) + public override async Task InnerInvoke(IScriptContext context, object[] args) { + await Task.Yield(); + _script?.ScriptLog?.Info("Script: " + string.Join(",", args)); + lock (_script) + { + _mutex = 0; + } + return 0; } } - public class Script_Sleep : ScriptInvokableBase + public class Script_Sleep : ScriptInvokableBaseAsync { public Script_Sleep(AasxScript script) : base(script) { @@ -122,15 +204,21 @@ public Script_Sleep(AasxScript script) : base(script) .Add("