public SourceFileInputParameters(ExtractMetadataOptions options, IEnumerable <string> files)
 {
     Options   = options;
     Files     = files;
     Key       = StringExtension.GetNormalizedFullPathKey(Files);
     Cache     = ProjectLevelCache.Get(files);
     BuildInfo = Cache?.GetValidConfig(Key);
 }
 public AssemblyFileInputParameters(ExtractMetadataOptions options, string key)
 {
     Options   = options;
     Files     = new string[] { key };
     Key       = StringExtension.GetNormalizedFullPathKey(Files);
     Cache     = ProjectLevelCache.Get(key);
     BuildInfo = Cache?.GetValidConfig(Key);
 }
Exemple #3
0
 public ProjectFileInputParameters(ExtractMetadataOptions options, IEnumerable <string> files, string projectFile, bool dependencyRebuilt)
 {
     Options           = options;
     Files             = files;
     DependencyRebuilt = dependencyRebuilt;
     Key       = StringExtension.ToNormalizedFullPath(projectFile);
     Cache     = ProjectLevelCache.Get(projectFile);
     BuildInfo = Cache?.GetValidConfig(Key);
 }
        private static async Task <Tuple <MetadataItem, bool> > GetMetadataFromProjectLevelCacheAsync <T>(
            T input,
            IEnumerable <string> inputKey,
            Func <IncrementalCheck, Task <bool> > rebuildChecker,
            Func <T, Task <Compilation> > compilationProvider,
            Func <T, IDictionary <string, List <string> > > containedFilesProvider,
            string outputFolder,
            bool preserveRawInlineComments,
            bool shouldSkipMarkup,
            string filterConfigFile,
            IReadOnlyDictionary <Compilation, IEnumerable <IMethodSymbol> > extensionMethods)
        {
            DateTime triggeredTime     = DateTime.UtcNow;
            var      projectLevelCache = ProjectLevelCache.Get(inputKey);
            var      projectConfig     = projectLevelCache.GetValidConfig(inputKey);
            var      rebuildProject    = true;

            if (projectConfig != null)
            {
                var projectCheck = new IncrementalCheck(projectConfig);
                rebuildProject = await rebuildChecker(projectCheck);
            }

            MetadataItem projectMetadata;

            if (!rebuildProject)
            {
                // Load from cache
                var cacheFile = Path.Combine(projectConfig.OutputFolder, projectConfig.RelatvieOutputFiles.First());
                Logger.Log(LogLevel.Info, $"'{projectConfig.InputFilesKey}' keep up-to-date since '{projectConfig.TriggeredUtcTime.ToString()}', cached intermediate result '{cacheFile}' is used.");
                if (TryParseYamlMetadataFile(cacheFile, out projectMetadata))
                {
                    return(Tuple.Create(projectMetadata, rebuildProject));
                }
                else
                {
                    Logger.Log(LogLevel.Info, $"'{projectConfig.InputFilesKey}' is invalid, rebuild needed.");
                }
            }

            var compilation = await compilationProvider(input);

            projectMetadata = GenerateYamlMetadata(compilation, preserveRawInlineComments, filterConfigFile, extensionMethods);
            var file = Path.GetRandomFileName();
            var cacheOutputFolder = projectLevelCache.OutputFolder;
            var path = Path.Combine(cacheOutputFolder, file);

            YamlUtility.Serialize(path, projectMetadata);
            Logger.Log(LogLevel.Verbose, $"Successfully generated metadata {cacheOutputFolder} for {projectMetadata.Name}");

            IDictionary <string, List <string> > containedFiles = null;

            if (containedFilesProvider != null)
            {
                containedFiles = containedFilesProvider(input);
            }

            // Save to cache
            projectLevelCache.SaveToCache(inputKey, containedFiles, triggeredTime, cacheOutputFolder, new List <string>()
            {
                file
            }, shouldSkipMarkup);

            return(Tuple.Create(projectMetadata, rebuildProject));
        }