zoukankan      html  css  js  c++  java
  • 从分析Main函数开始

    最BT的就是这里了,连个Application.Run()都没有——而全都是从AddIns读取。

     1        [STAThread()]
     2        public static void Main(string[] args)
     3        {
     4            commandLineArgs = args;
     5            bool noLogo = false;
     6            
     7            foreach (string arg in args) {
     8                if (arg.ToUpper().EndsWith("NOLOGO")) {
     9                    noLogo = true;
    10                }

    11            }

    12            
    13            if (!noLogo) {
    14                splashScreen = new SplashScreenForm();
    15                splashScreen.Show();
    16            }

    17            
    18            ArrayList commands = null;
    19            try {
    20                ServiceManager.Services.InitializeServicesSubsystem("/Workspace/Services");
    21            
    22                commands = AddInTreeSingleton.AddInTree.GetTreeNode("/Workspace/Autostart").BuildChildItems(null);
    23                
    24                for (int i = 0; i < commands.Count - 1++i) {
    25                    ((ICommand)commands[i]).Run();
    26                }

    27            }
     catch (XmlException e) {
    28                MessageBox.Show("Could not load XML :\n" + e.Message);
    29                return;
    30            }
     catch (Exception e) {
    31                MessageBox.Show("Loading error, please reinstall :\n" + e.ToString());
    32                return;
    33            }
     finally {
    34                if (splashScreen != null{
    35                    splashScreen.Close();
    36                    splashScreen.Dispose();
    37                }

    38            }

    39            
    40            // run the last autostart command, this must be the workbench starting command
    41            if (commands.Count > 0{
    42                ((ICommand)commands[commands.Count - 1]).Run();
    43            }

    44            
    45            // unloading services
    46            ServiceManager.Services.UnloadAllServices();            
    47        }

    逐行分析如下:
    18行之前是“每日提示”——splashScreen的现实与否,33行在最后一个命令(激活IDE主窗口)启动前关闭这个Form。
    18行以后是关键:
    ServiceManager这个单件,先初始化所有服务(包括Core中的4个核心服务,Base中的11个服务,其中Core中的服务调用是写死的,Base中调用的服务是动态加载SharpDevelop.Addin的节点"/Workspace/Services。

    接着获取AddIn树结点"Workspace/Autostart"上所有Codons——BuildChildItems()方法,因为每个Codons都是一个命令,所以都有Run()方法作各自的事情。通过for循环依次执行这些命令。
    其中,最后一个命令是"激活IDE主窗口",在确保所有Codons都正常运行时,才执行这个命令。在这个命令中,才可以看到Application.Run()这样的语句。

    最后,ServiceManager这个单件卸载所有服务。


    补注:另一个BT的地方是SharpDevelop中没有把编译dll目录放在各自工程的bin下,而是所有的project共享外部的同一个bin目录,于是每个需要反射dll的类中都写死了一个静态只读常量,记录这个相对路径——这套做法完全有别于VS2003,所以在把cmbx转为proj工程时,会发生dll引用丢失的问题。配置文件也是这个问题。


  • 相关阅读:
    0929作业
    0909上机作业
    熟悉的LINUX操作
    博客搭建成功啦!
    感谢管理员,通过了我的博客邀请。哈哈
    Asp.net常用的51个代码(非常实用)
    CSS命名规范:
    常用的JavaScript验证正则表达式
    Linq to sql 查询句法
    Web.config配置文件详解
  • 原文地址:https://www.cnblogs.com/Jax/p/829204.html
Copyright © 2011-2022 走看看