示例#1
0
        public override Assembly Deploy(FileInfo dllFile)
        {
            var      newDllFile = CopyToDynamicDirectory(dllFile);
            Assembly assembly   = Assembly.LoadFrom(newDllFile.FullName);
            var      plusInfo   = this.GetPluginInfo(assembly, dllFile);

            switch (plusInfo.PlusConfigInfo.AssemblyType)
            {
            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.WF:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Resource:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Code:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Theme:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Strategy:
                this.LoadPlusStrategys(assembly);
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Models:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.MVC:
            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.MVCHome:
            {
                //配置插件路由
                MvcConfigManager.Config(assembly, plusInfo.PlusConfigInfo.AssemblyType);
            }
            break;

            default:
                break;
            }
            //将程序集添加到当前应用程序域
            BuildManager.AddReferencedAssembly(assembly);
            //执行插件初始化函数
            assembly.GetTypes().Where(p => p.IsClass && p.GetInterface(typeof(IPlus).FullName) != null).Each(
                t =>
            {
                using (new CodeWatch("Plu Initialize", 3000))
                {
                    try
                    {
                        var type = (IPlus)Activator.CreateInstance(t);
                        type.Initialize();
                    }
                    catch (Exception ex)
                    {
                        throw new MagicodesException(string.Format("插件初始化失败!Assembly:{0},Type:{1}{2}", assembly.FullName, t.FullName, Environment.NewLine), ex);
                        //ApplicationLog.Log(LoggerLevels.Error, string.Format("Assembly:{0},Type:{1}{2}", assembly.FullName, t.FullName, Environment.NewLine), ex);
                    }
                }
            });
            return(assembly);
        }
示例#2
0
        public override Assembly Deploy(FileInfo dllFile)
        {
            var      newDllFile = CopyToDynamicDirectory(dllFile);
            Assembly assembly   = Assembly.LoadFrom(newDllFile.FullName);
            var      plusInfo   = this.GetPluginInfo(assembly, dllFile);

            switch (plusInfo.PlusConfigInfo.AssemblyType)
            {
            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.WF:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Resource:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Code:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Theme:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Strategy:
                this.LoadPlusStrategys(assembly);
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Models:
                break;

            case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.MVC:
            {
                //配置插件路由
                MvcConfigManager.Config(assembly, plusInfo.PlusConfigInfo);
                break;
            }
            break;

            default:
                break;
            }
            try
            {
                //将程序集添加到当前应用程序域
                BuildManager.AddReferencedAssembly(assembly);
                //执行插件初始化函数
                assembly.GetTypes().Where(p => p.IsClass && p.GetInterface(typeof(IPlus).FullName) != null).Each(
                    t =>
                {
                    using (new CodeWatch("Plu Initialize", 3000))
                    {
                        try
                        {
                            var type = (IPlus)Activator.CreateInstance(t);
                            type.Initialize();
                        }
                        catch (Exception ex)
                        {
                            throw new MagicodesException(string.Format("插件初始化失败!Assembly:{0},Type:{1}{2}", assembly.FullName, t.FullName, Environment.NewLine), ex);
                        }
                    }
                });
            }
            catch (FileLoadException ex)
            {
                throw new MagicodesException(string.Format("加载此程序失败!Assembly:{0},FileName:{1}", assembly.FullName, ex.FileName), ex);
            }
            catch (System.Reflection.ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                throw new MagicodesException(errorMessage);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(assembly);
        }