Skip to content

Commit

Permalink
ChildProcessFactory.Create - Add assemblyLocation optional param, use…
Browse files Browse the repository at this point in the history
…ful for scenarios like those outlined in red-gate#6
  • Loading branch information
amaitland committed Dec 16, 2015
1 parent 7cb0541 commit 6fe8a3e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
14 changes: 11 additions & 3 deletions RedGate.AppHost.Server/ChildProcessFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace RedGate.AppHost.Server
using System.IO;
using System.Reflection;

namespace RedGate.AppHost.Server
{
public class ChildProcessFactory
{
public IChildProcessHandle Create(string assemblyName, bool openDebugConsole = false, bool is64Bit = false, bool monitorHostProcess = false)
public IChildProcessHandle Create(string assemblyName, string assemblyLocation = null, bool openDebugConsole = false, bool is64Bit = false, bool monitorHostProcess = false)
{
IProcessStartOperation processStarter;

Expand All @@ -15,10 +18,15 @@ public IChildProcessHandle Create(string assemblyName, bool openDebugConsole = f
processStarter = new ProcessStarter32Bit();
}

if (assemblyLocation == null)
{
assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}

return new RemotedProcessBootstrapper(
new StartProcessWithTimeout(
new StartProcessWithJobSupport(
processStarter))).Create(assemblyName, openDebugConsole, monitorHostProcess);
processStarter))).Create(assemblyName, assemblyLocation, openDebugConsole, monitorHostProcess);
}
}
}
2 changes: 1 addition & 1 deletion RedGate.AppHost.Server/IProcessStartOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace RedGate.AppHost.Server
{
internal interface IProcessStartOperation
{
Process StartProcess(string assemblyName, string remotingId, bool openDebugConsole, bool monitorHostProcess);
Process StartProcess(string assemblyName, string assemblyLocation, string remotingId, bool openDebugConsole, bool monitorHostProcess);
}
}
4 changes: 2 additions & 2 deletions RedGate.AppHost.Server/ProcessStarter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ internal abstract class ProcessStarter : IProcessStartOperation
{
protected abstract string ProcessFileName { get; }

public Process StartProcess(string assemblyName, string remotingId, bool openDebugConsole, bool monitorHostProcess)
public Process StartProcess(string assemblyName, string assemblyLocation, string remotingId, bool openDebugConsole, bool monitorHostProcess)
{
string executingDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string quotedAssemblyArg = "\"" + Path.Combine(executingDirectory, assemblyName) + "\"";
string quotedAssemblyArg = "\"" + Path.Combine(assemblyLocation, assemblyName) + "\"";

var processToStart = Path.Combine(executingDirectory, ProcessFileName);
var processArguments = string.Join(" ", new[]
Expand Down
4 changes: 2 additions & 2 deletions RedGate.AppHost.Server/RemotedProcessBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public RemotedProcessBootstrapper(IProcessStartOperation processBootstrapper)
m_ProcessBootstrapper = processBootstrapper;
}

public IChildProcessHandle Create(string assemblyName, bool openDebugConsole, bool monitorHostProcess)
public IChildProcessHandle Create(string assemblyName, string assemblyLocation, bool openDebugConsole, bool monitorHostProcess)
{
Process process = null;
try
{
process = m_ProcessBootstrapper.StartProcess(assemblyName, m_RemotingId, openDebugConsole, monitorHostProcess);
process = m_ProcessBootstrapper.StartProcess(assemblyName, assemblyLocation, m_RemotingId, openDebugConsole, monitorHostProcess);
return new ChildProcessHandle(InitializeRemoting());
}
catch
Expand Down
4 changes: 2 additions & 2 deletions RedGate.AppHost.Server/StartProcessWithJobSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public StartProcessWithJobSupport(IProcessStartOperation wrappedProcessStarter)
m_WrappedProcessStarter = wrappedProcessStarter;
}

public Process StartProcess(string assemblyName, string remotingId, bool openDebugConsole, bool monitorHostProcess)
public Process StartProcess(string assemblyName, string assemblyLocation, string remotingId, bool openDebugConsole, bool monitorHostProcess)
{
var process = m_WrappedProcessStarter.StartProcess(assemblyName, remotingId, openDebugConsole, monitorHostProcess);
var process = m_WrappedProcessStarter.StartProcess(assemblyName, assemblyLocation, remotingId, openDebugConsole, monitorHostProcess);

if (Job.CanAssignProcessToJobObject(process))
new Job().AssignProcessToJobObject(process);
Expand Down
4 changes: 2 additions & 2 deletions RedGate.AppHost.Server/StartProcessWithTimeout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public StartProcessWithTimeout(IProcessStartOperation wrappedProcessStarter)
m_WrappedProcessStarter = wrappedProcessStarter;
}

public Process StartProcess(string assemblyName, string remotingId, bool openDebugConsole, bool monitorHostProcess)
public Process StartProcess(string assemblyName, string assemblyLocation, string remotingId, bool openDebugConsole, bool monitorHostProcess)
{
using (var signal = new EventWaitHandle(false, EventResetMode.ManualReset, remotingId))
{
var process = m_WrappedProcessStarter.StartProcess(assemblyName, remotingId, openDebugConsole, monitorHostProcess);
var process = m_WrappedProcessStarter.StartProcess(assemblyName, assemblyLocation, remotingId, openDebugConsole, monitorHostProcess);
WaitForReadySignal(signal);
return process;
}
Expand Down

0 comments on commit 6fe8a3e

Please sign in to comment.