static IEnumerable <Type> GetWebApplicationHostTypes() { return(Assemblies.Concat(AppCodeAssemblies) .SelectMany(assembly => assembly.GetAttributes <WebApplicationHostAttribute>()) .OrderBy(att => att.Order) .Select(att => att.Type)); }
public string FindTypeUrl(string typeFullName, bool shallow = false) { if (typeUrls.TryGetValue(typeFullName, out var url)) { return(url); } var types = from a in Assemblies.Concat(BuildAssemblies) from m in a.Definition.Modules select new { a, t = m.GetType(typeFullName) }; var at = types.FirstOrDefault(x => x.t != null); if (at == null) { if (typeFullName.StartsWith("System.", StringComparison.Ordinal)) { var slug = Uri.EscapeDataString(typeFullName.Replace('`', '-')).ToLowerInvariant(); return($"https://docs.microsoft.com/en-us/dotnet/api/{slug}"); } if (typeFullName.StartsWith("Windows.", StringComparison.Ordinal)) { var slug = Uri.EscapeDataString(typeFullName.Replace('`', '-')).ToLowerInvariant(); return($"https://docs.microsoft.com/en-us/uwp/api/{slug}"); } if (typeFullName.StartsWith("Foundation.", StringComparison.Ordinal) || typeFullName.StartsWith("UIKit.", StringComparison.Ordinal) || typeFullName.StartsWith("AppKit.", StringComparison.Ordinal) || typeFullName.StartsWith("CoreGraphics.", StringComparison.Ordinal) || typeFullName.StartsWith("Android.", StringComparison.Ordinal)) { var slug = Uri.EscapeDataString(typeFullName); return($"https://developer.xamarin.com/api/type/{slug}"); } if (!shallow) { //var sw = new Stopwatch (); //sw.Start (); url = DeepFindTypeUrlAsync( typeFullName, new ConcurrentDictionary <string, bool> (), new ConcurrentQueue <string> (), httpClient ).Result; //sw.Stop (); //Console.WriteLine ($"RESOLVED IN {sw.ElapsedMilliseconds} millis: {typeFullName} ---> {url}"); if (url != null) { typeUrls.TryAdd(typeFullName, url); } return(url); } return(null); } var dir = at.a.IsBuildAssembly ? "build" : "lib"; return($"/packages/{Uri.EscapeDataString(Package.Id)}/{Uri.EscapeDataString(Package.Version.VersionString)}/{dir}/{Uri.EscapeDataString(Moniker)}/{Uri.EscapeDataString(at.a.FileName)}/{Uri.EscapeDataString(at.t.Namespace)}/{Uri.EscapeDataString(at.t.Name)}"); }
public IAssemblyLookupSet IncludeAssemblies(IEnumerable <Assembly> assemblies) { return(new AssemblyLookupSet( _baseTypes, Assemblies .Concat(assemblies) .Distinct() .ToImmutableList())); }
private void HandlePackage(GlobTask globTask) { var assembliesInPackage = new List <string>(); var packageDefPath = Path.Combine(PackageInstallDir, "Packages", globTask.PackageName, "package.xml"); // Silently ignore the package if its package.xml does not exist if (!File.Exists(packageDefPath)) { Log.LogWarning($"No package named {globTask.PackageName}. Does a glob expression contain a semicolon?"); return; } var dllsInPackage = dllRx.Matches(File.ReadAllText(packageDefPath)).Cast <Match>() .Where(match => match.Groups["name"].Success) .Select(match => match.Groups["name"].Value); var matchedDlls = dllsInPackage.Where(x => globTask.Includes(x, Log)); foreach (var dllPath in matchedDlls.Distinct()) { var absolutedllPath = Path.Combine(PackageInstallDir, dllPath); // Ensure we don't add references twice if they are matched by multiple patterns if (_added.Contains(absolutedllPath)) { Log.LogMessage($"{absolutedllPath} already added. Not adding again."); continue; } _added.Add(absolutedllPath); if (IsDotNetAssembly(absolutedllPath)) { assembliesInPackage.Add(dllPath); } else { Log.LogWarning($"{absolutedllPath} not recognized as a DotNet assembly. Reference not added."); } } Log.LogMessage(MessageImportance.Normal, "Found these assemblies in OpenTAP references: " + string.Join(", ", assembliesInPackage)); if (!assembliesInPackage.Any()) { Log.LogWarning($"No references added from package '{globTask.PackageName}'."); } else { WriteItemGroup(assembliesInPackage); Assemblies = Assemblies.Concat(assembliesInPackage).ToArray(); } }
private static void RunActivationMethods <T>(bool designerMode = false) where T : BaseActivationMethodAttribute { var attribs = Assemblies.Concat(AppCodeAssemblies) .SelectMany(assembly => assembly.GetAttributes <T>()) .OrderBy(att => att.Order); foreach (var activationAttrib in attribs) { if (!designerMode || activationAttrib.ShouldRunInDesignerMode()) { activationAttrib.InvokeMethod(); } } }
// Call the relevant activation method from all assemblies private static void RunActivationMethods <T>(bool designerMode = false) where T : BaseActivationMethodAttribute { var attribs = Assemblies.Concat(AppCodeAssemblies) .SelectMany(assembly => assembly.GetActivationAttributes <T>()) .OrderBy(att => att.Order); foreach (var activationAttrib in attribs) { // Don't run it in designer mode, unless the attribute explicitly asks for that if (!designerMode || activationAttrib.ShouldRunInDesignerMode()) { activationAttrib.InvokeMethod(); } } }
XElement CreateApplicationElement(XElement manifest, string applicationClass, List <TypeDefinition> subclasses, List <string> selectedWhitelistAssemblies) { var application = manifest.Descendants("application").FirstOrDefault(); List <ApplicationAttribute> assemblyAttr = Assemblies.Select(path => ApplicationAttribute.FromCustomAttributeProvider(Resolver.GetAssembly(path))) .Where(attr => attr != null) .ToList(); List <MetaDataAttribute> metadata = Assemblies.SelectMany(path => MetaDataAttribute.FromCustomAttributeProvider(Resolver.GetAssembly(path))) .Where(attr => attr != null) .ToList(); var usesLibraryAttr = Assemblies.Concat(selectedWhitelistAssemblies).SelectMany(path => UsesLibraryAttribute.FromCustomAttributeProvider(Resolver.GetAssembly(path))) .Where(attr => attr != null); if (assemblyAttr.Count > 1) { throw new InvalidOperationException("There can be only one [assembly:Application] attribute defined."); } List <ApplicationAttribute> typeAttr = new List <ApplicationAttribute> (); List <UsesLibraryAttribute> typeUsesLibraryAttr = new List <UsesLibraryAttribute> (); foreach (var t in subclasses) { ApplicationAttribute aa = ApplicationAttribute.FromCustomAttributeProvider(t); if (aa == null) { continue; } if (!t.IsSubclassOf("Android.App.Application")) { throw new InvalidOperationException(string.Format("Found [Application] on type {0}. [Application] can only be used on subclasses of Application.", t.FullName)); } typeAttr.Add(aa); metadata.AddRange(MetaDataAttribute.FromCustomAttributeProvider(t)); typeUsesLibraryAttr.AddRange(UsesLibraryAttribute.FromCustomAttributeProvider(t)); } if (typeAttr.Count > 1) { throw new InvalidOperationException("There can be only one type with an [Application] attribute; found: " + string.Join(", ", typeAttr.Select(aa => aa.Name).ToArray())); } if (assemblyAttr.Count > 0 && typeAttr.Count > 0) { throw new InvalidOperationException("Application cannot have both a type with an [Application] attribute and an [assembly:Application] attribute."); } ApplicationAttribute appAttr = assemblyAttr.SingleOrDefault() ?? typeAttr.SingleOrDefault(); var ull1 = usesLibraryAttr ?? new UsesLibraryAttribute [0]; var ull2 = typeUsesLibraryAttr.AsEnumerable() ?? new UsesLibraryAttribute [0]; var usesLibraryAttrs = ull1.Concat(ull2); bool needManifestAdd = true; if (appAttr != null) { var newapp = appAttr.ToElement(Resolver, PackageName); if (application == null) { application = newapp; } else { needManifestAdd = false; foreach (var n in newapp.Attributes()) { application.SetAttributeValue(n.Name, n.Value); } foreach (var n in newapp.Nodes()) { application.Add(n); } } } else if (application == null) { application = new XElement("application"); } else { needManifestAdd = false; } application.Add(metadata.Select(md => md.ToElement(PackageName))); if (needManifestAdd) { manifest.Add(application); } AddUsesLibraries(application, usesLibraryAttrs); if (applicationClass != null && application.Attribute(androidNs + "name") == null) { application.Add(new XAttribute(androidNs + "name", applicationClass)); } if (application.Attribute(androidNs + "allowBackup") == null) { application.Add(new XAttribute(androidNs + "allowBackup", "true")); } return(application); }
public T WithAssemblies(params Assembly[] assemblies) { Assemblies = Assemblies.Concat(assemblies); return((T)(object)this); }
public T WithAssemblies(IEnumerable <Assembly> assemblies) { Assemblies = Assemblies.Concat(assemblies); return((T)(object)this); }