Skip to content

Commit

Permalink
Value Expression for Script Action
Browse files Browse the repository at this point in the history
  • Loading branch information
GokulBothe99 committed Nov 29, 2024
1 parent ce2d754 commit 665632f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
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;
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"))
{
TempFileName = CreateTempFile("pl");
}
Expand Down

0 comments on commit 665632f

Please sign in to comment.