private bool isCompatibleVersion(XrayVersion xrayVersion) { if (XrayUtil.IsXrayVersionCompatible(xrayVersion.xray_version)) { return(true); } return(false); }
private async Task PerformTestConnectionAsync() { try { if (!txtBoxServer.Text.EndsWith("/")) { txtBoxServer.Text += "/"; } HttpUtils.InitClient(txtBoxServer.Text, txtBoxUser.Text, txtBoxPassword.Text); XrayStatus xrayStatus = await HttpUtils.GetPingAsync(); if (xrayStatus == null) { testConnectionField.Text = "Failed to perform ping."; return; } XrayVersion xrayVersion = await HttpUtils.GetVersionAsync(); if (!isCompatibleVersion(xrayVersion)) { testConnectionField.Text = XrayUtil.GetMinimumXrayVersionErrorMessage(xrayVersion.xray_version); return; } // Check components permissions. String message = await HttpUtils.PostComponentToXrayAsync(new Components("", Util.PREFIX + "testComponent")); if (String.IsNullOrEmpty(message)) { testConnectionField.Text = "Received Xray version: " + xrayVersion.xray_version; } else { testConnectionField.Text = message; } } catch (IOException ioe) { testConnectionField.Text = ioe.Message; await OutputLog.ShowMessageAsync("Caught exception when performing test connection: " + ioe); } }
private void performTestConnection(object sender, EventArgs e) { try { if (!txtBoxServer.Text.EndsWith("/")) { txtBoxServer.Text += "/"; } HttpUtils.InitClient(txtBoxServer.Text, txtBoxUser.Text, txtBoxPassword.Text); XrayStatus xrayStatus = HttpUtils.GetPing(); if (xrayStatus == null) { testConnectionField.Text = "Failed to perfom ping."; return; } XrayVersion xrayVersion = HttpUtils.GetVersion(); if (!isCompatibleVersion(xrayVersion)) { testConnectionField.Text = "ERROR: Unsupported Xray version: " + xrayVersion.xray_version + ", version " + XrayUtil.MIN_XRAY_VERSION + " or above required."; return; } // Check components permissions. String message = HttpUtils.PostComponentToXray(new Components("", Util.PREFIX + "testComponent")); if (String.IsNullOrEmpty(message)) { testConnectionField.Text = "Received Xray version: " + xrayVersion.xray_version; } else { testConnectionField.Text = message; } } catch (IOException ioe) { testConnectionField.Text = ioe.Message; OutputLog.ShowMessage("Caught exception when performing test connection: " + ioe); } }
public async Task LoadAsync(RefreshType refreshType, HashSet <Severity> severities) { this.EnableRefreshButton = false; DataService dataService = DataService.Instance; RaisePropertyChanged("SelectedKey"); try { String solutionDir = await GetSolutionDirAsync(); if (String.IsNullOrWhiteSpace(solutionDir)) { return; } XrayVersion xrayVersion = await HttpUtils.GetVersionAsync(); if (!XrayUtil.IsXrayVersionCompatible(xrayVersion.xray_version)) { String errorMessage = XrayUtil.GetMinimumXrayVersionErrorMessage(xrayVersion.xray_version); await OutputLog.ShowMessageAsync(errorMessage); return; } // Steps to run: // 1. Trigger CLI to collect json info to a file. // 2. Read the info. // 3. Send dependencies to Xray. // 4. Get response and build the dependencies tree. // Running CLI - this is the returned output. String returnedText = await Task.Run(() => Util.GetCLIOutputAsync(solutionDir)); // Load projects from output. Projects projects = Util.LoadNugetProjects(returnedText); if (projects.projects == null || projects.projects.Length == 0) { await OutputLog.ShowMessageAsync("No projects were found."); return; } Artifacts artifacts = null; switch (refreshType) { case RefreshType.Hard: { // Get information for all dependencies. Ignore the cache. artifacts = await dataService.RefreshArtifactsAsync(true, projects); break; } case RefreshType.Soft: { // Get information only for the delta. Means only new dependencies will be added. artifacts = await dataService.RefreshArtifactsAsync(false, projects); break; } } dataService.Severities = severities; dataService.populateRootElements(projects); this.Artifacts = new ObservableCollection <ArtifactViewModel>(); foreach (string key in dataService.RootElements) { Artifacts.Add(new ArtifactViewModel(key)); } } catch (Exception e) { dataService.ClearAllComponents(); await OutputLog.ShowMessageAsync(e.Message); await OutputLog.ShowMessageAsync(e.StackTrace); } finally { this.EnableRefreshButton = true; } }
public void Load(RefreshType refreshType, HashSet <Severity> severities) { DataService dataService = DataService.Instance; RaisePropertyChanged("SelectedKey"); try { String solutionDir = GetSolutionDir(); if (String.IsNullOrWhiteSpace(solutionDir)) { return; } XrayVersion xrayVersion = HttpUtils.GetVersion(); if (!XrayUtil.IsXrayVersionCompatible(xrayVersion.xray_version)) { String errorMessage = "ERROR: Unsupported Xray version: " + xrayVersion.xray_version + ", version " + XrayUtil.MIN_XRAY_VERSION + " or above required."; OutputLog.ShowMessage(errorMessage); return; } // Steps to run: // Trigger CLI to collect json info to a file // Read the info // Send dependencies to Xray // Get response and build the dependencies tree // Running CLI - this is the returned output. String returnedText = Util.GetCLIOutput(solutionDir); // Load projects from output Projects projects = Util.LosdNugetProjects(returnedText); if (projects.projects == null || projects.projects.Length == 0) { OutputLog.ShowMessage("No projects were found."); return; } List <Components> components = new List <Components>(); Artifacts artifacts = null; switch (refreshType) { case RefreshType.Hard: { // Get information for all dependencies. Ignore the cache artifacts = dataService.RefreshArtifacts(true, projects); break; } case RefreshType.Soft: { // Get information only for the delta. Means only new dependencies will be added. artifacts = dataService.RefreshArtifacts(false, projects); break; } } dataService.Severities = severities; dataService.populateRootElements(projects); this.Artifacts = new ObservableCollection <ArtifactViewModel>(); foreach (string key in dataService.RootElements) { Artifacts.Add(new ArtifactViewModel(key)); } } catch (IOException ioe) { dataService.ClearAllComponents(); OutputLog.ShowMessage(ioe.Message); OutputLog.ShowMessage(ioe.StackTrace); } catch (HttpRequestException he) { dataService.ClearAllComponents(); OutputLog.ShowMessage(he.Message); OutputLog.ShowMessage(he.StackTrace); } }