コード例 #1
0
 protected WorkbenchBase(PluginApplicationContext applicationContext)
 {
     this.ApplicationContext = applicationContext ?? throw new ArgumentNullException(nameof(applicationContext));
     _status      = WorkbenchStatus.None;
     _title       = applicationContext.Title;
     _startupPath = PluginPath.Combine(applicationContext.Options.GetWorkbenchMountion(), "Startup");
     _semaphore   = new AutoResetEvent(true);
 }
コード例 #2
0
        protected virtual void OnClosing(CancelEventArgs args)
        {
            _status = WorkbenchStatus.Closing;

            if (this.Closing != null)
            {
                this.Closing(this, args);
            }
        }
コード例 #3
0
        protected virtual void OnClosed(EventArgs args)
        {
            _status = WorkbenchStatus.None;

            if (this.Closed != null)
            {
                this.Closed(this, args);
            }
        }
コード例 #4
0
        public virtual void OnOpening(EventArgs args)
        {
            _status = WorkbenchStatus.Opening;

            if (this.Opening != null)
            {
                this.Opening(this, args);
            }
        }
コード例 #5
0
        protected virtual void OnOpened(EventArgs args)
        {
            _status = WorkbenchStatus.Running;

            if (this.Opened != null)
            {
                this.Opened(this, args);
            }
        }
コード例 #6
0
        protected WorkbenchBase(PluginApplicationContext applicationContext)
        {
            if (applicationContext == null)
            {
                throw new ArgumentNullException("applicationContext");
            }

            _applicationContext = applicationContext;
            _title       = applicationContext.Title;
            _status      = WorkbenchStatus.None;
            _startupPath = applicationContext.PluginContext.Settings.WorkbenchPath + "/Startup";
        }
コード例 #7
0
        public void Open(string[] args)
        {
            if (_status == WorkbenchStatus.Running || _status == WorkbenchStatus.Opening)
            {
                return;
            }

            if (_status == WorkbenchStatus.Closing)
            {
                throw new InvalidOperationException();
            }

            //设置工作台状态为“Opening”
            _status = WorkbenchStatus.Opening;

            try
            {
                //激发“Opening”事件
                this.OnOpening(EventArgs.Empty);
            }
            catch
            {
                //注意:可能因为预打开事件处理程序或工作台构建过程出错,都必须重置工作台状态为“None”
                _status = WorkbenchStatus.None;

                //重抛异常,导致后续的关闭代码不能继续,故而上面代码重置了工作台状态
                throw;
            }

            try
            {
                //调用虚拟方法以执行实际启动的操作
                this.OnStart(args);

                //查找当前工作台的插件节点
                var node = _applicationContext.PluginContext.PluginTree.Find(_applicationContext.PluginContext.Settings.WorkbenchPath);

                //如果工作台对象未挂载或不是通过插件文件挂载的话,则将当前工作台对象挂载到指定的插件路径中
                if (node == null || node.NodeType != PluginTreeNodeType.Builtin)
                {
                    _applicationContext.PluginContext.PluginTree.Mount(_applicationContext.PluginContext.Settings.WorkbenchPath, this);
                }
            }
            catch
            {
                //注意:如果在实际启动操作中,子类已经通过OnOpened方法设置了工作台状态为运行,则无需再重置工作台状态;否则必须重置工作台状态为“None”
                if (_status == WorkbenchStatus.Opening)
                {
                    _status = WorkbenchStatus.None;
                }

                //重抛异常,导致后续的关闭代码不能继续,故而上面代码重置了工作台状态
                throw;
            }

            //如果没有激发过“Opened”事件则激发该事件
            if (_status == WorkbenchStatus.Opening)
            {
                this.OnOpened(EventArgs.Empty);
            }
        }
コード例 #8
0
        /// <summary>
        /// 关闭工作台。
        /// </summary>
        /// <returns>如果关闭成功返回真(true),否则返回假(false)。如果取消关闭操作,亦返回假(false)。</returns>
        public bool Close()
        {
            if (_status == WorkbenchStatus.None || _status == WorkbenchStatus.Closing)
            {
                return(false);
            }

            if (_status == WorkbenchStatus.Opening)
            {
                throw new InvalidOperationException();
            }

            //设置工作台状态为“Closing”
            _status = WorkbenchStatus.Closing;

            //创建“Closing”事件的参数对象
            CancelEventArgs args = new CancelEventArgs();

            try
            {
                //激发“Closing”事件
                this.OnClosing(args);
            }
            catch
            {
                //注意:由于事件处理程序出错,必须重置工作台状态为“Running”
                _status = WorkbenchStatus.Running;

                //重抛异常,导致后续的关闭代码不能继续,故而上面代码重置了工作台状态
                throw;
            }

            //如果事件处理程序要取消后续的关闭操作,则重置工作台状态
            if (args.Cancel)
            {
                //重置工作台状态为“Running”
                _status = WorkbenchStatus.Running;

                //因为取消关闭,所以退出后续关闭操作
                return(false);
            }

            try
            {
                //调用虚拟方法以进行实际的关闭操作
                this.OnStop();
            }
            catch
            {
                //注意:如果在实际关闭操作中,子类已经通过OnClosed方法设置了工作台状态为关闭,则无需再重置工作台状态;否则必须重置工作台状态为“Running”
                if (_status == WorkbenchStatus.Closing)
                {
                    _status = WorkbenchStatus.Running;
                }

                //重抛异常,导致后续的关闭代码不能继续,故而上面代码重置了工作台状态
                throw;
            }

            //设置工作台状态为“None”
            _status = WorkbenchStatus.None;

            //如果没有激发过“Closed”事件则激发该事件
            if (_status != WorkbenchStatus.None)
            {
                this.OnClosed(EventArgs.Empty);
            }

            //返回成功
            return(true);
        }
コード例 #9
0
 protected override void setup()
 {
     status_ = new WorkbenchStatus();
 }