public ChromeClientsLauncher(SdkConfig.Factory sdkConfigFactory, LaunchParams launchParams, IChromeLauncher chromeLauncher) { LaunchParams = launchParams; _chromeLauncher = chromeLauncher; _sdkConfig = new Lazy <SdkConfig>(sdkConfigFactory.LoadOrDefault); }
/// <summary> /// Parse a launch command and return the launch arguments. /// </summary> /// <exception cref="ArgumentException">Thrown if the command is malformed</exception> /// <exception cref="ArgumentNullException">Thrown if the command is null</exception> public void Parse(string command, out LaunchParams launchParams, out string launchName) { if (command == null) { throw new ArgumentNullException(nameof(command)); } var ccCmd = $"/c \"\"{launcherPath}\" "; if (!command.StartsWith(ccCmd)) { throw new ArgumentException($"launch command is malformed: {command}"); } var args = command.Substring(ccCmd.Length); args = args.Substring(0, args.Length - 1); string launchParamsArg = args; string launchNameArg = null; if (args.Contains(" ")) { launchParamsArg = args.Substring(0, args.IndexOf(" ", StringComparison.Ordinal)); launchNameArg = args.Substring(args.IndexOf(" ", StringComparison.Ordinal)); } launchParams = DecodeLaunchParams(launchParamsArg); launchName = launchNameArg == null ? null : Encoding.UTF8.GetString(Convert.FromBase64String(launchNameArg)); }
/// <summary> /// Create a launch command that can execute using Cmd.exe /// </summary> public string CreateFromParams(LaunchParams launchParams) => $"/c \"\"{launcherPath}\" {EncodeLaunchParams(launchParams)}\"";
/// <summary> /// Create a launch command that can execute using Cmd.exe /// </summary> public string CreateWithLaunchName(LaunchParams launchParams, string launchName) => $"/c \"\"{launcherPath}\" {EncodeLaunchParams(launchParams)} " + $"{EncodeLaunchName(launchName)}\"";
/// <summary> /// base64 encode launch parameters /// </summary> public string EncodeLaunchParams(LaunchParams launchParams) => Convert.ToBase64String( Encoding.UTF8.GetBytes( serializer.Serialize(launchParams)));