private static Dictionary <AddinManagerAssembly, List <IExcelExCommand> > DeserializeAssemblies(
            AssemblyInfos amInfos)
        {
            var nodesInfo = new Dictionary <AddinManagerAssembly, List <IExcelExCommand> >(new AssemblyComparer());

            //
            if (amInfos != null)
            {
                foreach (string assemblyPath in amInfos.AssemblyPaths)
                {
                    if (File.Exists(assemblyPath))
                    {
                        // 将每一个程序集中的外部命令提取出来
                        List <IExcelExCommand> 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);
        }
Beispiel #2
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            string[] dllPaths          = ChooseOpenDll("Choose an Addin file");
            bool     hasNewMethodAdded = false;

            //
            if (dllPaths != null)
            {
                foreach (string dllPath in dllPaths)
                {
                    if (string.IsNullOrEmpty(dllPath))
                    {
                        continue;
                    }
                    //
                    var methods = ExCommandFinder.RetriveExternalCommandsFromAssembly(dllPath);
                    if (methods.Any())
                    {
                        // 更新 Dictionary
                        AddMethodsInOneAssembly(dllPath, methods);
                        hasNewMethodAdded = true;
                    }
                }
            }

            if (hasNewMethodAdded)
            {
                // 刷新界面
                RefreshTreeView(_nodesInfo);
            }
        }
Beispiel #3
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);
                }
            }
        }