/// <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; }
public void fromConfiguration_setIsDexterHomeEnabled() { // given var config = new Configuration() { IsDexterHomeEnabled = true }; // when var dexterInfo = DexterInfo.fromConfiguration(config); // then Assert.AreEqual(true, dexterInfo.IsDexterHomeEnabled); }
/// <summary> /// Validates Dexter configuration /// </summary> /// <param name="config">configuration</param> /// <returns>true, if validation was successfull </returns> private bool ValidateConfiguration(Configuration config) { DexterInfo dexterInfo = DexterInfo.fromConfiguration(config); string validationResult; if (!dexterInfoValidator.ValidateDexterPath(dexterInfo)) { MessageBox.Show("Dexter wasn't found in given path. You cannot perform analysis until you set a proper path.", "Dexter error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!config.standalone && !dexterInfoValidator.ValidateServerConnection(dexterInfo, out validationResult)) { DialogResult result = MessageBox.Show("Couldn't connect to Dexter server. Please check server address in Dexter/Settings window. Continue in standalone mode?", "Dexter warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { config.standalone = true; return(true); } else { return(false); } } else { if (!config.standalone && !dexterInfoValidator.ValidateUserCredentials(dexterInfo, out validationResult)) { DialogResult result = MessageBox.Show("Couldn't login to Dexter server. Please check user credentials in Dexter/Settings window. Continue in standalone mode?", "Dexter warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { config.standalone = true; return(true); } else { return(false); } } } return(true); }