Пример #1
0
        internal void LaunchInitializationElevated()
        {
            if (this.server != null && this.server.EndsWith("\\\\"))
            {
                this.server = this.server.Substring(0, this.server.Length - 1);
            }
            Process process = new Process()
            {
                EnableRaisingEvents = true
            };
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("init");
            stringBuilder.Append(" /inprocess");
            if (this.forceCreate)
            {
                stringBuilder.Append(" /forcecreate");
            }
            if (this.skipCreate)
            {
                stringBuilder.Append(" /skipcreate");
            }
            if (this.autoDetect)
            {
                stringBuilder.Append(" /autodetect");
            }
            if (this.reservePorts)
            {
                stringBuilder.Append(" /reserveports");
            }
            if (this.unreservePorts)
            {
                stringBuilder.Append(" /unreserveports");
            }
            if (!string.IsNullOrWhiteSpace(this.server))
            {
                stringBuilder.AppendFormat(" /server \"{0}", this.server);
            }
            ProcessWrapper processWrapper = new ProcessWrapper("AzureStorageEmulator.exe", stringBuilder.ToString());

            process.StartInfo             = processWrapper.StartInfo;
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            process.StartInfo.Verb        = "runas";
            try
            {
                process.Start();
                process.WaitForExit();
            }
            catch (Win32Exception win32Exception1)
            {
                Win32Exception win32Exception = win32Exception1;
                throw new EmulatorException(EmulatorErrorCode.UnknownError, win32Exception.Message, win32Exception);
            }
            EmulatorErrorCode exitCode = (EmulatorErrorCode)process.ExitCode;

            if (!Enum.IsDefined(typeof(EmulatorErrorCode), (int)exitCode))
            {
                exitCode = EmulatorErrorCode.UnknownError;
            }
            if (exitCode != EmulatorErrorCode.Success)
            {
                throw new EmulatorException(exitCode);
            }
        }