Created
August 26, 2013 23:09
-
-
Save gblmarquez/6347787 to your computer and use it in GitHub Desktop.
Windows Azure emulator utility class to start, stop and kill: storage and compute emulators.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class AzureEmulatorManager | |
{ | |
public static AzureStorageEmulatorManager Storage = AzureStorageEmulatorManager.Instance; | |
public static AzureComputeEmulatorManager Compute = AzureComputeEmulatorManager.Instance; | |
} | |
public class AzureStorageEmulatorManager | |
{ | |
private const string StorageEmulatorProcessName = "DSServiceLDB"; | |
private const string EmulatorPath = @"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun.exe"; | |
public static AzureStorageEmulatorManager Instance = new AzureStorageEmulatorManager(); | |
public Process GetProcess() | |
{ | |
return Process.GetProcessesByName(StorageEmulatorProcessName).FirstOrDefault(); | |
} | |
public bool IsRunning() | |
{ | |
return GetProcess() != null; | |
} | |
public void Start() | |
{ | |
if (!IsRunning()) | |
{ | |
using (var process = Process.Start(EmulatorPath, "/devstore:start")) | |
{ | |
process.WaitForExit(); | |
} | |
} | |
} | |
public void Stop() | |
{ | |
if (IsRunning()) | |
{ | |
using (var process = Process.Start(EmulatorPath, "/devstore:shutdown")) | |
{ | |
process.WaitForExit(); | |
} | |
} | |
} | |
public void Kill() | |
{ | |
var process = GetProcess(); | |
if (process != null) | |
{ | |
process.Kill(); | |
} | |
} | |
} | |
public class AzureComputeEmulatorManager | |
{ | |
private const string ComputeEmulatorProcessName = "DFService"; | |
private const string ComputeEmulatorPath = @"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun.exe"; | |
public static AzureComputeEmulatorManager Instance = new AzureComputeEmulatorManager(); | |
public Process GetProcess() | |
{ | |
return Process.GetProcessesByName(ComputeEmulatorProcessName).FirstOrDefault(); | |
} | |
public bool IsRunning() | |
{ | |
return GetProcess() != null; | |
} | |
public void Start() | |
{ | |
if (!IsRunning()) | |
{ | |
using (var process = Process.Start(ComputeEmulatorPath, "/devfabric:start")) | |
{ | |
process.WaitForExit(); | |
} | |
} | |
} | |
public void Stop() | |
{ | |
if (IsRunning()) | |
{ | |
using (var process = Process.Start(ComputeEmulatorPath, "/devfabric:shutdown")) | |
{ | |
process.WaitForExit(); | |
} | |
} | |
} | |
public void Kill() | |
{ | |
var process = GetProcess(); | |
if (process != null) | |
{ | |
process.Kill(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment