protected virtual TContext DetermineApplicabilityAndAnalyze(
            TOptions options,
            IEnumerable <ISkimmer <TContext> > skimmers,
            TContext rootContext,
            string target,
            HashSet <string> disabledSkimmers)
        {
            var context = CreateContext(options, rootContext.Logger, rootContext.RuntimeErrors, target);

            context.Policy = rootContext.Policy;

            if (context.TargetLoadException != null)
            {
                Errors.LogExceptionLoadingTarget(context);
                context.Dispose();
                return(context);
            }
            else if (!context.IsValidAnalysisTarget)
            {
                Warnings.LogExceptionInvalidTarget(context);
                context.Dispose();
                return(context);
            }

            // Analyzing '{0}'...
            context.Logger.AnalyzingTarget(context);

            IEnumerable <ISkimmer <TContext> > applicableSkimmers = DetermineApplicabilityForTarget(skimmers, context, disabledSkimmers);

            AnalyzeTarget(applicableSkimmers, context, disabledSkimmers);

            return(context);
        }
        protected virtual TContext DetermineApplicabilityAndAnalyze(
            TContext context,
            IEnumerable <Skimmer <TContext> > skimmers,
            ISet <string> disabledSkimmers)
        {
            // insert results caching replay logic here

            if (context.TargetLoadException != null)
            {
                Errors.LogExceptionLoadingTarget(context);
                context.Dispose();
                return(context);
            }
            else if (!context.IsValidAnalysisTarget)
            {
                Warnings.LogExceptionInvalidTarget(context);
                context.Dispose();
                return(context);
            }

            context.Logger.AnalyzingTarget(context);
            IEnumerable <Skimmer <TContext> > applicableSkimmers = DetermineApplicabilityForTarget(context, skimmers, disabledSkimmers);

            AnalyzeTarget(context, applicableSkimmers, disabledSkimmers);

            return(context);
        }
        protected virtual TContext DetermineApplicabilityAndAnalyze(
            TOptions options,
            IEnumerable <Skimmer <TContext> > skimmers,
            TContext rootContext,
            string target,
            HashSet <string> disabledSkimmers)
        {
            var context = CreateContext(options, rootContext.Logger, rootContext.RuntimeErrors, target);

            context.Policy = rootContext.Policy;

            if (options.Verbose)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture,
                                                @"Analyzing '{0}'..",
                                                context.TargetUri.GetFileName()));
            }

            if (options.ComputeFileHashes)
            {
                _resultsCachingLogger.HashToResultsMap.TryGetValue(context.Hashes.Sha256, out List <Tuple <ReportingDescriptor, Result> > cachedResults);
                _resultsCachingLogger.HashToNotificationsMap.TryGetValue(context.Hashes.Sha256, out List <Notification> cachedNotifications);

                bool replayCachedData = (cachedResults != null || cachedNotifications != null);

                if (replayCachedData)
                {
                    context.Logger.AnalyzingTarget(context);

                    if (cachedResults != null)
                    {
                        foreach (Tuple <ReportingDescriptor, Result> cachedResult in cachedResults)
                        {
                            if (cachedResult.Item2.Locations?.Count > 0)
                            {
                                cachedResult.Item2.Locations[0].PhysicalLocation.ArtifactLocation.Uri = context.TargetUri;
                            }
                            context.Logger.Log(cachedResult.Item1, cachedResult.Item2);
                        }
                    }

                    if (cachedNotifications != null)
                    {
                        foreach (Notification notification in cachedNotifications)
                        {
                            context.Logger.LogConfigurationNotification(notification);
                        }
                    }
                    return(context);
                }
            }

            if (context.TargetLoadException != null)
            {
                Errors.LogExceptionLoadingTarget(context);
                context.Dispose();
                return(context);
            }
            else if (!context.IsValidAnalysisTarget)
            {
                Warnings.LogExceptionInvalidTarget(context);
                context.Dispose();
                return(context);
            }

            context.Logger.AnalyzingTarget(context);
            IEnumerable <Skimmer <TContext> > applicableSkimmers = DetermineApplicabilityForTarget(skimmers, context, disabledSkimmers);

            AnalyzeTarget(applicableSkimmers, context, disabledSkimmers);

            return(context);
        }
Example #4
0
        protected virtual TContext DetermineApplicabilityAndAnalyze(
            TOptions options,
            IEnumerable <Skimmer <TContext> > skimmers,
            TContext rootContext,
            string target,
            ISet <string> disabledSkimmers)
        {
            TContext context = CreateContext(
                options,
                rootContext.Logger,
                rootContext.RuntimeErrors,
                rootContext.Policy,
                target);

            if ((options.DataToInsert.ToFlags() & OptionallyEmittedData.Hashes) != 0)
            {
                _cacheByFileHashLogger.HashToResultsMap.TryGetValue(context.Hashes.Sha256, out List <Tuple <ReportingDescriptor, Result> > cachedResultTuples);
                _cacheByFileHashLogger.HashToNotificationsMap.TryGetValue(context.Hashes.Sha256, out List <Notification> cachedNotifications);

                bool replayCachedData = (cachedResultTuples != null || cachedNotifications != null);

                if (replayCachedData)
                {
                    context.Logger.AnalyzingTarget(context);

                    if (cachedResultTuples != null)
                    {
                        foreach (Tuple <ReportingDescriptor, Result> cachedResultTuple in cachedResultTuples)
                        {
                            Result clonedResult = cachedResultTuple.Item2.DeepClone();
                            ReportingDescriptor cachedReportingDescriptor = cachedResultTuple.Item1;

                            UpdateLocationsAndMessageWithCurrentUri(clonedResult.Locations, clonedResult.Message, context.TargetUri);
                            context.Logger.Log(cachedReportingDescriptor, clonedResult);
                        }
                    }

                    if (cachedNotifications != null)
                    {
                        foreach (Notification cachedNotification in cachedNotifications)
                        {
                            Notification clonedNotification = cachedNotification.DeepClone();
                            UpdateLocationsAndMessageWithCurrentUri(clonedNotification.Locations, cachedNotification.Message, context.TargetUri);
                            context.Logger.LogConfigurationNotification(clonedNotification);
                        }
                    }
                    return(context);
                }
            }

            if (context.TargetLoadException != null)
            {
                Errors.LogExceptionLoadingTarget(context);
                context.Dispose();
                return(context);
            }
            else if (!context.IsValidAnalysisTarget)
            {
                Warnings.LogExceptionInvalidTarget(context);
                context.Dispose();
                return(context);
            }

            context.Logger.AnalyzingTarget(context);
            IEnumerable <Skimmer <TContext> > applicableSkimmers = DetermineApplicabilityForTarget(skimmers, context, disabledSkimmers);

            AnalyzeTarget(applicableSkimmers, context, disabledSkimmers);

            return(context);
        }