/// <summary> /// Validates configuration and performs analysis /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> protected override void CommandClicked(object sender, EventArgs e) { Configuration config = ConfigurationProvider.Load(); if (!ValidateConfiguration(config)) { return; } OutputWindowPane outputPane = CreatePane("Dexter"); outputPane.Clear(); outputPane.Activate(); System.Threading.Tasks.Task.Run(() => { dexter = new Dexter(config); DataReceivedEventHandler writeToOutputPane = (s, e1) => outputPane.OutputString(e1.Data + Environment.NewLine); dexter.OutputDataReceived += writeToOutputPane; dexter.ErrorDataReceived += writeToOutputPane; OnAnalysisStarted(EventArgs.Empty); Result result = dexter.Analyse(); OnAnalysisFinished(EventArgs.Empty); ReportResult(result); }); }
/// <summary> /// Creates new Dexter instance /// </summary> /// <param name="dexterPath">path to a dexter-executor.jar</param> /// <param name="configuration">Configuration</param> public Dexter(Configuration configuration) { this.configuration = configuration; if (configuration == null) throw new ArgumentNullException("configuration"); if (!configuration.IsDexterFound) throw new FileNotFoundException("Cannot find dexter in specified path", configuration.DexterExecutorPath); configuration.Save(); }
public void Init() { configuration = new Configuration() { dexterHome = "D:/Applications/dexter/0.9.2/dexter-cli_0.9.2_32/", projectName = "TestData", type = "PROJECT", sourceDir = { AppDomain.CurrentDomain.BaseDirectory + "../../TestData/SampleCppProject/" }, headerDir = { AppDomain.CurrentDomain.BaseDirectory + "../../TestData/SampleCppProject/" }, projectFullPath = AppDomain.CurrentDomain.BaseDirectory + "../../TestData/SampleCppProject/", dexterServerPort = "0", dexterServerIp = "dexter-server" }; }
public void TestSaveLoad() { Configuration config = new Configuration() { dexterHome = "TestPath" }; string configPath = AppDomain.CurrentDomain.BaseDirectory + "../../TestData/test-config.json"; config.Save(configPath); Configuration loadedConfig = Configuration.Load(configPath); Assert.AreEqual("TestPath", loadedConfig.dexterHome); }
/// <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); }
/// <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; }
/// <summary> /// Dreates DexterInfo from Configuration /// </summary> /// <param name="configuration">Dexter configuration</param> /// <returns>DexterInfo</returns> public static DexterInfo fromConfiguration(Configuration configuration) { return new DexterInfo() { dexterHome = configuration.dexterHome, dexterServerIp = configuration.dexterServerIp, dexterServerPort = int.Parse(configuration.dexterServerPort), userName = configuration.userName, userPassword = configuration.userPassword, standalone = configuration.standalone }; }