示例#1
0
        /// <summary>
        /// Creates the Process which will run the service app.
        /// </summary>
        private void CreateProcess()
        {
            _process = _processFactory.CreateProcess();
            int sacsProcessId          = Process.GetCurrentProcess().Id;
            ProcessStartInfo startInfo = new ProcessStartInfo(ServiceApp.AppFilePath);

            startInfo.WorkingDirectory       = Path.GetDirectoryName(ServiceApp.AppFilePath);
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.ErrorDialog            = false;
            startInfo.RedirectStandardInput  = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;

            if (ApplicationSettings.Current.EnableCustomUserLogins)
            {
                _process.ArgumentObject["name"]  = ServiceApp.Name;
                _process.ArgumentObject["owner"] = sacsProcessId;
                if (!string.IsNullOrWhiteSpace(ServiceApp.Parameters))
                {
                    _process.ArgumentObject["parameters"] = ServiceApp.Parameters;
                }
            }
            else
            {
                // keeping this older feature until testing is complete.
                var arguments = new { name = ServiceApp.Name, action = "hide", owner = sacsProcessId, parameters = ServiceApp.Parameters };
                startInfo.Arguments = JsonConvert.SerializeObject(arguments);
            }

            if (!string.IsNullOrWhiteSpace(ServiceApp.Username))
            {
                startInfo.Domain   = UserUtilities.GetDomain(ServiceApp.Username);
                startInfo.UserName = UserUtilities.GetUserName(ServiceApp.Username);
            }

            _process.StartInfo = startInfo;
        }