Ejemplo n.º 1
0
        /// <summary>
        /// 开始升级
        /// </summary>
        /// <param name="updateVersion"></param>  
        private void StartUpdate(UpdateVersion updateVersion)
        {
            this._currentVersion = updateVersion;

            // 重新绑定升级时升级状态的变化事件
            foreach (UCUpdateState ucUpdateState in _ucUpdateStates)
            {
                IUpdateService updateServiceService = ((List<IUpdateService>)updateVersion.CurrentService).Find(delegate(IUpdateService update)
                    { return update.Title == ucUpdateState.Title; });
                if (updateServiceService.State != UpdateState.Success && updateServiceService.State != UpdateState.AfterUpdate)
                {
                    ucUpdateState.ResetPanelColor(); // 重置Panel 的色彩
                }
                // 注册升级状态发生变化事件 控件颜色变化
                updateServiceService.StateChange -= ucUpdateState.UpdateState;
                updateServiceService.StateChange += ucUpdateState.UpdateState;

                // 进度条信息变化
                updateServiceService.StateChange -= UpdateServiceServiceStateChange;
                updateServiceService.StateChange += UpdateServiceServiceStateChange;
            }
            updateVersion.RegisterMessage(ShowMessage);  // 注册消息事件
            this.ShowMessage(string.Format("本次升级版本为:{0}", updateVersion.Version));
            // 异步升级开始
            new MethodInvoker(delegate() { updateVersion.BeginUpdate(); }).BeginInvoke(UpdateCallBack, updateVersion);
        }