Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Expression for Script Action #4012

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Ginger/Ginger/Actions/ActionEditPages/ActScriptEditPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
</StackPanel>
<StackPanel Orientation="Vertical" >
<StackPanel x:Name="InterpreterPathPanel" Visibility="Collapsed" Orientation="Horizontal" >
<Label x:Name="ScriptInterpreterLabel" Style="{StaticResource @InputFieldLabelStyle}" Width="250" Height="35">Script Interpreter Path</Label>
<Actions:UCFileBrowser HorizontalAlignment="Left" x:Name="ScriptInterPreter" Width="370"/>
<Label x:Name="ScriptInterpreterLabel" Style="{StaticResource @InputFieldLabelStyle}" Width="250" Height="35">Script Interpreter Path</Label>
<Actions:UCValueExpression x:Name="xVScriptInterPreter" ToolTip="Select Interpreter according to script." Width="370"/>

</StackPanel>
<StackPanel x:Name="ScriptActionPanel" Visibility="Visible" Orientation="Horizontal">
<Label Style="{StaticResource @InputFieldLabelStyle}" Height="35" Width="250">Script Action</Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,8 +54,8 @@ public ActScriptEditPage(GingerCore.Actions.ActScript Act)

WeakEventManager<Selector, SelectionChangedEventArgs>.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<GingerCore.GeneralLib.ComboEnumItem>().FirstOrDefault(x => x.text == ActScript.eScriptInterpreterType.JS.ToString());
Expand Down
40 changes: 32 additions & 8 deletions Ginger/GingerCoreNET/ActionsLib/ActScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -142,6 +161,11 @@ protected void AddData(string outLine)
}
public override void Execute()
{
ValueExpression VE = new()
{
Value = ScriptInterpreter
};
string calculatedScriptInterpreter = VE.ValueCalculated;
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
if (ScriptName == null && ScriptCommand == eScriptAct.Script)
{
Reporter.ToLog(eLogLevel.ERROR, "Script file not Selected. Kindly select suitable file");
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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"))
GokulBothe99 marked this conversation as resolved.
Show resolved Hide resolved
{
TempFileName = CreateTempFile("pl");
}
Expand Down
Loading