private bool isCompatibleVersion(XrayVersion xrayVersion)
 {
     if (XrayUtil.IsXrayVersionCompatible(xrayVersion.xray_version))
     {
         return(true);
     }
     return(false);
 }
 public static XrayStatus GetPing()
 {
     try
     {
         HttpResponseMessage responseFromXray = xray.PerformGetRequest("system/ping");
         string resultFromXray = parseXrayResponse(responseFromXray);
         return(XrayUtil.LoadXrayStatus(resultFromXray));
     } catch (Exception e)
     {
         throw new IOException(e.Message, e);
     }
 }
        public static async Task <XrayVersion> GetVersionAsync()
        {
            try
            {
                HttpResponseMessage responseFromXray = await xray.PerformGetRequestAsync("system/version");

                string resultFromXray = await parseXrayResponseAsync(responseFromXray);

                return(XrayUtil.LoadXrayVersion(resultFromXray));
            }
            catch (Exception e)
            {
                throw new IOException(e.Message, e);
            }
        }
        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);
            }
        }
        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;
            }
        }
Exemplo n.º 6
0
        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);
            }
        }