Exemplo n.º 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);

                }

            }
        }
Exemplo n.º 2
0
        private MenuEntity GetMenu(RightEntity rightEntity, PluginEntity pluginEntity)
        {
            string startWith = "/" + pluginEntity.Name + "/" ;
            string replace = "/" + pluginEntity.Name + "/" +pluginEntity.PVersion + "/";

            MenuEntity mm = new MenuEntity(rightEntity.Id, rightEntity.Name, "/plugins" + rightEntity.Url.Replace(startWith, replace), false, pluginEntity.Icon);
            foreach (var item in rightEntity.Children)
            {
                mm.Children.Add(GetMenu(item, pluginEntity));
            }
            return mm;
        }
Exemplo n.º 3
0
        /// <summary>启动插件 
        /// </summary>
        /// <param name="plugipEntity"></param>
        public void StartPlugins(PluginEntity plugipEntity)
        {
            //PluginDescriptor pluginDescriptor = PluginLoader.Load(plugipEntity);
            //if (pluginDescriptor == null)
            //{
            //    return;
            //}
            //Type[] types = pluginDescriptor.PluginAssembly.GetTypes();
            ////继承的MVC控制器版本必须是程序集 System.Web.Mvc.dll, v4.0.0.0
            //pluginDescriptor.ControllerTypes = types.Where(t => typeof(IController).IsAssignableFrom(t) && t.Name.EndsWith("Controller")).ToArray();

            //RouteValueDictionary routeValueDictionary = new RouteValueDictionary
            //{
            //    {"controller", plugipEntity.DefaultController},
            //    {"action", plugipEntity.DefaultAction},
            //    {"id", UrlParameter.Optional},
            //    {"pluginName", plugipEntity.Name}
            //};
            //Route route = new Route("plugins" + "/" + pluginDescriptor.Plugin.Name + "/{controller}/{action}/{id}", routeValueDictionary, new MvcRouteHandler(ControllerBuilder.Current.GetControllerFactory()));
            //RouteTable.Routes.Insert(0, route);
            //PluginDescriptorlist.Add(pluginDescriptor);
        }
Exemplo n.º 4
0
 /// <summary>添加模块 
 /// </summary>
 /// <param name="pluginEntity"></param>
 /// <returns></returns>
 public string AddModule(PluginEntity pluginEntity)
 {
     if (Request.Files.Count < 1)
     {
         return "0";
     }
     HttpPostedFileBase fileBase = Request.Files[0];
     if (fileBase == null || !fileBase.FileName.EndsWith(".zip"))
     {
         return "0";
     }
     pluginEntity.Icon = "fa fa-files-o";
     pluginEntity.DefaultAction = string.Empty;
     pluginEntity.DefaultController = string.Empty;
     PluginEntity result = _PluginBll.AddPlugin(pluginEntity);
     if (result != null)
     {
         saveZip(fileBase, result);
         UnZipFile(pluginEntity, fileBase.InputStream);
         return "1";
     }
     return "-2";
 }
Exemplo n.º 5
0
        /// <summary>卸载组件
        /// </summary>
        /// <param name="plugin"></param>
        public static void UnLoadPlugin(PluginEntity plugin)
        {
            lock (_Plugins)
            {
                if (_Plugins.Exists(p => p.Id == plugin.Id))
                {
                    var loader = getSandBox(plugin.Name, plugin.PVersion);
                    loader.Unload();
                    _LoaderDic.Remove(loader.PluginName);
                    var plist = _Plugins.Where(p => p.Id == plugin.Id);
                    if (plist.Any())
                    {
                        var pplist = plist.ToList();
                        for (int i = 0; i < pplist.Count; i++)
                        {
                            _Plugins.Remove(pplist[i]);
                            break;
                        }
                    }

                }

            }
        }
Exemplo n.º 6
0
        /// <summary>添加插件,暂不启用 
        /// </summary>
        /// <param name="pluginEntity"></param>
        /// <returns>如果该插件已存在则返回null</returns>
        public PluginEntity AddPlugin(PluginEntity pluginEntity)
        {
            lock (PluginDao)
            {
                int result = 0;
                if (!PluginDao.ExsitPlugin(pluginEntity.Name, pluginEntity.PVersion))
                {

                    pluginEntity.MenuShow = 0;
                    pluginEntity.Status = 0;
                    pluginEntity.DefaultAction = string.Empty;
                    pluginEntity.DefaultController = string.Empty;
                    result = PluginDao.AddPlugin(pluginEntity);
                    if (result > 0)
                    {
                        pluginEntity.Id = PluginDao.GetMaxID();
                        return pluginEntity;
                    }
                }
                return null;
            }

        }
