Esempio n. 1
0
        private static Dictionary <AddinManagerAssembly, List <IWordExCommand> > DeserializeAssemblies(
            AssemblyInfos amInfos)
        {
            Dictionary <AddinManagerAssembly, List <IWordExCommand> > nodesInfo;

            nodesInfo = new Dictionary <AddinManagerAssembly, List <IWordExCommand> >(new AssemblyComparer());
            //
            if (amInfos != null)
            {
                foreach (string assemblyPath in amInfos.AssemblyPaths)
                {
                    if (File.Exists(assemblyPath))
                    {
                        // 将每一个程序集中的外部命令提取出来
                        List <IWordExCommand> m = ExCommandFinder.RetriveExternalCommandsFromAssembly(assemblyPath);
                        if (m.Any())
                        {
                            Assembly             ass        = m[0].GetType().Assembly;
                            AddinManagerAssembly amAssembly = new AddinManagerAssembly(assemblyPath, ass);
                            if (nodesInfo.ContainsKey(amAssembly))
                            {
                                nodesInfo[amAssembly] = m;
                            }
                            else
                            {
                                nodesInfo.Add(amAssembly, m);
                            }
                        }
                    }
                }
            }
            return(nodesInfo);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
                }
            }
        }