本文整理汇总了C#中ExtensionLoadingContext类的典型用法代码示例。如果您正苦于以下问题:C# ExtensionLoadingContext类的具体用法?C# ExtensionLoadingContext怎么用?C# ExtensionLoadingContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExtensionLoadingContext类属于命名空间,在下文中一共展示了ExtensionLoadingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtensionActivated
public override void ExtensionActivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
{
if (_reloadWorkaround.AppDomainRestartNeeded) {
Logger.Information("ExtensionActivated: Module \"{0}\" has changed, forcing AppDomain restart", extension.Id);
ctx.RestartAppDomain = _reloadWorkaround.AppDomainRestartNeeded;
}
}
示例2: DeleteAssembly
private void DeleteAssembly(ExtensionLoadingContext ctx, string moduleName) {
var assemblyPath = _virtualPathProvider.Combine("~/bin", moduleName + ".dll");
if (_virtualPathProvider.FileExists(assemblyPath)) {
ctx.DeleteActions.Add(
() => {
Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from bin directory (AppDomain will restart)", moduleName);
File.Delete(_virtualPathProvider.MapPath(assemblyPath));
});
ctx.RestartAppDomain = true;
}
}
示例3: ExtensionRemoved
public override void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency) {
if (_assemblyProbingFolder.AssemblyExists(dependency.Name)) {
ctx.DeleteActions.Add(
() => {
Logger.Information("ExtensionRemoved: Deleting assembly \"{0}\" from probing directory", dependency.Name);
_assemblyProbingFolder.DeleteAssembly(dependency.Name);
});
// We need to restart the appDomain if the assembly is loaded
if (_hostEnvironment.IsAssemblyLoaded(dependency.Name)) {
Logger.Information("ExtensionRemoved: Module \"{0}\" is removed and its assembly is loaded, forcing AppDomain restart", dependency.Name);
ctx.RestartAppDomain = true;
}
}
}
示例4: ExtensionActivated
public override void ExtensionActivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension) {
string sourceFileName = _virtualPathProvider.MapPath(GetAssemblyPath(extension));
// Copy the assembly if it doesn't exist or if it is older than the source file.
bool copyAssembly =
!_assemblyProbingFolder.AssemblyExists(extension.Id) ||
File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(extension.Id);
if (copyAssembly) {
ctx.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(extension.Id, sourceFileName));
// We need to restart the appDomain if the assembly is loaded
if (_hostEnvironment.IsAssemblyLoaded(extension.Id)) {
Logger.Information("ExtensionRemoved: Module \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", extension.Id);
ctx.RestartAppDomain = true;
}
}
}
示例5: ExtensionDeactivated
public override void ExtensionDeactivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
{
DeleteAssembly(ctx, extension.Id);
}
示例6: ProcessExtension
private void ProcessExtension(ExtensionLoadingContext context, ExtensionDescriptorEntry extension)
{
var extensionProbes = context.AvailableExtensionsProbes.ContainsKey(extension.Id) ?
context.AvailableExtensionsProbes[extension.Id] :
Enumerable.Empty<ExtensionProbeEntry>();
var extensionProbeEntries = extensionProbes as ExtensionProbeEntry[] ?? extensionProbes.ToArray();
if (Logger.IsEnabled(LogLevel.Debug))
{
Logger.Debug("加载扩展 \"{0}\": ", extension.Id);
foreach (var probe in extensionProbeEntries)
{
Logger.Debug(" Loader: {0}", probe.Loader.Name);
Logger.Debug(" VirtualPath: {0}", probe.VirtualPath);
Logger.Debug(" VirtualPathDependencies: {0}", string.Join(", ", probe.VirtualPathDependencies));
}
}
var moduleReferences =
context.AvailableExtensions
.Where(e =>
context.ReferencesByModule.ContainsKey(extension.Id) &&
context.ReferencesByModule[extension.Id].Any(r => StringComparer.OrdinalIgnoreCase.Equals(e.Id, r.Name)))
.ToList();
var processedModuleReferences =
moduleReferences
.Where(e => context.ProcessedExtensions.ContainsKey(e.Id))
.Select(e => context.ProcessedExtensions[e.Id])
.ToList();
var activatedExtension = extensionProbeEntries.FirstOrDefault(
e => e.Loader.IsCompatibleWithModuleReferences(extension, processedModuleReferences)
);
var previousDependency = context.PreviousDependencies.FirstOrDefault(
d => StringComparer.OrdinalIgnoreCase.Equals(d.Name, extension.Id)
);
if (activatedExtension == null)
{
Logger.Warning("没有找到装载机来装载扩展 \"{0}\"!", extension.Id);
}
var references = ProcessExtensionReferences(context, activatedExtension);
foreach (var loader in _loaders)
{
if (activatedExtension != null && activatedExtension.Loader.Name == loader.Name)
{
Logger.Information("使用装载机 \"{1}\" 来激活扩展 \"{0}\"", activatedExtension.Descriptor.Id, loader.Name);
loader.ExtensionActivated(context, extension);
}
else if (previousDependency != null && previousDependency.LoaderName == loader.Name)
{
Logger.Information("使用装载机 \"{1}\" 来停用扩展 \"{0}\"", previousDependency.Name, loader.Name);
loader.ExtensionDeactivated(context, extension);
}
}
if (activatedExtension != null)
{
context.NewDependencies.Add(new DependencyDescriptor
{
Name = extension.Id,
LoaderName = activatedExtension.Loader.Name,
VirtualPath = activatedExtension.VirtualPath,
References = references
});
}
//跟踪哪些装载机,我们使用的每一个扩展
//这将需要从其他相关的扩展处理参考
context.ProcessedExtensions.Add(extension.Id, activatedExtension);
}
示例7: ExtensionDeactivated
public void ExtensionDeactivated(ExtensionLoadingContext ctx, ExtensionDescriptor extension)
{
}
示例8: ExtensionDeactivated
/// <summary>
/// 扩展停用。
/// </summary>
/// <param name="context">扩展装载上下文。</param>
/// <param name="descriptor">扩展描述符条目。</param>
public override void ExtensionDeactivated(ExtensionLoadingContext context, ExtensionDescriptorEntry descriptor)
{
DeleteAssembly(context, descriptor.Id);
}
示例9: ExtensionRemoved
public virtual void ExtensionRemoved(ExtensionLoadingContext ctx, DependencyDescriptor dependency) { }
示例10: ExtensionActivated
/// <summary>
/// 扩展激活。
/// </summary>
/// <param name="context">扩展装载上下文。</param>
/// <param name="descriptor">扩展描述符条目。</param>
public override void ExtensionActivated(ExtensionLoadingContext context, ExtensionDescriptorEntry descriptor)
{
var sourceFileName = _applicationFolder.MapPath(GetAssemblyPath(descriptor));
//如果程序集文件不存在或者比新的旧则复制新的程序集文件到依赖目录。
var copyAssembly =
!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(descriptor.Id)) ||
File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(new AssemblyDescriptor(descriptor.Id));
if (!copyAssembly)
return;
context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(new AssemblyDescriptor(descriptor.Id), sourceFileName));
//如果程序集已经被加载,需要重新启动AppDomain
if (!_hostEnvironment.IsAssemblyLoaded(descriptor.Id))
return;
Logger.Information("ExtensionRemoved: 模块 \"{0}\" 激活新的程序集文件加载,迫使AppDomain重启", descriptor.Id);
context.RestartAppDomain = true;
}
示例11: ReferenceActivated
/// <summary>
/// 激活引用。
/// </summary>
/// <param name="context">扩展装载上下文。</param>
/// <param name="referenceEntry">引用条目。</param>
public override void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry)
{
if (string.IsNullOrEmpty(referenceEntry.VirtualPath))
return;
var sourceFileName = _applicationFolder.MapPath(referenceEntry.VirtualPath);
//如果程序集文件不存在或者比新的旧则复制新的程序集文件到依赖目录。
var copyAssembly =
!_assemblyProbingFolder.AssemblyExists(new AssemblyDescriptor(referenceEntry.Name)) ||
File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(new AssemblyDescriptor(referenceEntry.Name));
if (!copyAssembly)
return;
context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(new AssemblyDescriptor(referenceEntry.Name), sourceFileName));
//如果程序集已经被加载,需要重新启动AppDomain
if (!_hostEnvironment.IsAssemblyLoaded(referenceEntry.Name))
return;
Logger.Information("ReferenceActivated: 引用 \"{0}\" 激活新的程序集文件加载,迫使AppDomain重启", referenceEntry.Name);
context.RestartAppDomain = true;
}
示例12: ProcessContextCommands
private void ProcessContextCommands(ExtensionLoadingContext ctx)
{
Logger.Information("执行的加载扩展所需的操作列表...");
foreach (var action in ctx.DeleteActions)
{
action();
}
foreach (var action in ctx.CopyActions)
{
action();
}
}
示例13: ProcessExtensionReference
private void ProcessExtensionReference(ExtensionLoadingContext context, string referenceName, ICollection<DependencyReferenceDescriptor> activatedReferences)
{
//如果参考是一个扩展已经被处理,使用相同的装载机扩展,因为给定的扩展名应具有独特的装载机在整个应用程序加载
var bestExtensionReference = context.ProcessedExtensions.ContainsKey(referenceName) ?
context.ProcessedExtensions[referenceName] :
null;
//激活扩展引用
if (bestExtensionReference != null)
{
activatedReferences.Add(new DependencyReferenceDescriptor
{
LoaderName = bestExtensionReference.Loader.Name,
Name = referenceName,
VirtualPath = bestExtensionReference.VirtualPath
});
return;
}
//跳过来自 "~/bin" 的引用。
if (_buildManager.HasReferencedAssembly(referenceName))
return;
//二进制引用
var references = context.ReferencesByName.ContainsKey(referenceName) ?
context.ReferencesByName[referenceName] :
Enumerable.Empty<ExtensionReferenceProbeEntry>();
var bestBinaryReference = references
.Where(entry => !string.IsNullOrEmpty(entry.VirtualPath))
.Select(entry => new { Entry = entry, LastWriteTimeUtc = _virtualPathProvider.GetFileLastWriteTimeUtc(entry.VirtualPath) })
.OrderBy(e => e.LastWriteTimeUtc)
.ThenBy(e => e.Entry.Name)
.FirstOrDefault();
//激活二进制引用
if (bestBinaryReference == null)
return;
if (!context.ProcessedReferences.ContainsKey(bestBinaryReference.Entry.Name))
{
context.ProcessedReferences.Add(bestBinaryReference.Entry.Name, bestBinaryReference.Entry);
bestBinaryReference.Entry.Loader.ReferenceActivated(context, bestBinaryReference.Entry);
}
activatedReferences.Add(new DependencyReferenceDescriptor
{
LoaderName = bestBinaryReference.Entry.Loader.Name,
Name = bestBinaryReference.Entry.Name,
VirtualPath = bestBinaryReference.Entry.VirtualPath
});
}
示例14: ProcessExtensionReferences
private IEnumerable<DependencyReferenceDescriptor> ProcessExtensionReferences(ExtensionLoadingContext context, ExtensionProbeEntry activatedExtension)
{
if (activatedExtension == null)
return Enumerable.Empty<DependencyReferenceDescriptor>();
var referenceNames = (context.ReferencesByModule.ContainsKey(activatedExtension.Descriptor.Id) ?
context.ReferencesByModule[activatedExtension.Descriptor.Id] :
Enumerable.Empty<ExtensionReferenceProbeEntry>())
.Select(r => r.Name)
.Distinct(StringComparer.OrdinalIgnoreCase);
var referencesDecriptors = new List<DependencyReferenceDescriptor>();
foreach (var referenceName in referenceNames)
{
ProcessExtensionReference(context, referenceName, referencesDecriptors);
}
return referencesDecriptors;
}
示例15: ReferenceActivated
public override void ReferenceActivated(ExtensionLoadingContext context, ExtensionReferenceProbeEntry referenceEntry) {
//Note: This is the same implementation as "PrecompiledExtensionLoader"
if (string.IsNullOrEmpty(referenceEntry.VirtualPath))
return;
string sourceFileName = _virtualPathProvider.MapPath(referenceEntry.VirtualPath);
// Copy the assembly if it doesn't exist or if it is older than the source file.
bool copyAssembly =
!_assemblyProbingFolder.AssemblyExists(referenceEntry.Name) ||
File.GetLastWriteTimeUtc(sourceFileName) > _assemblyProbingFolder.GetAssemblyDateTimeUtc(referenceEntry.Name);
if (copyAssembly) {
context.CopyActions.Add(() => _assemblyProbingFolder.StoreAssembly(referenceEntry.Name, sourceFileName));
// We need to restart the appDomain if the assembly is loaded
if (_hostEnvironment.IsAssemblyLoaded(referenceEntry.Name)) {
Logger.Information("ReferenceActivated: Reference \"{0}\" is activated with newer file and its assembly is loaded, forcing AppDomain restart", referenceEntry.Name);
context.RestartAppDomain = true;
}
}
}