Skip to content

Commit

Permalink
Merge branch 'master' into BugFix/SharedRepositoryFix
Browse files Browse the repository at this point in the history
  • Loading branch information
prashelke authored Oct 28, 2024
2 parents 90f9dc9 + fbd5850 commit e482bbe
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 10 deletions.
63 changes: 54 additions & 9 deletions Ginger/Ginger/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ limitations under the License.
using GingerWPF.WorkSpaceLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
Expand Down Expand Up @@ -280,11 +283,12 @@ private async void Application_Startup(object sender, StartupEventArgs e)
await RunNewCLI(parserResult);
}
}
catch (Exception ex) {
catch (Exception ex)
{
Reporter.ToLog(eLogLevel.ERROR, "Unhandled exception in Application_Startup", ex);
}

}


/// <summary>
/// Initializes the logging mechanism for the application using log4net.
Expand All @@ -306,15 +310,37 @@ private bool ShouldStartGrid(string[] args)
}

/// <summary>
/// Parses command-line arguments and returns the result.
/// If no arguments are provided, returns null.
/// Parses the command line arguments and returns the parsed result.
/// </summary>
/// <param name="args">Command-line arguments.</param>
/// <returns>ParserResult containing parsed arguments or null.</returns>
/// <param name="args">The command line arguments.</param>
/// <returns>The parsed result of the command line arguments.</returns>
private ParserResult<object> ParseCommandLineArguments(string[] args)
{
string[] arguments;
//Added this codition if only user want to launch Ginger without any solution from browser.
if (args.Length == 1 && System.Web.HttpUtility.UrlDecode(args[0]).Equals("ginger:///", StringComparison.OrdinalIgnoreCase))
{
return null;
}
if (args.Length == 1)
{
string input = args[0];
input = System.Web.HttpUtility.UrlDecode(input);
if (input.StartsWith("ginger://"))
{
input = input.Substring("ginger://".Length);
}
List<string> resultList = General.SplitWithPaths(input).Select(s => s.Trim('\"', '\'')).ToList();
arguments = resultList.ToArray();
}
else
{
arguments = args;
}


cliProcessor = new CLIProcessor();
return args.Length != 0 ? cliProcessor.ParseArguments(args) : null;
return arguments.Length != 0 ? cliProcessor.ParseArguments(arguments) : null;
}

/// <summary>
Expand All @@ -341,6 +367,10 @@ private DoOptions ExtractDoOptions(ParserResult<object> parserResult)
/// <returns>True if the application is in execution mode, otherwise false.</returns>
private bool IsExecutionMode(string[] args, DoOptions doOptions)
{
if (args.Length == 1 && System.Web.HttpUtility.UrlDecode(args[0]).Equals("ginger:///", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return args.Length != 0 && doOptions == null;
}

Expand Down Expand Up @@ -387,7 +417,15 @@ private void ProcessGingerUIStartup(DoOptions doOptions)

if (doOptions != null && !string.IsNullOrWhiteSpace(doOptions.Solution))
{
DoOptionsHandler.Run(doOptions);
if(Directory.Exists(doOptions.Solution))
{
DoOptionsHandler.Run(doOptions);
}
else
{
Reporter.ToLog(eLogLevel.ERROR, "The specified solution folder path does not exist. Please check the path and try again.");
}

}
}
finally
Expand Down Expand Up @@ -423,6 +461,11 @@ public static void ShowConsoleWindow()
ShowWindow(handle, SW_SHOW);
}

/// <summary>
/// Runs the new CLI process with the provided parsed arguments.
/// </summary>
/// <param name="parserResult">The parsed result of the command line arguments.</param>
/// <returns>A task representing the asynchronous operation.</returns>
private async Task RunNewCLI(ParserResult<object> parserResult)
{
try
Expand All @@ -440,9 +483,11 @@ private async Task RunNewCLI(ParserResult<object> parserResult)
{
System.Windows.Application.Current.Shutdown(Environment.ExitCode);
}

}

/// <summary>
/// Starts the Ginger UI. Initializes dictionaries and the main window.
/// </summary>
public void StartGingerUI()
{
if (WorkSpace.Instance.RunningFromUnitTest)
Expand Down
25 changes: 25 additions & 0 deletions Ginger/Ginger/GeneralLib/General.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ limitations under the License.
using Amdocs.Ginger.Repository;
using Ginger.Help;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
Expand Down Expand Up @@ -663,5 +665,28 @@ public static string EscapeAccessKey(string s)

return s.Replace("_", "__");
}

/// <summary>
/// Splits the input string into a list of strings, preserving paths enclosed in quotes.
/// </summary>
/// <param name="input">The input string to split.</param>
/// <returns>A list of strings split from the input.</returns>
public static List<string> SplitWithPaths(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return [];
}
var pattern = @"[^\s""']+|""([^""]*)""|'([^']*)'";
var matches = Regex.Matches(input, pattern);
List<string> results = [];

foreach (Match match in matches)
{
results.Add(match.Value.Trim());
}

return results;
}
}
}
24 changes: 23 additions & 1 deletion Ginger/GingerCoreNET/RunLib/CLILib/DoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
#endregion

using CommandLine;
using System;
using System.IO;
using System.Net;

namespace Amdocs.Ginger.CoreNET.RunLib.CLILib
{
Expand All @@ -35,8 +38,27 @@ public enum DoOperation
[Option('o', "operation", Required = true, HelpText = "Select operation to run on solution")]
public DoOperation Operation { get; set; }

private string _solution;

[Option('s', "solution", Required = true, HelpText = "Set solution folder")]
public string Solution { get; set; }
public string Solution
{
get => _solution;
set
{
if (string.IsNullOrWhiteSpace(value))
{
return;
}
if (value.IndexOf("Ginger.Solution.xml", StringComparison.OrdinalIgnoreCase) >= 0)
{
value = Path.GetDirectoryName(value)?.Trim() ?? string.Empty;

}
_solution = value;
}
}


}

Expand Down

0 comments on commit e482bbe

Please sign in to comment.