Exemple #1
0
        //此处封装了关键的方法:Start,Stop,Continue,Pause
        internal void Start(List <MirrorBlockInfo> mirrorBlockInfos, int startedFileIndex = 0, long startedPos = 0)
        {
            if (mirrorBlockInfos.Count < 1)
            {
                _stateReporter.Report(CmdStrings.NoSelectedPartition);
                return;
            }

            _curState = null;
            //设置反馈,以及执行命令
            if (_mirrorBackgroundProcess != null)
            {
                _mirrorBackgroundProcess.CallBack -= OnCallBack;
                _mirrorBackgroundProcess.Close();
            }
            _mirrorBackgroundProcess           = new MirrorBackgroundProcess();
            _mirrorBackgroundProcess.CallBack += OnCallBack;

            bool isInitialized = _mirrorBackgroundProcess.Initialize();

            if (!isInitialized)
            {
                return;
            }

            for (int i = startedFileIndex; i < mirrorBlockInfos.Count; i++)
            {
                var item = mirrorBlockInfos[i];
                //以下是构建参数
                string    arg      = string.Format(@"{0}|{1}|{2}|{3}|{4}|{5}", CmdStrings.StartMirror, _deviceID, _isHtc, item.TargetMirrorFile, item.SourceBlockPath, startedPos);
                CmdString startCmd = new CmdString(arg);
                _mirrorBackgroundProcess.ExcuteCmd(startCmd);
                _pauseInfo.SetPauseFileInfo(i, mirrorBlockInfos);

                while (true)
                {
                    if (_curState != null)
                    {
                        if (_curState.Match(CmdStrings.FinishState))
                        {
                            break;
                        }
                        else if (_curState.Match(CmdStrings.StopMirror) ||
                                 _curState.Match(CmdStrings.Exception))
                        {
                            return;
                        }
                    }

                    Thread.Sleep(1000);
                }
            }

            _mirrorBackgroundProcess.CallBack -= OnCallBack;
            _mirrorBackgroundProcess.Close();
            _stateReporter.Report(CmdStrings.AllFinishState);
        }
Exemple #2
0
 /// <summary>
 /// 状态变化事件
 /// </summary>
 private void StateChanged(CmdString state)
 {
     if (state.IsType(CmdStrings.Progress))
     {
         CmdString progress    = state.GetChildCmd();
         long      finisedSize = 0;
         if (long.TryParse(progress.ToString(), out finisedSize))
         {
             ProgressChanged(finisedSize);
             _pauseInfo.SetPausePos(finisedSize);
         }
     }
     else if (state.Match(CmdStrings.StartMirror))
     {
         SourcePosition.IsMirroring = true;
     }
     else if (state.Match(CmdStrings.AllFinishState))
     {
         _msgBox.ShowDialogSuccessMsg("镜像完成");
         SourcePosition.IsMirroring    = false;
         ProgressPosition.FinishedSize = ProgressPosition.TotalSize;
         ProgressPosition.Stop();
     }
     else if (state.IsType(CmdStrings.Exception))
     {
         _msgBox.ShowErrorMsg("镜像失败" + state.GetChildCmd());
         SourcePosition.IsMirroring = false;
     }
     else if (state.Match(CmdStrings.StopMirror))
     {
         _msgBox.ShowDialogSuccessMsg("镜像停止");
         SourcePosition.IsMirroring = false;
     }
     else if (state.Match(CmdStrings.NoSelectedPartition))
     {
         _msgBox.ShowDialogSuccessMsg("请选择至少一个分区");
         SourcePosition.IsMirroring = false;
     }
     else if (state.Match(CmdStrings.PauseMirror) ||
              state.Match(CmdStrings.ContinueMirror))
     {
         _msgBox.ShowDialogSuccessMsg(state.ToString());
     }
 }