Пример #1
0
 /// <summary>加载组件
 /// </summary>
 /// <param name="plugin"></param>
 public static void LoadPlugin(PluginEntity plugin)
 {
     lock (_Plugins)
     {
         if (!_Plugins.Exists(p => p.Id == plugin.Id))
         {
             string webPath = _ApplicationBase + plugin.Name + "\\" + plugin.PVersion + "\\";
             string appPath = webPath + "bin\\";
             try
             {
                 System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\bin\\Huber.SandBonDriver.dll", appPath + "Huber.SandBonDriver.dll", true);
                 System.IO.File.Copy(AppDomain.CurrentDomain.BaseDirectory + "Huber.Kernel.dll", appPath + "Huber.Kernel.dll", true);
             }
             catch (Exception)
             {
             }
             var loader = new SandBoxDynamicLoader(
                 appPath,
                 string.Format(_AppdomainName, plugin.Name, plugin.PVersion.ToString()),
                 webPath + "Web.config",
                 plugin.Id);
             loader.LoadAssembly(appPath + plugin.Name + ".dll");
             _LoaderDic.Add(loader.PluginName, loader);
             _Plugins.Add(plugin);
             AddUrls(loader);
             loader.InvokeMothod("Huber.Kernel.Entity.HuberVariable", "SetCurWebDir", webPath, "/Plugins/" + plugin.Name + "/" + plugin.PVersion);
         }
     }
 }
Пример #2
0
        /// <summary>根据url获取其所属的子应用程序域
        /// </summary>
        /// <param name="pluginName"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public static SandBoxDynamicLoader getSandBox(string pluginName, int version)
        {
            SandBoxDynamicLoader result = null;

            _LoaderDic.TryGetValue(string.Format(_AppdomainName, pluginName, version), out result);
            return(result);
        }
Пример #3
0
        private static void AddUrls(SandBoxDynamicLoader loader)
        {
            Dictionary <string, CAModel> Urls = loader.GetAllAction();

            foreach (var url in Urls)
            {
                try
                {
                    AllUrl.Add(url.Value.UrlPath);
                }
                catch (Exception)
                { }
                try
                {
                    UrlRefAction.Add(url.Key, url.Value);
                }
                catch (Exception)
                { }
            }
        }
Пример #4
0
        // 请求拦截
        private void Application_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            HttpResponse    respond     = application.Response;
            HttpRequest     request     = application.Request;
            string          url         = request.Url.AbsolutePath.ToString();

            //如果请求以“/plugins/”开头,表面我们需要对该请求做拦截处理了。
            if (url.ToLower().StartsWith("/plugins/"))
            {
                string action = url.Substring(url.LastIndexOf("/") + 1);
                //如果是非静态文件,即是action
                if (action.IndexOf(".") < 0)
                {
                    #region 匹配controller和action

                    var urlEntity = HuberPluginHandle.getUrlPathEntity(url.Substring(8), true);
                    #endregion
                    if (urlEntity != null && urlEntity.controller != null)
                    {
                        #region 获取路径中的插件名称等信息

                        #endregion
                        SandBoxDynamicLoader sandBox = HuberPluginHandle.getSandBox(urlEntity.pluginname, urlEntity.pluginversion);

                        if (sandBox != null)
                        {
                            List <RightEntity> userRight = new List <RightEntity>();
                            string             uid       = string.Empty;
                            int login = new UserBll().chekLogin(ref uid, false, userRight);
                            if (login == 2)//验证用户是否具有访问的权限
                            {
                                RefRequestEntity paras = new RefRequestEntity();
                                paras.PageRights = userRight;
                                paras.UserID     = uid;
                                #region 获取http参数
                                RequestHandle.FillCorRefEntity(paras, request);
                                #endregion
                                //sandBox.InvokeMothod(urlEntity.controller, "InitChannel", paras)
                                var result = sandBox.InvokeMothod(urlEntity.controller, urlEntity.action, paras);
                                RequestHandle.ResposeResult(respond, result);
                            }
                            else if (login == 1)
                            {
                                RequestHandle.ResponseNoRight(request, respond);
                            }
                            else
                            {
                                RequestHandle.ResponseNoLogin(request, respond);
                            }
                        }
                    }
                    else
                    {
                        RequestHandle.ResponseNotfound(request, respond);;
                    }

                    respond.End();
                }
            }
            else
            {
                if (!url.ToLower().Equals("/user/login"))
                {
                    string action = url.Substring(url.LastIndexOf("/") + 1);
                    if (action.IndexOf(".") < 0)
                    {
                        List <RightEntity> userRight = new List <RightEntity>();
                        string             uid       = string.Empty;
                        int login = new UserBll().chekLogin(ref uid, false, userRight);
                        if (login == 2)//验证用户是否具有访问的权限
                        {
                        }
                        else if (login == 1)
                        {
                            RequestHandle.ResponseNoRight(request, respond);
                        }
                        else
                        {
                            RequestHandle.ResponseNoLogin(request, respond);
                        }
                    }
                }
            }
        }