Beispiel #1
0
 public PlginModel(ICommand plugin, ICommandUI pluginUI, ICommandWorkSpace pluginWks, string pluginName)
 {
     this._pluginWks  = pluginWks;
     this._plugin     = plugin;
     this._pluginUI   = pluginUI;
     this._pluginName = pluginName;
 }
        public void QueryContextMenu(ICommandUI ui, object obj)
        {
//            var diagramNode = obj as DiagramNodeViewModel;
//            if (diagramNode != null)
//            {
//                ui.AddCommand(new OpenWinCommand());
//            }
        }
        public void QueryContextMenu(ICommandUI ui, object obj)
        {
//            var diagramNode = obj as DiagramNodeViewModel;
//            if (diagramNode != null)
//            {
//                ui.AddCommand(new OpenWinCommand());
//            }
        }
Beispiel #4
0
    public void Use(ICommandUI commadUI)
    {
        if (lastCommandUI != null && lastCommandUI != commadUI)
        {
            lastCommandUI.EnableCommand();
        }

        lastCommandUI = commadUI;
    }
Beispiel #5
0
        /// <summary>
        /// 搜索插件
        /// </summary>
        public void SearchPlugin()
        {
            //遍历启动目前下所有dll
            string[] files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + @"\\" + _plugPath);
            //
            foreach (string file in files)
            {
                //确定结尾
                if (file.ToUpper().EndsWith(_startWith.ToUpper()) && !LoadedList.Contains(file))
                {
                    //已加载的列表中不存在file,则新增
                    LoadedList.Add(file);
                    try
                    {
                        Assembly assembly = null;
                        //将插件拷贝到内存缓冲
                        byte[] addinStream = null;
                        using (System.IO.FileStream input = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                        {
                            BinaryReader reader = new BinaryReader(input);
                            addinStream = reader.ReadBytes((int)input.Length);
                        }
                        //加载内存中的Dll
                        assembly = Assembly.Load(addinStream);
                        Type[] types = assembly.GetTypes();

                        //生成传入参数
                        object[] args = new object[1];
                        args[0] = assembly;

                        foreach (Type element in types)
                        {
                            try
                            {
                                string            plgName   = element.FullName;
                                ICommand          plugin    = null;
                                ICommandUI        pluginUI  = null;
                                ICommandWorkSpace pluginWks = null;
                                //command初始化时执行new操作,其他情况则只执行转换操作
                                if (element.GetInterface(_ifcmd) != null)
                                {
                                    plugin = assembly.CreateInstance(element.FullName, true, System.Reflection.BindingFlags.Default, null,
                                                                     //传入参数
                                                                     args,
                                                                     //
                                                                     null, null) as ICommand;
                                }
                                //commandUI
                                if (element.GetInterface(_ifcui) != null)
                                {
                                    pluginUI = plugin as ICommandUI;
                                }
                                //
                                if (element.GetInterface(_ifcwks) != null)
                                {
                                    pluginWks = plugin as ICommandWorkSpace;
                                }
                                if (plugin == null & pluginUI == null & pluginWks == null)
                                {
                                    continue;
                                }
                                //查找是否存在plugin
                                if (CmdPlgin.HasPlugin(plgName))
                                {
                                    CmdPlgin.FindPlugin(plgName).Plugin          = CmdPlgin.FindPlugin(plgName).Plugin == null ? plugin : CmdPlgin.FindPlugin(plgName).Plugin;
                                    CmdPlgin.FindPlugin(plgName).PluginUI        = CmdPlgin.FindPlugin(plgName).PluginUI == null ? pluginUI : CmdPlgin.FindPlugin(plgName).PluginUI;
                                    CmdPlgin.FindPlugin(plgName).PluginWorkSpace = CmdPlgin.FindPlugin(plgName).PluginWorkSpace == null ? pluginWks : CmdPlgin.FindPlugin(plgName).PluginWorkSpace;
                                }
                                else
                                {
                                    PlginModel newPlugin = new PlginModel(plugin, pluginUI, pluginWks, plgName);
                                    CmdPlgin.Add(newPlugin);
                                }
                                //加载UI
                                if (pluginUI != null)
                                {
                                    Function.ExtSington.AttributeControl.AddTable(pluginUI.UserContrl);
                                    pluginUI.IsAdded = true;
                                }
                                //加载插件
                                if (plugin != null)
                                {
                                    _outPut.Add(plugin.OutPut);
                                }
                            }
                            catch
                            {
                                continue;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }