Esempio n. 1
0
        /// <summary>
        /// Creates (but doesn't start) new Dexter process
        /// </summary>
        /// <param name="createUser">if true, this process will create new user account</param>
        private void CreateDexterProcess(bool createUser = false)
        {
            string configFlag          = File.Exists(Configuration.DefaultConfigurationPath) ? " -f " + Configuration.DefaultConfigurationPath : "";
            string createUserFlag      = createUser ? " -c " : "";
            string createXmlResultFlag = " -x ";
            string credentialsParams   = (configuration.standalone && !createUser)
                ? " -s "
                : " -u " + configuration.userName + " -p " + configuration.userPassword + " -h " + configuration.dexterServerIp + " -o " + configuration.dexterServerPort;
            string resultFileFormatFlag = " -F xml";

            dexterProcess = new Process();

            DexterInfo dexterInfo = DexterInfo.fromConfiguration(configuration);

            if (LanguageDetector.IsCodeModelLanguageCSharp())
            {
                if (!File.Exists(configuration.DexterCSPath))
                {
                    throw new DexterRuntimeException("DexterCS.exe not found in \"" + configuration.DexterCSPath + "\"");
                }

                dexterProcess.StartInfo = new ProcessStartInfo()
                {
                    FileName               = configuration.DexterCSPath,
                    Arguments              = createUserFlag + createXmlResultFlag + configFlag + credentialsParams + resultFileFormatFlag,
                    WorkingDirectory       = Path.GetDirectoryName(configuration.DexterCSPath),
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
            }
            else
            {
                if (!File.Exists(configuration.DexterExecutorPath))
                {
                    throw new DexterRuntimeException("dexter-executor.jar not found in \"" + configuration.DexterExecutorPath + "\"");
                }

                dexterProcess.StartInfo = new ProcessStartInfo()
                {
                    FileName               = "java.exe",
                    Arguments              = "-jar " + configuration.DexterExecutorPath + createUserFlag + createXmlResultFlag + configFlag + credentialsParams,
                    WorkingDirectory       = Path.GetDirectoryName(configuration.DexterExecutorPath),
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                };
            }

            dexterProcess.OutputDataReceived += OutputDataReceived;
            dexterProcess.ErrorDataReceived  += ErrorDataReceived;
            dexterProcess.Disposed           += (s, e) => dexterProcess = null;
        }