public RemoteExecution(Diagnostics.Process process, string className, string methodName, string exceptionFile)
 {
     Process        = process;
     ClassName      = className;
     MethodName     = methodName;
     _exceptionFile = exceptionFile;
 }
Example #2
0
        public static async Task <int> CompleteAsync(
            this Diagnostics.Process process,
            CancellationToken?cancellationToken = null) =>
        await Task.Run(() =>
        {
            process.WaitForExit();

            return(Task.FromResult(process.ExitCode));
        }, cancellationToken ?? CancellationToken.None);
        private static RemoteExecution Execute(MethodInfo methodInfo, string[] args, ProcessStartInfo psi)
        {
            Type   declaringType = methodInfo.DeclaringType;
            string className     = declaringType.FullName;
            string methodName    = methodInfo.Name;
            string exceptionFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            string dotnetExecutable = Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string thisAssembly     = typeof(RemoteExecutor).Assembly.Location;
            var    assembly         = (Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly());
            string entryAssemblyWithoutExtension = Path.Combine(Path.GetDirectoryName(assembly.Location),
                                                                Path.GetFileNameWithoutExtension(assembly.Location));
            string runtimeConfig = GetApplicationArgument("--runtimeconfig");

            if (runtimeConfig == null)
            {
                runtimeConfig = entryAssemblyWithoutExtension + ".runtimeconfig.json";
            }
            string depsFile = GetApplicationArgument("--depsfile");

            if (depsFile == null)
            {
                depsFile = entryAssemblyWithoutExtension + ".deps.json";
            }

            if (psi == null)
            {
                psi = new ProcessStartInfo();
            }
            psi.FileName = dotnetExecutable;

            var argumentList = new List <string>();

            argumentList.AddRange(new[] { "exec", "--runtimeconfig", runtimeConfig, "--depsfile", depsFile, thisAssembly,
                                          className, methodName, exceptionFile });
            if (args != null)
            {
                argumentList.AddRange(args);
            }

            psi.Arguments = string.Join(" ", argumentList);
            Diagnostics.Process process = Diagnostics.Process.Start(psi);

            return(new RemoteExecution(process, className, methodName, exceptionFile));
        }
Example #4
0
 public unsafe ProcessBinaryWriter(Diagnostics.Process process, IntPtr baseAddress, ulong size) : this(baseAddress, InitializeStream((uint)process.Handle, baseAddress, size))
 {
     this.process  = process;
     this.hProcess = (uint)process.Handle;
 }