public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!descriptor.Location.StartsWith("~/Core/")) { return null; } var plocation = _hostEnvironment.MapPath("~/Core"); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(plocation))) { var assembly = Assembly.Load(new AssemblyName(CoreAssemblyName)); _logger.LogInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes.Where(x => IsTypeFromModule(x, descriptor)) }; } }
public ExtensionEntry Load(ExtensionDescriptor descriptor) { if (!ExtensionsVirtualPathPrefixes.Contains(descriptor.Location)) { return null; } var plocation = _hostEnvironment.MapPath(descriptor.Location); using (_loaderContainer.AddLoader(_extensionAssemblyLoader.WithPath(plocation))) { var assembly = Assembly.Load(new AssemblyName(descriptor.Id)); _logger.LogInformation("Loaded referenced extension \"{0}\": assembly name=\"{1}\"", descriptor.Name, assembly.FullName); return new ExtensionEntry { Descriptor = descriptor, Assembly = assembly, ExportedTypes = assembly.ExportedTypes }; } }
public static ExtensionDescriptor GetDescriptorForExtension(string locationPath, string extensionId, string extensionType, string manifestText) { Dictionary<string, string> manifest = ParseManifest(manifestText); var extensionDescriptor = new ExtensionDescriptor { Location = locationPath, Id = extensionId, ExtensionType = extensionType, Name = GetValue(manifest, NameSection) ?? extensionId, Path = GetValue(manifest, PathSection), Description = GetValue(manifest, DescriptionSection), Version = GetValue(manifest, VersionSection), OrchardVersion = GetValue(manifest, OrchardVersionSection), Author = GetValue(manifest, AuthorSection), WebSite = GetValue(manifest, WebsiteSection), Tags = GetValue(manifest, TagsSection), AntiForgery = GetValue(manifest, AntiForgerySection), Zones = GetValue(manifest, ZonesSection), BaseTheme = GetValue(manifest, BaseThemeSection), SessionState = GetValue(manifest, SessionStateSection) }; extensionDescriptor.Features = GetFeaturesForExtension(manifest, extensionDescriptor); return extensionDescriptor; }
private static IEnumerable<FeatureDescriptor> GetFeaturesForExtension(IDictionary<string, string> manifest, ExtensionDescriptor extensionDescriptor) { var featureDescriptors = new List<FeatureDescriptor>(); // Default feature FeatureDescriptor defaultFeature = new FeatureDescriptor { Id = extensionDescriptor.Id, Name = GetValue(manifest, FeatureNameSection) ?? extensionDescriptor.Name, Priority = GetValue(manifest, PrioritySection) != null ? int.Parse(GetValue(manifest, PrioritySection)) : 0, Description = GetValue(manifest, FeatureDescriptionSection) ?? GetValue(manifest, DescriptionSection) ?? string.Empty, Dependencies = ParseFeatureDependenciesEntry(GetValue(manifest, DependenciesSection)), Extension = extensionDescriptor, Category = GetValue(manifest, CategorySection) }; featureDescriptors.Add(defaultFeature); // Remaining features string featuresText = GetValue(manifest, FeaturesSection); if (featuresText != null) { FeatureDescriptor featureDescriptor = null; using (StringReader reader = new StringReader(featuresText)) { string line; while ((line = reader.ReadLine()) != null) { if (IsFeatureDeclaration(line)) { if (featureDescriptor != null) { if (!featureDescriptor.Equals(defaultFeature)) { featureDescriptors.Add(featureDescriptor); } featureDescriptor = null; } string[] featureDeclaration = line.Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries); string featureDescriptorId = featureDeclaration[0].Trim(); if (String.Equals(featureDescriptorId, extensionDescriptor.Id, StringComparison.OrdinalIgnoreCase)) { featureDescriptor = defaultFeature; featureDescriptor.Name = extensionDescriptor.Name; } else { featureDescriptor = new FeatureDescriptor { Id = featureDescriptorId, Extension = extensionDescriptor }; } } else if (IsFeatureFieldDeclaration(line)) { if (featureDescriptor != null) { string[] featureField = line.Split(new[] { ":" }, 2, StringSplitOptions.None); int featureFieldLength = featureField.Length; if (featureFieldLength != 2) continue; for (int i = 0; i < featureFieldLength; i++) { featureField[i] = featureField[i].Trim(); } switch (featureField[0].ToLowerInvariant()) { case NameSection: featureDescriptor.Name = featureField[1]; break; case DescriptionSection: featureDescriptor.Description = featureField[1]; break; case CategorySection: featureDescriptor.Category = featureField[1]; break; case PrioritySection: featureDescriptor.Priority = int.Parse(featureField[1]); break; case DependenciesSection: featureDescriptor.Dependencies = ParseFeatureDependenciesEntry(featureField[1]); break; } } else { string message = string.Format("The line {0} in manifest for extension {1} was ignored", line, extensionDescriptor.Id); throw new ArgumentException(message); } } else { string message = string.Format("The line {0} in manifest for extension {1} was ignored", line, extensionDescriptor.Id); throw new ArgumentException(message); } } if (featureDescriptor != null && !featureDescriptor.Equals(defaultFeature)) featureDescriptors.Add(featureDescriptor); } } return featureDescriptors; }
private static bool IsTypeFromModule(Type type, ExtensionDescriptor descriptor) { return (type.Namespace + ".").StartsWith(CoreAssemblyName + "." + descriptor.Id + "."); }
public ExtensionProbeEntry Probe(ExtensionDescriptor descriptor) { return null; }
public bool IsCompatibleWithModuleReferences(ExtensionDescriptor extension, IEnumerable<ExtensionProbeEntry> references) { return true; }
public void ExtensionDeactivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension) { }
private ExtensionEntry BuildEntry(ExtensionDescriptor descriptor) { foreach (var loader in _loaders) { ExtensionEntry entry = loader.Load(descriptor); if (entry != null) return entry; } _logger.LogWarning("No suitable loader found for extension \"{0}\"", descriptor.Id); return null; }