/// <summary> /// Extracts the events and delegates from the specified target frameworks. /// </summary> /// <param name="writer">The writer where to output to.</param> /// <param name="frameworks">The frameworks we are adapting to.</param> /// <returns>A task to monitor the progress.</returns> public static async Task ExtractEventsFromTargetFramework(TextWriter writer, IReadOnlyList <NuGetFramework> frameworks) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } if (frameworks == null) { throw new ArgumentNullException(nameof(frameworks)); } if (frameworks.Count == 0) { throw new ArgumentOutOfRangeException(nameof(frameworks)); } var mainFramework = frameworks[0]; LogHost.Default.Info(CultureInfo.InvariantCulture, "Processing target framework {0}", mainFramework); var input = new InputAssembliesGroup(); input.IncludeGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(mainFramework.GetNuGetFrameworkFolders(), AssemblyHelpers.AssemblyFileExtensionsSet)); await ExtractEventsFromAssemblies(writer, input, mainFramework).ConfigureAwait(false); LogHost.Default.Info(CultureInfo.InvariantCulture, "Finished target framework {0}", mainFramework); }
/// <summary> /// Extracts the events and delegates from the specified platform. /// </summary> /// <param name="writer">The writer where to output to.</param> /// <param name="input">The input into the processor.</param> /// <param name="framework">The framework we are adapting to.</param> /// <returns>A task to monitor the progress.</returns> public static async Task ExtractEventsFromAssemblies(TextWriter writer, InputAssembliesGroup input, NuGetFramework framework) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } using (var compilation = new EventBuilderCompiler(input, framework)) { var compilationOutputSyntax = CompilationUnit() .WithMembers(List <MemberDeclarationSyntax>(_resolvers.SelectMany(x => x.Create(compilation)))) .WithUsings(List(new[] { UsingDirective(IdentifierName("global::System")), UsingDirective(IdentifierName("global::System.Reactive")), UsingDirective(IdentifierName("global::System.Reactive.Linq")), UsingDirective(IdentifierName("global::System.Reactive.Subjects")), UsingDirective(IdentifierName("global::Pharmacist.Common")) })); await writer.WriteAsync(Environment.NewLine).ConfigureAwait(false); await writer.WriteAsync(compilationOutputSyntax.NormalizeWhitespace(elasticTrivia : true).ToString()).ConfigureAwait(false); await writer.FlushAsync().ConfigureAwait(false); } }
/// <summary> /// Extracts the events and delegates from the specified platform. /// </summary> /// <param name="writer">The writer where to output to.</param> /// <param name="assemblies">The assemblies to extract.</param> /// <param name="searchDirectories">Directories to search.</param> /// <param name="targetFramework">The name of the TFM to extract for.</param> /// <returns>A task to monitor the progress.</returns> public static async Task ExtractEventsFromAssemblies(TextWriter writer, IEnumerable <string> assemblies, IEnumerable <string> searchDirectories, string targetFramework) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } var input = new InputAssembliesGroup(); input.IncludeGroup.AddFiles(assemblies); input.SupportGroup.AddFiles(FileSystemHelpers.GetFilesWithinSubdirectories(searchDirectories, AssemblyHelpers.AssemblyFileExtensionsSet)); var framework = targetFramework.ToFrameworks(); await ExtractEventsFromAssemblies(writer, input, framework[0]).ConfigureAwait(false); }
public EventBuilderCompiler(InputAssembliesGroup input, NuGetFramework framework) { _knownTypeCache = new KnownTypeCache(this); if (input == null) { throw new ArgumentNullException(nameof(input)); } var context = new SimpleTypeResolveContext(this); var moduleReferences = input.IncludeGroup.GetAllFileNames() .Where(file => AssemblyHelpers.AssemblyFileExtensionsSet.Contains(Path.GetExtension(file))) .Select(x => (IModuleReference) new PEFile(x, PEStreamOptions.PrefetchMetadata)); _assemblies.AddRange(moduleReferences.Select(x => x.Resolve(context))); _referencedAssemblies.AddRange(GetReferenceModules(_assemblies, input, framework, context)); _rootNamespace = CreateRootNamespace(); }
private static string?SearchDirectories(IAssemblyReference name, InputAssembliesGroup input, IEnumerable <string> extensions) { foreach (var extension in extensions) { var testName = input.SupportGroup.GetFullFilePath(name.Name + extension); if (string.IsNullOrWhiteSpace(testName)) { continue; } if (!File.Exists(testName)) { continue; } return(testName); } return(null); }
private static string?SearchDirectories(IAssemblyReference name, InputAssembliesGroup input, IEnumerable <string> extensions) { return(extensions.Select(extension => input.SupportGroup.GetFullFilePath(name.Name + extension)).Where(testName => !string.IsNullOrWhiteSpace(testName)).FirstOrDefault(File.Exists)); }
private static string?GetFileName(IAssemblyReference reference, IModule parent, InputAssembliesGroup input, NuGetFramework framework) { var extensions = reference.IsWindowsRuntime ? new[] { ".winmd", ".dll" } : new[] { ".exe", ".dll" }; if (reference.IsWindowsRuntime) { return(AssemblyHelpers.FindWindowsMetadataFile(reference.Name, reference.Version)); } string?file; if (reference.Name == "mscorlib") { file = GetCorlib(reference); if (!string.IsNullOrWhiteSpace(file)) { return(file); } } file = FindInParentDirectory(reference, parent, extensions); if (!string.IsNullOrWhiteSpace(file)) { return(file); } file = SearchDirectories(reference, input, extensions); return(!string.IsNullOrWhiteSpace(file) ? file : SearchNugetFrameworkDirectories(reference, extensions, framework)); }
/// <summary> /// Resolves the specified full assembly name. /// </summary> /// <param name="reference">A reference with details about the assembly.</param> /// <param name="parent">The parent of the reference.</param> /// <param name="input">The directories potentially containing the assemblies.</param> /// <param name="framework">The framework we are processing for.</param> /// <param name="parameters">Parameters to provide to the reflection system..</param> /// <returns>The assembly definitions.</returns> public static PEFile?Resolve(this IAssemblyReference reference, IModule parent, InputAssembliesGroup input, NuGetFramework framework, PEStreamOptions parameters = PEStreamOptions.PrefetchMetadata) { var fileName = GetFileName(reference, parent, input, framework); return(string.IsNullOrWhiteSpace(fileName) ? null : new PEFile(fileName, parameters)); }
private static IEnumerable <IModule> GetReferenceModules(IEnumerable <IModule> mainModules, InputAssembliesGroup input, NuGetFramework framework, ITypeResolveContext context) { var assemblyReferencesSeen = new HashSet <IAssemblyReference>(AssemblyReferenceNameComparer.Default); var referenceModulesToProcess = new Stack <(IModule parent, IAssemblyReference reference)>(mainModules.SelectMany(x => x.PEFile.AssemblyReferences.Select(reference => (x, (IAssemblyReference)reference)))); while (referenceModulesToProcess.Count > 0) { var current = referenceModulesToProcess.Pop(); if (!assemblyReferencesSeen.Add(current.reference)) { continue; } #pragma warning disable CA2000 // Dispose objects before losing scope var moduleReference = (IModuleReference?)current.reference.Resolve(current.parent, input, framework); #pragma warning restore CA2000 // Dispose objects before losing scope if (moduleReference == null) { continue; } var module = moduleReference.Resolve(context); yield return(module); foreach (var childAssemblyReference in module.PEFile.AssemblyReferences) { referenceModulesToProcess.Push((module, childAssemblyReference)); } } }
/// <inheritdoc /> protected override void SetFiles(InputAssembliesGroup folderGroups) { var fileMetadataEnumerable = folderGroups.IncludeGroup.GetAllFileNames().Where(file => WantedFileNames.Contains(Path.GetFileName(file), StringComparer.InvariantCultureIgnoreCase)); Input.IncludeGroup.AddFiles(fileMetadataEnumerable); }
/// <summary> /// Processes the files. /// </summary> /// <param name="folderGroups">The files.</param> protected abstract void SetFiles(InputAssembliesGroup folderGroups);