Created
May 27, 2013 22:24
-
-
Save codingoutloud/5659370 to your computer and use it in GitHub Desktop.
Power Switch for the Azure Emulator processes. Make it easy to programmatically turn Storage or Compute emulation On or Off.
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
using System; | |
using System.Diagnostics; | |
using System.IO; | |
namespace DevPartners | |
{ | |
/// <summary> | |
/// Power Switch for the Azure Emulator processes. Make it easy to programmatically turn Storage or Compute emulation On or Off. | |
/// </summary> | |
public static class AzureEmulatorPowerSwitch | |
{ | |
public static readonly string CsRunExeName = "csrun.exe"; | |
public static readonly string CsRunStartStorageEmulatorParams = "/devstore"; | |
public static readonly string CsRunStopStorageEmulatorParams = "/devstore:shutdown"; | |
public static readonly string CsRunStartComputeEmulatorParams = "/devfabric"; | |
public static readonly string CsRunStopComputeEmulatorParams = "/devfabric:shutdown"; | |
public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(2); | |
public static string GetAzureEmulatorDirectoryPath(string version = default(string)) | |
{ | |
const string windowsAzureEmulatorInstallPath_EnvironmentVariableName = "WindowsAzureEmulatorInstallPath"; // will probably NEVER be visible to this process - bad choice - see results of registry spelunking down below | |
var windowsAzureEmulatorInstallPath = | |
Environment.GetEnvironmentVariable(windowsAzureEmulatorInstallPath_EnvironmentVariableName, | |
EnvironmentVariableTarget.User); | |
if (windowsAzureEmulatorInstallPath == null) | |
windowsAzureEmulatorInstallPath = @"C:\Program Files\Microsoft SDKs\Windows Azure\Emulator"; | |
return windowsAzureEmulatorInstallPath; | |
} | |
public static string GetAzureCsrunExePath(string version = default(string)) | |
{ | |
return Path.Combine(GetAzureEmulatorDirectoryPath(version), AzureEmulatorStarter.CsRunExeName); | |
} | |
public static void StartStorage() | |
{ | |
ExecuteCsRunExeWithParam(AzureEmulatorStarter.CsRunStartStorageEmulatorParams); | |
} | |
public static void StopStorage() | |
{ | |
ExecuteCsRunExeWithParam(AzureEmulatorStarter.CsRunStopStorageEmulatorParams); | |
// process name is probably "DSServiceLDB.exe" but we don't care about such details; let csrun.exe deal with it | |
} | |
public static void StartCompute() | |
{ | |
ExecuteCsRunExeWithParam(AzureEmulatorStarter.CsRunStartComputeEmulatorParams); | |
} | |
public static void StopCompute() | |
{ | |
ExecuteCsRunExeWithParam(AzureEmulatorStarter.CsRunStopComputeEmulatorParams); | |
} | |
private static void ExecuteCsRunExeWithParam(string csRunParam) | |
{ | |
using (var csrun = Process.Start(GetAzureCsrunExePath(), csRunParam)) | |
{ | |
var timeoutInMilliseconds = Convert.ToInt32(DefaultTimeout.TotalMilliseconds); | |
csrun.WaitForExit(timeoutInMilliseconds); | |
} | |
} | |
/* registry setting spelunking shows... | |
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Features\8C975987EDDF6EF4A84863F619256BE3 | |
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\A1592A1D4CA5CF551B84E9BA2B9E2ADA | |
8C975987EDDF6EF4A84863F619256BE3 | |
Value Data = ... | |
This key: | |
HKEY_CLASSES_ROOT\Installer\UpgradeCodes\905421376DAC49546AAD863467651137 | |
Has this value name: | |
8C975987EDDF6EF4A84863F619256BE3 | |
No value data | |
-- FROM POWERSHELL -- | |
PS HKLM:\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting> Get-ChildItem . | |
Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting | |
Name Property | |
---- -------- | |
v1.8 InstallPath : C:\Program Files\Microsoft SDKs\Windows Azure\.NET | |
SDK\2012-10\ | |
SchemaPath : C:\Program Files\Microsoft SDKs\Windows Azure\.NET | |
SDK\2012-10\schemas | |
FullVersion : 1.8.31004.1351 | |
MajorVersion : 1 | |
ServicePack : 0 | |
ToolsVersionSupportLevel : 16 | |
v2.0 InstallPath : C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\v2.0\ | |
SchemaPath : C:\Program Files\Microsoft SDKs\Windows Azure\.NET | |
SDK\v2.0\schemas | |
FullVersion : 2.0.6493.2 | |
MajorVersion : 2 | |
ServicePack : 0 | |
ToolsVersionSupportLevel : 16 | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment