private bool isCompatibleVersion(XrayVersion xrayVersion)
 {
     if (XrayUtil.IsXrayVersionCompatible(xrayVersion.xray_version))
     {
         return(true);
     }
     return(false);
 }
        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;
            }
        }
예제 #3
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);
            }
        }