Ejemplo n.º 1
0
 public void AddIns(string ID)
 {
     if (HttpContext.Current.Request.HttpMethod == "POST")
     {
         AddInManager.CreateAddInAppDomain(ID);
         AddInManager.LoadAddInDll(ID, "");
     }
 }
Ejemplo n.º 2
0
 public void AddAddIn(string ID, string Path)
 {
     try
     {
         Path = "G:\\Project\\NET\\DynamicDllLoad\\Plug-inDll\\bin\\Debug\\Plug-inDll.dll";
         AddInManager.CreateAddInAppDomain(ID);
         AddInManager.LoadAddInDll(ID, Path);
         HttpContext.Current.Response.Write("加载成功!");
     }
     catch (Exception ex)
     {
         HttpContext.Current.Response.Write(ex.Message);
     }
 }
Ejemplo n.º 3
0
 public void LoadAddIn(List <AddIn> AddIns)
 {
     try
     {
         foreach (AddIn current in AddIns)
         {
             if (current.AppDomainStatus == 1)
             {
                 string text = ConfigurationManager.AppSettings["AddInPath"].ToString() + "\\" + current.ControllerName + "\\";
                 if (!Directory.Exists(text))
                 {
                     throw new Exception("插件路径错误:" + text);
                 }
                 AddInManager.CreateAddInAppDomain(current.ControllerName);
                 AddInManager.LoadAddInDll(current.ControllerName, text + current.DllName);
             }
         }
     }
     catch (Exception ex)
     {
         Log.log(ex.ToString());
     }
 }
        public ActionResult AddInDomain(string ID)
        {
            HttpRequest  request = HttpContext.Current.Request;
            ActionResult result;

            try
            {
                SqlHelper sqlHelper = new SqlHelper();
                DataTable dataTable = sqlHelper.ExecuteDataTable("select * from T_AddIn where f_id = " + ID, new SqlParameter[0]);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    string        appDomainName = dataTable.Rows[0]["F_AppDomain_Name"].ToString();
                    string        description   = dataTable.Rows[0]["F_Description"].ToString();
                    string        status        = dataTable.Rows[0]["F_Status"].ToString();
                    List <object> list          = new List <object>();
                    if (!AddInManager.AppDomains.ContainsKey(appDomainName))
                    {
                        result = this.RazorEngineView(new
                        {
                            ID            = ID,
                            AppDomainName = appDomainName,
                            Description   = description,
                            Status        = status,
                            Controllers   = list
                        });
                    }
                    else
                    {
                        if (AddInManager.Loaders[appDomainName] == null)
                        {
                            AddInManager.CreateAddInAppDomain(appDomainName);
                            AddIn.Common.Log.Write("创建新的代理类。");
                        }
                        try
                        {
                            foreach (IController current in AddInManager.Loaders[appDomainName].GetControllers())
                            {
                                List <object> list2 = new List <object>();
                                foreach (IAction current2 in current.Actions)
                                {
                                    List <object> list3 = new List <object>();
                                    foreach (IParameter current3 in current2.Parameters)
                                    {
                                        var item = new
                                        {
                                            ParameterName = current3.ParameterName,
                                            ParameterType = current3.ParameterType.Name
                                        };
                                        list3.Add(item);
                                    }
                                    var item2 = new
                                    {
                                        ActionName  = current2.ActionName,
                                        ReturnType  = current2.ReturnType.Name,
                                        HttpMethod  = current2.HttpMethod,
                                        Description = current2.Description,
                                        Parameters  = list3
                                    };
                                    list2.Add(item2);
                                }
                                var item3 = new
                                {
                                    ControllerName = current.ControllerName,
                                    Actions        = list2
                                };
                                list.Add(item3);
                            }
                        }
                        catch (Exception ex)
                        {
                            AddInWebApp.Common.Log.log(ex.ToString());
                        }
                        result = this.RazorEngineView(new
                        {
                            ID            = ID,
                            AppDomainName = appDomainName,
                            Description   = description,
                            Status        = status,
                            Controllers   = list
                        });
                    }
                }
                else
                {
                    result = this.Json(new
                    {
                        errcode = 0,
                        errmsg  = "OK",
                        msgdoc  = string.Concat(new object[]
                        {
                            "http://",
                            request.Url.Host,
                            ":",
                            request.Url.Port,
                            "/AddInsDomain/help/doc"
                        })
                    }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex2)
            {
                result = this.Json(new
                {
                    errcode = -1,
                    errmsg  = ex2.Message,
                    msgdoc  = string.Concat(new object[]
                    {
                        "http://",
                        request.Url.Host,
                        ":",
                        request.Url.Port,
                        "/AddInsDomain/help/doc"
                    })
                }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
Ejemplo n.º 5
0
        //public void AddIns()
        //{
        //    if (HttpContext.Current.Request.HttpMethod == "GET")
        //    {
        //        string html = "<ul>";
        //        foreach (var domain in AddInManager.AppDomains)
        //        {
        //            html += "<li><span>" + domain.Key + "</span><ul>";

        //            foreach (var c in AddInManager.Loaders[domain.Key].Controllers)
        //            {
        //                html += "<li><span>" + c.ControllerName + "</span><ul>";
        //                foreach (var a in c.Actions)
        //                {
        //                    html += "<li><span>" + a.ActionName + "():" + a.ReturnType.Name + "</span><ul>";

        //                    foreach (var p in a.Parameters)
        //                    {
        //                        html += "<li>" + p.ParameterName + ":" + p.ParameterType.Name + "</li>";
        //                    }
        //                    html += "</ul></li>";
        //                }
        //                html += "</ul></li>";
        //            }
        //            html += "</ul></li>";
        //        }
        //        html += "</ul>";
        //        HttpContext.Current.Response.Write(html);
        //    }

        //}

        public ActionResult AddIns()
        {
            //if (HttpContext.Current.Request.HttpMethod == "GET")
            //{

            //    List<dynamic> models = new List<dynamic>();
            //    foreach (var domain in AddInManager.AppDomains)
            //    {
            //        //初始化动态类型
            //        dynamic model = new ExpandoObject();
            //        model.AddInDomain = domain.Key;

            //        //controllers 集合变量
            //        List<dynamic> controllers = new List<dynamic>();
            //        foreach (var c in AddInManager.Loaders[domain.Key].Controllers)
            //        {
            //            dynamic controller = new ExpandoObject();
            //            controller.ControllerName = c.ControllerName;
            //            List<dynamic> actions = new List<dynamic>();
            //            foreach (var a in c.Actions)
            //            {
            //                dynamic action = new ExpandoObject();
            //                action.ActionName = a.ActionName;
            //                action.ReturnType = a.ReturnType.Name;

            //                List<dynamic> parameters = new List<dynamic>();
            //                foreach (var p in a.Parameters)
            //                {
            //                    dynamic parameter = new ExpandoObject();
            //                    parameter.ParameterName = p.ParameterName;
            //                    parameter.ParameterType = p.ParameterType.Name;
            //                    parameters.Add(parameter);
            //                }
            //                action.Parameters = parameters;
            //                actions.Add(action);
            //            }
            //            controller.Actions = actions;
            //            controllers.Add(controller);
            //        }

            //        model.Controllers = controllers;
            //        models.Add(model);
            //    }
            //    //return VelocityView(models);
            //    return Json(models, JsonRequestBehavior.AllowGet);
            //}

            if (HttpContext.Current.Request.HttpMethod == "GET")
            {
                List <dynamic> models = new List <dynamic>();

                foreach (var domain in AddInManager.AppDomains)
                {
                    //初始化动态类型
                    dynamic model = new ExpandoObject();
                    model.AddInDomain = domain.Key;
                    //controllers 集合变量
                    List <dynamic> controllers  = new List <dynamic>();
                    var            _controllers = new { };

                    // 当Loader被回收 ,创建新的代理类。
                    if (AddInManager.Loaders[domain.Key] == null)
                    {
                        AddInManager.CreateAddInAppDomain(domain.Key);
                        AddIn.Common.Log.Write("创建新的代理类。");
                    }
                    try
                    {
                        foreach (var c in AddInManager.Loaders[domain.Key].GetControllers())
                        {
                            List <dynamic> actions = new List <dynamic>();
                            foreach (var a in c.Actions)
                            {
                                List <dynamic> parameters = new List <dynamic>();
                                foreach (var p in a.Parameters)
                                {
                                    var _parameter = new { ParameterName = p.ParameterName, ParameterType = p.ParameterType.Name };
                                    parameters.Add(_parameter);
                                }
                                var _action = new { ActionName = a.ActionName, ReturnType = a.ReturnType.Name, HttpMethod = a.HttpMethod, Description = a.Description, Parameters = parameters };
                                actions.Add(_action);
                            }
                            var _controller = new { ControllerName = c.ControllerName, Actions = actions };
                            controllers.Add(_controller);
                        }
                    }
                    catch (Exception e)
                    {
                        Common.Log.log(e.ToString());
                        //return VelocityView(e.ToString());
                        return(VelocityView(models));
                    }
                    var _model = new { AddInDomain = domain.Key, Controllers = controllers };
                    models.Add(_model);
                }

                return(VelocityView(models));
                //return Json(models, JsonRequestBehavior.AllowGet);
            }
            return(null);
        }