Beispiel #1
0
        /// <summary>
        /// 设置默认插件
        /// </summary>
        /// <param name="systemName">插件系统名称</param>
        public static void Default(string systemName)
        {
            lock (_locker)
            {
                if (string.IsNullOrEmpty(systemName))
                {
                    return;
                }

                PluginInfo             pluginInfo = null;
                Predicate <PluginInfo> condition  = x => x.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase);
                pluginInfo = _oauthpluginlist.Find(condition);
                if (pluginInfo == null)
                {
                    pluginInfo = _paypluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _shippluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _uninstalledpluginlist.Find(condition);
                }

                //当插件为空时直接返回
                if (pluginInfo == null)
                {
                    return;
                }

                List <PluginInfo> updatePluginList = new List <PluginInfo>();
                if (pluginInfo.Type == 0)
                {
                    foreach (PluginInfo info in _oauthpluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }
                else if (pluginInfo.Type == 1)
                {
                    foreach (PluginInfo info in _paypluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }
                else
                {
                    foreach (PluginInfo info in _shippluginlist)
                    {
                        if (info.IsDefault == 1)
                        {
                            info.IsDefault = 0;
                            updatePluginList.Add(info);
                        }
                    }
                }

                foreach (PluginInfo info in _uninstalledpluginlist)
                {
                    if (info.Type == pluginInfo.Type && info.IsDefault == 1)
                    {
                        info.IsDefault = 0;
                        updatePluginList.Add(info);
                    }
                }

                pluginInfo.IsDefault = 1;
                updatePluginList.Add(pluginInfo);

                //将插件信息持久化到对应文件中
                foreach (PluginInfo info in updatePluginList)
                {
                    IOHelper.SerializeToXml(info, IOHelper.GetMapPath("/plugins/" + info.Folder + "/plugin.config"));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 加载插件程序集到应用程序域中
        /// </summary>
        public static void Load()
        {
            try
            {
                //插件目录
                DirectoryInfo pluginFolder = new DirectoryInfo(IOHelper.GetMapPath(_pluginfolderpath));
                if (!pluginFolder.Exists)
                {
                    pluginFolder.Create();
                }
                //插件bin目录
                DirectoryInfo shadowFolder = new DirectoryInfo(IOHelper.GetMapPath(_shadowfolderpath));
                if (!shadowFolder.Exists)
                {
                    shadowFolder.Create();
                }
                else
                {
                    //清空影子复制目录中的dll文件
                    foreach (FileInfo fileInfo in shadowFolder.GetFiles())
                    {
                        fileInfo.Delete();
                    }
                }

                //获得安装的插件系统名称列表
                List <string> installedPluginSystemNameList = GetInstalledPluginSystemNameList();
                //获得全部插件
                List <KeyValuePair <FileInfo, PluginInfo> > allPluginFileAndInfo = GetAllPluginFileAndInfo(pluginFolder);
                foreach (KeyValuePair <FileInfo, PluginInfo> fileAndInfo in allPluginFileAndInfo)
                {
                    FileInfo   pluginFile = fileAndInfo.Key;
                    PluginInfo pluginInfo = fileAndInfo.Value;

                    if (String.IsNullOrWhiteSpace(pluginInfo.SystemName))
                    {
                        throw new BSPException(string.Format("插件'{0}'没有\"systemName\", 请输入一个唯一的\"systemName\"", pluginFile.FullName));
                    }
                    if (pluginInfo.Type < 0 || pluginInfo.Type > 2)
                    {
                        throw new BSPException(string.Format("插件'{0}'不属于任何一种类型, 请输入正确的的\"type\"", pluginFile.FullName));
                    }

                    //加载插件dll文件
                    FileInfo[] dllFiles = pluginFile.Directory.GetFiles("*.dll", SearchOption.TopDirectoryOnly);
                    foreach (FileInfo dllFile in dllFiles)
                    {
                        //部署dll文件
                        DeployDllFile(dllFile, shadowFolder);
                    }

                    if (IsInstalledlPlugin(pluginInfo.SystemName, installedPluginSystemNameList))//安装的插件
                    {
                        //根据插件类型将插件添加到相应列表
                        switch (pluginInfo.Type)
                        {
                        case 0:
                            _oauthpluginlist.Add(pluginInfo);
                            break;

                        case 1:
                            _paypluginlist.Add(pluginInfo);
                            break;

                        case 2:
                            _shippluginlist.Add(pluginInfo);
                            break;
                        }
                    }
                    else//未安装的插件
                    {
                        _uninstalledpluginlist.Add(pluginInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new BSPException("加载OWZX插件时出错", ex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 编辑插件信息
        /// </summary>
        /// <param name="systemName">插件系统名称</param>
        /// <param name="friendlyName">插件友好名称</param>
        /// <param name="description">插件描述</param>
        /// <param name="displayOrder">插件排序</param>
        public static void Edit(string systemName, string friendlyName, string description, int displayOrder)
        {
            lock (_locker)
            {
                bool                   isInstalled = true;//是否安装
                PluginInfo             pluginInfo  = null;
                Predicate <PluginInfo> condition   = x => x.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase);

                pluginInfo = _oauthpluginlist.Find(condition);
                if (pluginInfo == null)
                {
                    pluginInfo = _paypluginlist.Find(condition);
                }
                if (pluginInfo == null)
                {
                    pluginInfo = _shippluginlist.Find(condition);
                }

                //当插件为空时直接返回
                if (pluginInfo == null)
                {
                    pluginInfo = _uninstalledpluginlist.Find(condition);;
                    //当插件为空时直接返回
                    if (pluginInfo == null)
                    {
                        return;
                    }
                    else
                    {
                        isInstalled = false;
                    }
                }

                pluginInfo.FriendlyName = friendlyName;
                pluginInfo.Description  = description;
                pluginInfo.DisplayOrder = displayOrder;

                //将插件信息持久化到对应文件中
                IOHelper.SerializeToXml(pluginInfo, IOHelper.GetMapPath("/plugins/" + pluginInfo.Folder + "/plugin.config"));

                //插件列表重新排序
                if (isInstalled)
                {
                    switch (pluginInfo.Type)
                    {
                    case 0:
                        _oauthpluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;

                    case 1:
                        _paypluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;

                    case 2:
                        _shippluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                        break;
                    }
                }
                else
                {
                    _uninstalledpluginlist.Sort((first, next) => first.DisplayOrder.CompareTo(next.DisplayOrder));
                }
            }
        }