SharpDevelop插件树(AddinTree)的建立过程

本文详细介绍了如何在SharpDevelop中构建和管理AddinTree,涉及插件的assembly加载、extension点定义、字符串处理、null检查及class和服务的注册与使用,为开发者提供了一个完整的插件开发流程。
摘要由CSDN通过智能技术生成

 

                                               插件树(AddinTree)
 
模式:
模式是决定架构,还是架构决定模式?
常用模式
Singleton
Factory
Decorator
Strategy
Memento
Proxy
AddinTree 的建立
A=> 加载服务
ServiceManager .Services.AddService(new IconService());
A.1=>
public static ServiceManager Services {
              get {
                   return defaultServiceManager;
              }
         }   
public ServiceManager()//bjarne private -> public
         {
              // add 'core' services
              AddService(new PropertyService());
              AddService(new StringParserService());
              AddService(new FileUtilityService());
         }
public void AddService(IService service)
         {
              serviceList.Add(service); // 装载服务的容器
         }
B=>
ServiceManager .Services.InitializeServicesSubsystem("/Workspace/Services");
B.1=>
public void InitializeServicesSubsystem(string servicesPath)
         {
处理插件树
              // add add-in tree services"/Workspace/Services"
     AddServices((IService[])AddInTreeSingleton.AddInTree.GetTreeNode(servicesPath).BuildChildItems(this).ToArray(typeof(IService)));      // B.1.1 //B.1.2//B.1.3
              // initialize all services
              foreach (IService service in serviceList) {
                   DateTime now = DateTime.Now;
                   service.InitializeService();
              }
         }   
B.1.1=>     public static IAddInTree AddInTree {
              get {
                   if (addInTree == null) {
                       CreateAddInTree(); 创建插件树
                   }
                   return addInTree;
              }
         }
static void CreateAddInTree() 创建插件树
         {
              addInTree = new DefaultAddInTree();
             
              FileUtilityService fileUtilityService = (FileUtilityService)ServiceManager.Services.GetService(typeof(FileUtilityService)); //B.1.1.1
             
              StringCollection addInFiles = null;
              StringCollection retryList = null;
             
            // 条件成立
              if (ignoreDefaultCoreDirectory == false) {
                   addInFiles = fileUtilityService.SearchDirectory(defaultCoreDirectory, "*.addin"); // 取得所有插件文件//B.1.1.2
 
                retryList = InsertAddIns(addInFiles); // 加载插件//B.1.1.3
              }
              else
                   retryList = new StringCollection();
             
              if (addInDirectories != null) {
                   foreach(string path in addInDirectories) {
                       addInFiles = fileUtilityService.SearchDirectory(path, "*.addin");
                    StringCollection partialRetryList = InsertAddIns(addInFiles); // 加载插件
                       if (partialRetryList.Count != 0) {
                            string [] retryListArray = new string[partialRetryList.Count];
                            partialRetryList.CopyTo(retryListArray, 0);
                            retryList.AddRange(retryListArray);
                       }
                   }
              }
              // 重试加载插件
              while (retryList.Count > 0) {
                   StringCollection newRetryList = InsertAddIns(retryList);
                  
                   // break if no add-in could be inserted.
                   if (newRetryList.Count == retryList.Count) {
                       break;
                   }
                  
                   retryList = newRetryList;
              }
             
              if (retryList.Count > 0) {
                   throw new ApplicationException("At least one AddIn uses an undefined codon or condition: " + retryList[0]);
              }
              //            tree.ShowCodonTree();
         }   
B.1.1.1=> 取得服务
public IService GetService(Type serviceType)
         {
              IService s = (IService)servicesHashtable[serviceType];
              if (s != null) {
                   return s;
              }
             
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值