Exemplo n.º 7
0
        private static void saveZip(HttpPostedFileBase fileBase, PluginEntity pluginEntity)
        {
            string dirName = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\Plugin_updates_temp\\";
            string zipName = dirName + pluginEntity.Name + "." + pluginEntity.PVersion + ".zip";
            if (!Directory.Exists(dirName))
            {
                lock (_PluginBll)
                {
                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }
                }
            }

            fileBase.SaveAs(zipName);//保存文件

        }
Exemplo n.º 8
0
        /// <summary>解压 
        /// </summary>
        /// <param name="zipName"></param>
        /// <param name="baseStream"></param>
        private static void UnZipFile(PluginEntity pluginEntity, Stream baseStream)
        {
            using (ZipInputStream s = new ZipInputStream(baseStream))
            {
                string baseDir = AppDomain.CurrentDomain.BaseDirectory + "Plugins\\" + pluginEntity.Name + "\\" + pluginEntity.PVersion + "\\";
                ZipEntry theEntry;
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = baseDir + Path.GetDirectoryName(theEntry.Name) + "\\";
                    string fileName = Path.GetFileName(theEntry.Name);

                    // create directory
                    if (!string.IsNullOrEmpty(directoryName))
                    {
                        Directory.CreateDirectory(directoryName);
                    }

                    if (fileName != String.Empty)
                    {
                        using (FileStream streamWriter = System.IO.File.Create(directoryName + fileName))
                        {
                            byte[] data = new byte[2048];
                            while (true)
                            {
                                var size = s.Read(data, 0, data.Length);
                                if (size > 0)
                                {
                                    streamWriter.Write(data, 0, size);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }

                }


            }
        }
Exemplo n.º 9
0
        /// <summary>添加插件(不启动) 
        /// </summary>
        public int AddPlugin(PluginEntity pluginDescriptor)
        {
            const string sql = "insert into t_plugin (Name,Describe,Author,DefaultController,DefaultAction,PVersion,MenuShow,Icon) values (@Name,@Describe,@Author,@DefaultController,@DefaultAction,@PVersion,@MenuShow,@Icon)";
            int result = 0;
            SQLiteParameter[] para = new SQLiteParameter[]
            {
                new SQLiteParameter("@Name", pluginDescriptor.Name),
                new SQLiteParameter("@Describe", pluginDescriptor.Describe),
                new SQLiteParameter("@Author", pluginDescriptor.Author),
                new SQLiteParameter("@DefaultController", pluginDescriptor.DefaultController),
                new SQLiteParameter("@DefaultAction", pluginDescriptor.DefaultAction),
                new SQLiteParameter("@PVersion", pluginDescriptor.PVersion),
                new SQLiteParameter("@MenuShow", pluginDescriptor.MenuShow),
                new SQLiteParameter("@Icon", pluginDescriptor.Icon)
            };
            try
            {
                result = new SqlLiteHelper().RunSQL(sql, para);
            }
            catch (Exception ex)
            {

            }
            return result;
        }
Exemplo n.º 10
0
 /// <summary>将row转换为实体类 
 /// </summary>
 /// <param name="dataRow"></param>
 /// <returns></returns>
 private static PluginEntity Convert2Entity(DataRow dataRow)
 {
     PluginEntity pluginEntity = new PluginEntity();
     pluginEntity.Id = Int32.Parse(dataRow["Id"].ToString());
     pluginEntity.Name = dataRow["Name"].ToString();
     pluginEntity.Status = Int32.Parse(dataRow["Status"].ToString());
     pluginEntity.Describe = dataRow["Describe"].ToString();
     pluginEntity.DefaultAction = dataRow["DefaultAction"].ToString();
     pluginEntity.DefaultController = dataRow["DefaultController"].ToString();
     pluginEntity.Author = dataRow["Author"].ToString();
     pluginEntity.PVersion = int.Parse(dataRow["PVersion"].ToString());
     pluginEntity.MenuShow = int.Parse(dataRow["MenuShow"].ToString());
     pluginEntity.Icon = dataRow["Icon"].ToString();
     return pluginEntity;
 }