public void InsertRange() => Assert.Equal( new [] { "zero", "one", "two", "three", "four" }, ProcessArguments .Create("four") .InsertRange(0, "zero", "one") .InsertRange(2, new [] { "two", "three" }));
public void Insert() => Assert.Equal( new [] { "zero", "one", "two", "three", "four" }, ProcessArguments .Create("one", "three") .Insert(1, "two") .Insert(3, "four") .Insert(0, "zero"));
public void ImplicitlyExecAssemblyWithMonoOnUnix() { var exec = new Exec(ProcessArguments.Create("test.exe", "a", "b")); Assert.False(exec.Elevated); Assert.Equal( exec.Arguments, ProcessArguments.Create("mono", "test.exe", "a", "b")); }
public void CreateFromArgsFailTest() { var processArgumentsArgs = ProcessArguments.Create(new [] { "blabla" }); Assert.IsNull(processArgumentsArgs); var processArgumentsArgs2 = ProcessArguments.Create(new[] { "blabla=" }); Assert.IsNull(processArgumentsArgs2); }
public void ElevateOnMac() { var exec = new Exec( ProcessArguments.Create("installer"), ExecFlags.Elevate); Assert.True(exec.Elevated); Assert.Equal( exec.Arguments, ProcessArguments.Create("/usr/bin/sudo", "installer")); }
public void ElevateOnMacAndImplicitlyExecAssemblyWithMonoOnUnix() { var exec = new Exec( ProcessArguments.Create("test.exe", "a", "b"), ExecFlags.Elevate); Assert.True(exec.Elevated); Assert.Equal( exec.Arguments, ProcessArguments.Create("/usr/bin/sudo", "mono", "test.exe", "a", "b")); }
public void CreateFromNameTest() { const string ipcName = "TestMe"; var processArguments = ProcessArguments.Create(ipcName, typeof(ProcessArgumentsTest)); Assert.IsTrue(processArguments.IsValid); Assert.AreEqual(processArguments.IpcClientName, ProcessArguments.CreateIpcClientName(ipcName)); Assert.AreEqual(processArguments.IpcProcessName, ProcessArguments.CreateIpcProcessName(ipcName)); Assert.AreEqual(processArguments.IpcServerName, ProcessArguments.CreateIpcServerName(ipcName)); Assert.AreEqual(processArguments.IpcParentProgramPid, Process.GetCurrentProcess().Id); Assert.AreEqual(typeof(ProcessArgumentsTest).Assembly, processArguments.IpcAssembly); Assert.AreEqual(typeof(ProcessArgumentsTest), processArguments.IpcRemoteType); }
public void IgnoreElevateOnUnix() { // On VSTS the hosted Linux pool runs as root (sigh, but we can take // advantage of that fact to test that we are _not_ wrapping with // sudo if we already are root). if (Environment.GetEnvironmentVariable("TF_BUILD") == "True") { var exec = new Exec( ProcessArguments.Create("installer"), ExecFlags.Elevate); Assert.False(exec.Elevated); Assert.Equal( exec.Arguments, ProcessArguments.Create("installer")); } }
public void CreateFromArgsTest() { const string ipcName = "TestMe"; var processArguments = ProcessArguments.Create(ipcName, typeof(ProcessArgumentsTest)); var args = processArguments.ToStringArray(); var processArgumentsArgs = ProcessArguments.Create(args); Assert.IsTrue(processArgumentsArgs.IsValid); Assert.AreEqual(processArguments.IpcClientName, processArgumentsArgs.IpcClientName); Assert.AreEqual(processArgumentsArgs.IpcProcessName, processArgumentsArgs.IpcProcessName); Assert.AreEqual(processArguments.IpcServerName, processArgumentsArgs.IpcServerName); Assert.AreEqual(processArguments.IpcParentProgramPid, processArgumentsArgs.IpcParentProgramPid); Assert.AreEqual(processArguments.IpcAssembly, processArgumentsArgs.IpcAssembly); Assert.AreEqual(processArguments.IpcRemoteType, processArgumentsArgs.IpcRemoteType); }
public void ToStringTest() { const string ipcName = "TestMe"; var processArguments = ProcessArguments.Create(ipcName, typeof(ProcessArgumentsTest)); var argsString = processArguments.ToString(); var args = argsString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var processArgumentsArgs = ProcessArguments.Create(args); Assert.IsTrue(processArgumentsArgs.IsValid); Assert.AreEqual(processArguments.IpcClientName, processArgumentsArgs.IpcClientName); Assert.AreEqual(processArgumentsArgs.IpcProcessName, processArgumentsArgs.IpcProcessName); Assert.AreEqual(processArguments.IpcServerName, processArgumentsArgs.IpcServerName); Assert.AreEqual(processArguments.IpcParentProgramPid, processArgumentsArgs.IpcParentProgramPid); Assert.AreEqual(processArguments.IpcAssembly, processArgumentsArgs.IpcAssembly); Assert.AreEqual(processArguments.IpcRemoteType, processArgumentsArgs.IpcRemoteType); }
/// <summary> /// Constructor with interprocess communication name /// </summary> /// <param name="ipcName"></param> protected MultiProcessWorkerClientBase(string ipcName) : this(ProcessArguments.Create(ipcName)) { MaxShutdownTimeout = 0; }
public void Create(params string [] args) => Assert.Equal(args, ProcessArguments.Create(args));
public void Empty() { Assert.Same(ProcessArguments.Empty, ProcessArguments.Create()); Assert.Same(ProcessArguments.Empty, ProcessArguments.Parse(string.Empty)); }
protected override string GenerateCommandLineCommands() { ProcessArguments arguments = null; if (!InvokeLinkerUsingMono) { arguments = ProcessArguments.Create("--verbose"); } else { var toolsPath = GetPathToMonoLinker(); Log.LogMessage(MessageImportance.High, $"Running monolinker from {toolsPath}."); arguments = ProcessArguments.Create(toolsPath); arguments = arguments.Add("--verbose"); } arguments = arguments.AddRange("--deterministic"); // add exclude features arguments = arguments.AddRange("--exclude-feature", "remoting", "--exclude-feature", "com", "--exclude-feature", "etw"); string coremode, usermode; switch ((WasmLinkMode)Enum.Parse(typeof(WasmLinkMode), LinkMode)) { case WasmLinkMode.SdkOnly: coremode = "link"; usermode = "copy"; break; case WasmLinkMode.Full: coremode = "link"; usermode = "link"; break; default: coremode = "copyused"; usermode = "copy"; break; } arguments = arguments.AddRange("-c", coremode, "-u", usermode); //the linker doesn't consider these core by default foreach (var bn in bindingNames) { arguments = arguments.AddRange("-p", coremode, bn); } if (!string.IsNullOrEmpty(LinkSkip)) { var skips = LinkSkip.Split(new[] { ';', ',', ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in skips) { arguments = arguments.AddRange("-p", "copy", s); } } arguments = arguments.AddRange("-out", OutputDir); arguments = arguments.AddRange("-d", FrameworkDir); arguments = arguments.AddRange("-d", Path.Combine(FrameworkDir, "Facades")); arguments = arguments.AddRange("-b", Debug.ToString()); arguments = arguments.AddRange("-v", Debug.ToString()); // add custom link descriptions // to ensure the type, methods and/or fields are not eliminated from your application. if (LinkDescriptions != null) { foreach (var desc in LinkDescriptions) { var l = desc.GetMetadata("FullPath"); arguments = arguments.AddRange("-x", l); } } arguments = arguments.AddRange("-a", RootAssembly[0].GetMetadata("FullPath")); //we'll normally have to check most of the files because the SDK references most framework asm by default //so let's enumerate upfront var frameworkAssemblies = new HashSet <string> (StringComparer.OrdinalIgnoreCase); foreach (var f in Directory.EnumerateFiles(FrameworkDir)) { frameworkAssemblies.Add(Path.GetFileNameWithoutExtension(f)); } foreach (var f in Directory.EnumerateFiles(Path.Combine(FrameworkDir, "Facades"))) { frameworkAssemblies.Add(Path.GetFileNameWithoutExtension(f)); } // Load the runtime assemblies to be replaced in the references below var runtimeCopyLocal = new Dictionary <string, string> (StringComparer.OrdinalIgnoreCase); if (RuntimeCopyLocalAssemblies != null) { foreach (var copyAsm in RuntimeCopyLocalAssemblies) { var p = copyAsm.GetMetadata("FullPath"); if (frameworkAssemblies.Contains(Path.GetFileNameWithoutExtension(p))) { continue; } runtimeCopyLocal.Add(Path.GetFileNameWithoutExtension(p), p); } } //add references for non-framework assemblies if (Assemblies != null) { foreach (var asm in Assemblies) { var p = asm.GetMetadata("FullPath"); if (frameworkAssemblies.Contains(Path.GetFileNameWithoutExtension(p))) { continue; } if (runtimeCopyLocal.TryGetValue(Path.GetFileNameWithoutExtension(p), out var runtimePath)) { if (!string.IsNullOrEmpty(BindingsDir) && bindingNames.Contains(Path.GetFileNameWithoutExtension(p))) { runtimePath = Path.Combine(BindingsDir, Path.GetFileName(p)); } // Just in case if (File.Exists(runtimePath)) { p = runtimePath; } } arguments = arguments.AddRange("-r", p); } } if (string.IsNullOrEmpty(I18n)) { arguments = arguments.AddRange("-l", "none"); } else { var vals = I18n.Split(new[] { ',', ';', ' ', '\r', '\n', '\t' }); arguments = arguments.AddRange("-l", string.Join(",", vals)); } return(arguments.ToString()); }
/// <summary> /// Create a remote worker with a hosted object /// </summary> /// <param name="ipcName"></param> /// <param name="maxShutdownTimeout"></param> /// <param name="remoteType"></param> protected MultiProcessWorkerClientBase(string ipcName, int maxShutdownTimeout, Type remoteType) : this(ProcessArguments.Create(ipcName, remoteType)) { MaxShutdownTimeout = maxShutdownTimeout; }
protected override string GenerateCommandLineCommands() { ProcessArguments arguments = null; if (!InvokeLinkerUsingMono) { arguments = ProcessArguments.Create("--verbose"); } else { var toolsPath = GetPathToMonoLinker(); Log.LogMessage(MessageImportance.High, $"Running monolinker from {toolsPath}."); arguments = ProcessArguments.Create(toolsPath); arguments = arguments.Add("--verbose"); } // add exclude features arguments = arguments.AddRange("--exclude-feature", "remoting", "--exclude-feature", "com", "--exclude-feature", "etw"); string coremode, usermode; switch ((WasmLinkMode)Enum.Parse(typeof(WasmLinkMode), LinkMode)) { case WasmLinkMode.SdkOnly: coremode = "link"; usermode = "copy"; break; case WasmLinkMode.Full: coremode = "link"; usermode = "link"; break; default: coremode = "copyused"; usermode = "copy"; break; } arguments = arguments.AddRange("-c", coremode, "-u", usermode); //the linker doesn't consider these core by default arguments = arguments.AddRange("-p", coremode, "WebAssembly.Bindings"); arguments = arguments.AddRange("-p", coremode, "WebAssembly.Net.Http"); arguments = arguments.AddRange("-p", coremode, "WebAssembly.Net.WebSockets"); if (!string.IsNullOrEmpty(LinkSkip)) { var skips = LinkSkip.Split(new[] { ';', ',', ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in skips) { arguments = arguments.AddRange("-p", "copy", s); } } arguments = arguments.AddRange("-out", OutputDir); arguments = arguments.AddRange("-d", FrameworkDir); arguments = arguments.AddRange("-d", Path.Combine(FrameworkDir, "Facades")); arguments = arguments.AddRange("-b", Debug.ToString()); arguments = arguments.AddRange("-v", Debug.ToString()); arguments = arguments.AddRange("-a", RootAssembly[0].GetMetadata("FullPath")); //we'll normally have to check most of the because the SDK references most framework asm by default //so let's enumerate upfront var frameworkAssemblies = new HashSet <string> (StringComparer.OrdinalIgnoreCase); foreach (var f in Directory.EnumerateFiles(FrameworkDir)) { frameworkAssemblies.Add(Path.GetFileNameWithoutExtension(f)); } foreach (var f in Directory.EnumerateFiles(Path.Combine(FrameworkDir, "Facades"))) { frameworkAssemblies.Add(Path.GetFileNameWithoutExtension(f)); } //add references for non-framework assemblies if (Assemblies != null) { foreach (var asm in Assemblies) { var p = asm.GetMetadata("FullPath"); if (frameworkAssemblies.Contains(Path.GetFileNameWithoutExtension(p))) { continue; } arguments = arguments.AddRange("-r", p); } } if (string.IsNullOrEmpty(I18n)) { arguments = arguments.AddRange("-l", "none"); } else { var vals = I18n.Split(new[] { ',', ';', ' ', '\r', '\n', '\t' }); arguments = arguments.AddRange("-l", string.Join(",", vals)); } return(arguments.ToString()); }
public static MultiProcessWorkerRunner Create(string[] args) { var processArguments = ProcessArguments.Create(args); return(processArguments != null ? new MultiProcessWorkerRunner(processArguments) : null); }