public async Task <IActionResult> PutUniqueTags(string Email, UniqueTags uniqueTags)
        {
            if (Email != uniqueTags.Email)
            {
                return(BadRequest());
            }

            _context.Entry(uniqueTags).State = EntityState.Modified;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UniqueTagsExists(Email))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <UniqueTags> > PostUniqueTags(UniqueTags uniqueTags)
        {
            _context.UniqueTags.Add(uniqueTags);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUniqueTags", new { id = uniqueTags.Email }, uniqueTags));
        }
Example #3
0
        /// <summary>
        /// Transfer concurrent data from scan to analyze result with sorted, simplier types for callers
        /// </summary>
        public void PrepareReport()
        {
            Metadata.CPUTargets         = CPUTargets.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.AppTypes           = AppTypes.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.OSTargets          = OSTargets.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.UniqueDependencies = UniqueDependencies.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.UniqueTags         = UniqueTags.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.CloudTargets       = CloudTargets.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.PackageTypes       = PackageTypes.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.FileExtensions     = FileExtensions.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.Outputs            = Outputs.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.Targets            = Targets.ToImmutableSortedDictionary().Keys.ToList();
            Metadata.Languages          = Languages.ToImmutableSortedDictionary();

            foreach (MetricTagCounter metricTagCounter in TagCounters.Values)
            {
                Metadata?.TagCounters?.Add(metricTagCounter);
            }
        }
Example #4
0
        /// <summary>
        /// Assist in aggregating reporting properties of matches as they are added
        /// Keeps helpers isolated from MetaData class which is used as a result object to keep pure
        /// </summary>
        /// <param name="matchRecord"></param>
        public void AddMatchRecord(MatchRecord matchRecord)
        {
            bool allowAdd = true;

            //special handling for standard characteristics in report
            foreach (var tag in matchRecord.Tags ?? new string[] { })
            {
                switch (tag)
                {
                case "Metadata.Application.Author":
                case "Metadata.Application.Publisher":
                    Metadata.Authors = ExtractValue(matchRecord.Sample);
                    break;

                case "Metadata.Application.Description":
                    Metadata.Description = ExtractValue(matchRecord.Sample);
                    break;

                case "Metadata.Application.Name":
                    Metadata.ApplicationName = ExtractValue(matchRecord.Sample);
                    break;

                case "Metadata.Application.Version":
                    Metadata.SourceVersion = ExtractValue(matchRecord.Sample);
                    break;

                case "Metadata.Application.Target.Processor":
                    _ = CPUTargets.TryAdd(ExtractValue(matchRecord.Sample).ToLower(), 0);
                    break;

                case "Metadata.Application.Output.Type":
                    _ = Outputs.TryAdd(ExtractValue(matchRecord.Sample).ToLower(), 0);
                    break;

                case "Dependency.SourceInclude":
                    allowAdd = false;     //design to keep noise out of detailed match list
                    break;

                default:
                    if (tag.Contains("Metric."))
                    {
                        _ = TagCounters.TryAdd(tag, new MetricTagCounter()
                        {
                            Tag = tag
                        });
                    }
                    else if (tag.Contains(".Platform.OS"))
                    {
                        _ = OSTargets.TryAdd(tag.Substring(tag.LastIndexOf('.', tag.Length - 1) + 1), 0);
                    }
                    else if (tag.Contains("CloudServices.Hosting"))
                    {
                        _ = CloudTargets.TryAdd(tag.Substring(tag.LastIndexOf('.', tag.Length - 1) + 1), 0);
                    }
                    break;
                }
            }

            //Special handling; attempt to detect app types...review for multiple pattern rule limitation
            string solutionType = DetectSolutionType(matchRecord);

            if (!string.IsNullOrEmpty(solutionType))
            {
                _ = AppTypes.TryAdd(solutionType, 0);
            }

            bool CounterOnlyTagSet = false;
            var  selected          = TagCounters.Where(x => matchRecord.Tags.Any(y => y.Contains(x.Value.Tag ?? "")));

            foreach (var select in selected)
            {
                CounterOnlyTagSet = true;
                select.Value.IncrementCount();
            }

            //omit adding if ther a counter metric tag
            if (!CounterOnlyTagSet)
            {
                //update list of unique tags as we go
                foreach (string tag in matchRecord.Tags ?? new string[] { })
                {
                    _ = UniqueTags.TryAdd(tag, 0);
                }

                if (allowAdd)
                {
                    Metadata?.Matches?.Add(matchRecord);
                }
            }
            else
            {
                Metadata.IncrementTotalMatchesCount(-1);//reduce e.g. tag counters not included as detailed match
            }
        }