コード例 #1
0
ファイル: Addin.cs プロジェクト: jingyiliu/JointCode.AddIns
        bool StartThisAddin()
        {
            if (_started)
            {
                return(true);
            }

            // after all referenced addins started, change the status of this addin, activate it, and load extensions for loaded extension points (if there is any).
            _started = true; // 必须在 ActivateThisAddin 方法之前设置此值,否则加载插件程序集时会再调用此方法,造成死循环。
            // register all assemblies of this addin to the assembly resolver, for getting them ready to be loaded into runtime, but not load them yet.
            _addinRuntime.RegisterAssemblies();

            try
            {
                OnAddinStatusChanged(AddinStatus.Starting);
                // activate the addin. this method might load needed assemblies.
                ActivateThisAddin();
                // if there is any loaded extension points for which this addin extends, loads the extension builders and extensions of this addin [addinRecord]
                // that extending the extension point.
                _addinEngine.LoadIntoLoadedExtensionPoints(_addinContext, _addinRecord);
                OnAddinStatusChanged(AddinStatus.Started);
                return(true);
            }
            catch (Exception e)
            {
                _started = false;
                _addinRuntime.UnregisterAssemblies();

                // log, show message, ...
                return(false);
            }
        }