Example #1
0
        private static Dictionary <AddinManagerAssembly, List <ICADExCommand> > DeserializeAssemblies(
            AssemblyInfos amInfos)
        {
            var nodesInfo = new Dictionary <AddinManagerAssembly, List <ICADExCommand> >(new AssemblyComparer());

            //
            if (amInfos != null)
            {
                foreach (string assemblyPath in amInfos.AssemblyPaths)
                {
                    if (File.Exists(assemblyPath))
                    {
                        // 将每一个程序集中的外部命令提取出来
                        List <ICADExCommand> m = ExCommandFinder.RetriveExternalCommandsFromAssembly(assemblyPath);
                        if (m.Any())
                        {
                            Assembly             ass        = m[0].GetType().Assembly;
                            AddinManagerAssembly amAssembly = new AddinManagerAssembly(assemblyPath, ass);
                            nodesInfo.Add(amAssembly, m);
                        }
                    }
                }
            }
            return(nodesInfo);
        }
Example #2
0
        private void RemoveAssembly(TreeNode ndAss)
        {
            if (ndAss.Level != 0)
            {
                throw new ArgumentException("this is not a node representing an assembly.");
            }
            //
            AddinManagerAssembly asm = ndAss.Tag as AddinManagerAssembly;

            _nodesInfo.Remove(asm);
        }
Example #3
0
        private void RemoveMethod(TreeNode ndAss)
        {
            if (ndAss.Level != 1)
            {
                throw new ArgumentException("this is not a node representing an method.");
            }
            //
            AddinManagerAssembly asm = ndAss.Parent.Tag as AddinManagerAssembly;

            ICADExCommand mtd = ndAss.Tag as ICADExCommand;

            //
            _nodesInfo[asm].Remove(mtd);
        }
Example #4
0
        private void RunExternalCommand(TreeNode ndCommand)
        {
            var exCommand            = ndCommand.Tag as ICADExCommand;
            AddinManagerAssembly asm = ndCommand.Parent.Tag as AddinManagerAssembly;
            //
            string assemblyPath = asm.Path;

            //  ---------- 将窗口缩小 ----------
            if (checkBox_MinimizeWhileRun.Checked)
            {
                this.WindowState = FormWindowState.Minimized;
            }

            // 执行外部命令
            ExCommandExecutor.InvokeExternalCommand(assemblyPath, exCommand);
        }
Example #5
0
        private void button_Reload_Click(object sender, EventArgs e)
        {
            TreeNode nd    = treeView1.SelectedNode;
            TreeNode ndAss = null;

            if (nd == null)
            {
                return;
            }
            //
            if (nd.Level == 0) // 移除程序集
            {
                ndAss = nd;
            }
            else if (nd.Level == 1)// 移除某个方法所对应的程序集
            {
                ndAss = nd.Parent;
            }
            AddinManagerAssembly mtd = ndAss.Tag as AddinManagerAssembly;
            string assFullPath       = mtd.Path;

            // 重新加载此程序集
            if (!string.IsNullOrEmpty(assFullPath))
            {
                bool hasNewMethodAdded = false;
                //
                var methods = ExCommandFinder.RetriveExternalCommandsFromAssembly(assFullPath);
                if (methods.Any())
                {
                    // 更新 Dictionary
                    AddMethodsInOneAssembly(assFullPath, methods);
                    hasNewMethodAdded = true;
                }

                if (hasNewMethodAdded)
                {
                    // 刷新界面
                    RefreshTreeView(_nodesInfo);
                }
            }
        }
Example #6
0
        /// <summary>
        /// 将所有的外部命令刷新到列表控件中
        /// </summary>
        /// <param name="nodesInfo">字典中每一个程序集对应其中的多个外部命令</param>
        internal void RefreshTreeView(Dictionary <AddinManagerAssembly, List <ICADExCommand> > nodesInfo)
        {
            if (nodesInfo != null)
            {
                if (nodesInfo.Comparer.GetType() != typeof(AssemblyComparer))
                {
                    throw new ArgumentException("The dictionary used to synchronize the treeview must have an \"AssemblyComparer\".");
                }
                treeView1.Nodes.Clear();
                //
                foreach (var ndInfo in nodesInfo)
                {
                    AddinManagerAssembly asm     = ndInfo.Key;
                    List <ICADExCommand> methods = ndInfo.Value;

                    // 添加新的程序集
                    TreeNode tnAss = new TreeNode(asm.Assembly.ManifestModule.ScopeName);
                    tnAss.Tag = asm;
                    treeView1.Nodes.Add(tnAss);

                    // 添加此程序集中所有的外部命令
                    methods.Sort(new ExCmdCompare());
                    foreach (ICADExCommand m in methods)
                    {
                        TreeNode tnMethod = new TreeNode(m.GetType().FullName);
                        tnMethod.Tag = m;
                        tnAss.Nodes.Add(tnMethod);
                    }
                }

                // 刷新
                _nodesInfo = nodesInfo;
                //
                treeView1.ExpandAll();
                treeView1.Refresh();
            }
        }
Example #7
0
        /// <summary> 将从一个 Assembly 中加载进来的所有有效的外部命令同步到 _nodesInfo 中 </summary>
        /// <param name="methods"></param>
        private void AddMethodsInOneAssembly(string assemblyPath, List <ICADExCommand> methods)
        {
            AddinManagerAssembly asm;

            if (methods.Any())
            {
                asm = new AddinManagerAssembly(assemblyPath, methods.First().GetType().Assembly);
                //
                List <ICADExCommand> mds = new List <ICADExCommand>();
                foreach (var m in methods)
                {
                    mds.Add(m);
                }
                //
                if (_nodesInfo.ContainsKey(asm))  // 覆盖式刷新
                {
                    _nodesInfo[asm] = mds;
                }
                else  // 直接进行添加就可以了
                {
                    _nodesInfo.Add(asm, mds);
                }
            }
        }