Пример #1
0
        /// <summary>
        /// 根据程序集描述符装载一个程序集。
        /// </summary>
        /// <param name="assemblyLoader">程序集装载机。</param>
        /// <param name="descriptor">程序集描述符。</param>
        /// <returns>程序集。</returns>
        /// <exception cref="ArgumentNullException"><paramref name="descriptor"/> 为null。</exception>
        public static Assembly Load(this IAssemblyLoader assemblyLoader, AssemblyDescriptor descriptor)
        {
            if (assemblyLoader == null)
                throw new ArgumentNullException("assemblyLoader");
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            return assemblyLoader.Load(descriptor.FullName);
        }
 /// <summary>
 /// 装载程序集。
 /// </summary>
 /// <param name="descriptor">程序集描述符。</param>
 /// <returns>程序集。</returns>
 public Assembly LoadAssembly(AssemblyDescriptor descriptor)
 {
     var path = PrecompiledAssemblyPath(descriptor);
     return !_appDataFolder.FileExists(path) ? null : _assemblyLoader.Load(descriptor);
 }
        /// <summary>
        /// 删除程序集。
        /// </summary>
        /// <param name="descriptor">程序集描述符。</param>
        public void DeleteAssembly(AssemblyDescriptor descriptor)
        {
            var path = PrecompiledAssemblyPath(descriptor);

            if (!_appDataFolder.FileExists(path))
                return;
            Logger.Information("从程序集探测目录删除程序集 {0}", descriptor.ToString());
            _appDataFolder.DeleteFile(path);
        }
 /// <summary>
 /// 获取程序集的最后修改的Utc时间,如果不存在则返回null。
 /// </summary>
 /// <param name="descriptor">程序集描述符。</param>
 /// <returns>Utc时间。</returns>
 public DateTime? GetAssemblyDateTimeUtc(AssemblyDescriptor descriptor)
 {
     var path = PrecompiledAssemblyPath(descriptor);
     return _appDataFolder.GetFileLastWriteTimeUtc(path);
 }
 /// <summary>
 /// 获取程序集的虚拟路径。
 /// </summary>
 /// <param name="descriptor">程序集描述符。</param>
 /// <returns>虚拟路径。</returns>
 public string GetAssemblyVirtualPath(AssemblyDescriptor descriptor)
 {
     var path = PrecompiledAssemblyPath(descriptor);
     return !_appDataFolder.FileExists(path) ? null : _appDataFolder.GetVirtualPath(path);
 }
 /// <summary>
 /// 程序集是否存在。
 /// </summary>
 /// <param name="descriptor">程序集描述符。</param>
 /// <returns>true为存在,false为不存在。</returns>
 public bool AssemblyExists(AssemblyDescriptor descriptor)
 {
     var path = PrecompiledAssemblyPath(descriptor);
     return _appDataFolder.FileExists(path);
 }
 private string PrecompiledAssemblyPath(AssemblyDescriptor descriptor)
 {
     return _appDataFolder.Combine(BasePath, descriptor.Name + ".dll");
 }
        /// <summary>
        /// 存储程序集。
        /// </summary>
        /// <param name="moduleName">模块名称。</param>
        public void StoreAssembly(string moduleName)
        {
            var descriptor = _extensionManager.GetExtension(moduleName);

            if (descriptor == null)
                return;

            /*            var paths = GetModuleAssemblyPaths(descriptor);
                        if (paths == null)
                            return;

                        foreach (var item in paths)
                        {
                            var assembly = item.Key;
                            var fileName = item.Value;
                            StoreAssembly(assembly, _applicationFolder.MapPath(fileName));
                        }*/
            var path = GetModuleAssemblyPath(descriptor);
            Logger.Information("为模块 \"{1}\" 存储程序集文件 \"{0}\"", path, moduleName);
            var assemblyDescriptor = new AssemblyDescriptor(moduleName);
            StoreAssembly(assemblyDescriptor, _applicationFolder.MapPath(path));
        }
        /// <summary>
        /// 存储程序集。
        /// </summary>
        /// <param name="descriptor">程序集描述符。</param>
        /// <param name="fileName">程序集文件名称。</param>
        public void StoreAssembly(AssemblyDescriptor descriptor, string fileName)
        {
            var path = PrecompiledAssemblyPath(descriptor);

            Logger.Information("存储程序集 {0} 到程序集探测目录", descriptor.ToString());
            _appDataFolder.StoreFile(fileName, path);
        }
        public void StoreAndDeleteAssemblyTest()
        {
            var descriptor = new AssemblyDescriptor("Rabbit.Kernel.Tests");

            if (AssemblyProbingFolder.AssemblyExists(descriptor))
                AssemblyProbingFolder.DeleteAssembly(descriptor);

            AssemblyProbingFolder.StoreAssembly(descriptor, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, descriptor.Name + ".dll"));
            Assert.IsTrue(AssemblyProbingFolder.AssemblyExists(descriptor));
            AssemblyProbingFolder.DeleteAssembly(descriptor);
            Assert.IsFalse(AssemblyProbingFolder.AssemblyExists(descriptor));
        }