public static void EnsureRunning(int timeoutInMilliseconds) { if (EmulatorProcessController.IsRunning()) { EmulatorProcessController.InternalWaitForStorageEmulator(timeoutInMilliseconds); throw new EmulatorException(EmulatorErrorCode.AlreadyRunning); } ProcessWrapper processWrapper = new ProcessWrapper("AzureStorageEmulator.exe", "start /InProcess"); if (timeoutInMilliseconds == 0) { processWrapper.EnsureStarted(); return; } bool flag = false; StringBuilder stringBuilder = new StringBuilder(); if (!CheckStoragePrerequisites.CheckPrerequisites((string msg) => stringBuilder.Append(msg), out flag)) { if (!flag) { string str = stringBuilder.ToString(); if (!string.IsNullOrEmpty(str)) { throw new EmulatorException(EmulatorErrorCode.StartFailed, str); } throw new EmulatorException(EmulatorErrorCode.StartFailed); } try { Initialization initialization = new Initialization(false, false, true, null, null, false, false); initialization.PerformEmulatorInitialization(); } catch (Exception exception) { throw new EmulatorException(EmulatorErrorCode.InitializationRequired, exception); } } processWrapper.EnsureStarted(); EmulatorProcessController.InternalWaitForStorageEmulator(timeoutInMilliseconds); }
public static void Shutdown() { if (!EmulatorProcessController.IsRunning()) { throw new EmulatorException(EmulatorErrorCode.AlreadyStopped); } try { using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting("DevelopmentStorage-3D75486A-E34F-447c-BF4B-A35284FA8D96")) { eventWaitHandle.Set(); } } catch (WaitHandleCannotBeOpenedException waitHandleCannotBeOpenedException) { } Process[] instances = (new ProcessWrapper("AzureStorageEmulator.exe", "start /InProcess")).GetInstances(); for (int i = 0; i < (int)instances.Length; i++) { Process process = instances[i]; if (process.Id != Process.GetCurrentProcess().Id) { try { if (!process.WaitForExit(15000)) { process.Kill(); process.WaitForExit(15000); } } catch (InvalidOperationException invalidOperationException) { } catch (Win32Exception win32Exception) { } } } }
public void Stop() { EmulatorProcessController.Shutdown(); }
public void Start() { EmulatorProcessController.EnsureRunning(60000); }