From 665632feba1c6442630a032a861ab0f9e5f496ab Mon Sep 17 00:00:00 2001 From: Gokul Bothe Date: Fri, 29 Nov 2024 23:26:36 +0530 Subject: [PATCH] Value Expression for Script Action --- .../ActionEditPages/ActScriptEditPage.xaml | 5 ++- .../ActionEditPages/ActScriptEditPage.xaml.cs | 5 ++- Ginger/GingerCoreNET/ActionsLib/ActScript.cs | 40 +++++++++++++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml b/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml index 30efdc49e0..46b8beb457 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml +++ b/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml @@ -14,8 +14,9 @@ - - + + + diff --git a/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml.cs b/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml.cs index b25a10af9e..c0e09945d9 100644 --- a/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml.cs +++ b/Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml.cs @@ -17,6 +17,7 @@ limitations under the License. #endregion using amdocs.ginger.GingerCoreNET; +using Amdocs.Ginger.Common; using GingerCore.Actions; using System; using System.IO; @@ -53,8 +54,8 @@ public ActScriptEditPage(GingerCore.Actions.ActScript Act) WeakEventManager.AddHandler(source: ScriptNameComboBox, eventName: nameof(Selector.SelectionChanged), handler: ScriptNameComboBox_SelectionChanged); - ScriptInterPreter.FileExtensions.Add(".exe"); - ScriptInterPreter.Init(Act, nameof(ActScript.ScriptInterpreter), true); + xVScriptInterPreter.Init(Context.GetAsContext(actScript.Context), actScript, nameof(ActScript.ScriptInterpreter), true, true, UCValueExpression.eBrowserType.File, "*.*"); + actScript.ScriptPath = SHFilesPath; var comboEnumItem = ScriptInterpreterComboBox.Items.Cast().FirstOrDefault(x => x.text == ActScript.eScriptInterpreterType.JS.ToString()); diff --git a/Ginger/GingerCoreNET/ActionsLib/ActScript.cs b/Ginger/GingerCoreNET/ActionsLib/ActScript.cs index 1b4f9759fd..f75416e791 100644 --- a/Ginger/GingerCoreNET/ActionsLib/ActScript.cs +++ b/Ginger/GingerCoreNET/ActionsLib/ActScript.cs @@ -82,8 +82,27 @@ public enum eScriptInterpreterType [IsSerializedForLocalRepository] public eScriptAct ScriptCommand { get; set; } + + private string mScriptInterpreter; [IsSerializedForLocalRepository] - public string ScriptInterpreter { get; set; } + public string ScriptInterpreter + { + get + { + return mScriptInterpreter; + } + set + { + if (mScriptInterpreter != value) + { + mScriptInterpreter = value; + OnPropertyChanged(nameof(ScriptInterpreter)); + + } + } + } + + [IsSerializedForLocalRepository] public eScriptInterpreterType ScriptInterpreterType { get; set; } @@ -142,6 +161,11 @@ protected void AddData(string outLine) } public override void Execute() { + ValueExpression VE = new() + { + Value = ScriptInterpreter + }; + string calculatedScriptInterpreter = VE.ValueCalculated; if (ScriptName == null && ScriptCommand == eScriptAct.Script) { Reporter.ToLog(eLogLevel.ERROR, "Script file not Selected. Kindly select suitable file"); @@ -178,9 +202,9 @@ public override void Execute() p.StartInfo.FileName = "/bin/bash"; break; case eScriptInterpreterType.Other: - if (!string.IsNullOrEmpty(ScriptInterpreter)) + if (!string.IsNullOrEmpty(calculatedScriptInterpreter)) { - p.StartInfo.FileName = WorkSpace.Instance.Solution.SolutionOperations.ConvertSolutionRelativePath(ScriptInterpreter); + p.StartInfo.FileName = WorkSpace.Instance.Solution.SolutionOperations.ConvertSolutionRelativePath(calculatedScriptInterpreter); } break; } @@ -232,7 +256,7 @@ public override void Execute() string filePath = Path.Combine(p.StartInfo.WorkingDirectory, ScriptName); p.StartInfo.Arguments = filePath + Params; } - else if (ScriptInterpreter != null && ScriptInterpreter.Contains("cmd.exe")) + else if (calculatedScriptInterpreter != null && calculatedScriptInterpreter.Contains("cmd.exe")) { p.StartInfo.Arguments = " /k " + ScriptName + " " + Params; } @@ -254,20 +278,20 @@ public override void Execute() } else if (ScriptInterpreterType == eScriptInterpreterType.Other) { - if (ScriptInterpreter != null && ScriptInterpreter.ToLower().Contains("cmd.exe")) + if (calculatedScriptInterpreter != null && calculatedScriptInterpreter.ToLower().Contains("cmd.exe")) { TempFileName = CreateTempFile("cmd"); } - else if (ScriptInterpreter != null && ScriptInterpreter.ToLower().Contains("powershell.exe")) + else if (calculatedScriptInterpreter != null && calculatedScriptInterpreter.ToLower().Contains("powershell.exe")) { TempFileName = CreateTempFile("ps1"); p.StartInfo.Arguments = @"-executionpolicy bypass -file .\" + TempFileName + " " + Params; } - else if (ScriptInterpreter != null && ScriptInterpreter.ToLower().Contains("python.exe")) + else if (calculatedScriptInterpreter != null && calculatedScriptInterpreter.ToLower().Contains("python.exe")) { TempFileName = CreateTempFile("py"); } - else if (ScriptInterpreter != null && ScriptInterpreter.ToLower().Contains("perl.exe")) + else if (calculatedScriptInterpreter != null && calculatedScriptInterpreter.ToLower().Contains("perl.exe")) { TempFileName = CreateTempFile("pl"); }