/// <summary> /// 初始化动态应用程序域 /// </summary> /// <param name="name">应用程序域名称</param> /// <param name="privatePath">程序集加载目录</param> /// <param name="configFile">配置文件</param> /// <param name="cacheDirectory">应用程序域缓存目录,null表示非缓存</param> /// <param name="log">日志处理</param> public DynamicDomain(string name, string privatePath, string configFile, string cacheDirectory, AutoCSer.Log.ILog log = null) { this.log = log ?? AutoCSer.Log.Pub.Log; if (string.IsNullOrEmpty(privatePath)) { privatePath = AutoCSer.PubPath.ApplicationPath; } else { privatePath = new DirectoryInfo(privatePath).fullName().fileNameToLower(); if (privatePath != AutoCSer.PubPath.ApplicationPath) { this.privatePath = privatePath; } } setup = new AppDomainSetup(); if (configFile != null && File.Exists(configFile)) { setup.ConfigurationFile = configFile; } setup.ApplicationName = name; setup.ApplicationBase = privatePath; setup.PrivateBinPath = privatePath; if (cacheDirectory != null && cacheDirectory.Length != 0) { setup.ShadowCopyFiles = "true"; setup.ShadowCopyDirectories = cacheDirectory; setup.CachePath = cacheDirectory; } domain = AppDomain.CreateDomain(name, null, setup); loader = (assemblyLoader)domain.CreateInstanceAndUnwrap(assemblyName, assemblyLoaderName); loader.Log = this.log; }
/// <summary> /// 卸载应用程序域 /// </summary> public void Dispose() { if (domain != null) { try { AppDomain.Unload(domain); } catch (Exception error) { log.add(Log.LogType.Error, error); } domain = null; loader = null; } }
/// <summary> /// 卸载应用程序域 /// </summary> public void Dispose() { if (domain != null) { try { AppDomain.Unload(domain); } catch (Exception error) { log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer); } domain = null; loader = null; } }
/// <summary> /// 卸载应用程序域 /// </summary> public void Dispose() { if (domain != null) { try { AppDomain.Unload(domain); } catch (Exception error) { log.Error.Add(error, null, false); } domain = null; loader = null; } }