コード例 #1
0
ファイル: ProtocolRunner.cs プロジェクト: rombolshak/Requc
        private void OnStepFinished(IProtocolStep step)
        {
            _logger.Write("OnStepFinished " + step);
            var handler = StepFinished;
            if (handler == null) return;

            _logger.Write("Raising event, handler not null");
            var stepFinishedEventArgs = new ProtocolStepFinishedEventArgs(step);
            _logger.Write("args prepared");
            try
            {
                handler(this, stepFinishedEventArgs);
                _logger.Write("handler was called, waiting for animations");
            }
            catch (Exception exception)
            {
                _logger.Write(string.Format("Something went wrong: {0}", exception.Message));
            }
            finally
            {
                stepFinishedEventArgs.Handle.WaitOne(2000);
            }

            _logger.Write("finish processing of OnStepFinished");
        }
コード例 #2
0
ファイル: ProtocolViewModel.cs プロジェクト: rombolshak/Requc
        private void RunnerOnStepFinished(object sender, ProtocolStepFinishedEventArgs protocolStepFinishedEventArgs)
        {
            // OnStepFinished(protocolStepFinishedEventArgs);
            CurrentStepDescription = protocolStepFinishedEventArgs.Step.Description;
            CurrentStepDescriptionVisualState = "Visible";
            TypeSwitch.Do(protocolStepFinishedEventArgs.Step,
                          TypeSwitch.Case<ShowInitialErrorsStep>(() =>
                              {
                                  foreach (var viewModel in BobKey.Where(model => model.ErrorHere))
                                  {
                                      viewModel.State = KeyItemViewModel.VisualStateE.Error;
                                  }

                                  foreach (var viewModel in ErrorItems)
                                  {
                                      viewModel.State = KeyItemViewModel.VisualStateE.Normal;
                                  }
                              }),
                          TypeSwitch.Case<HideInitialErrorsStep>(() =>
                              {
                                  foreach (var viewModel in BobKey)
                                  {
                                      viewModel.State = KeyItemViewModel.VisualStateE.Normal;
                                  }
                              }),
                          TypeSwitch.Case<FillBlocksWithRandomPermutationStep>(step =>
                              {
                                  AliceBlocks[_environment.Pass].State = BlockSetViewModel.VisualStateE.Visible;
                                  BobBlocks[_environment.Pass].State = BlockSetViewModel.VisualStateE.Visible;
                              }),
                          TypeSwitch.Case<CalculateParitiesStep>(step =>
                              {
                                  foreach (
                                      var blockViewModel in
                                          AliceBlocks[_environment.Pass].Blocks.Concat(BobBlocks[_environment.Pass].Blocks))
                                  {
                                      blockViewModel.State = BlockViewModel.VisualStateE.ParityVisible;
                                  }
                              }),
                          TypeSwitch.Case<CheckParitiesStep>(step =>
                              {
                                  for (var i = 0; i < _environment.BlocksCount[_environment.Pass]; ++i)
                                  {
                                      if (AliceBlocks[_environment.Pass].Blocks[i].Parity ==
                                          BobBlocks[_environment.Pass].Blocks[i].Parity)
                                      {
                                          AliceBlocks[_environment.Pass].Blocks[i].State =
                                              BobBlocks[_environment.Pass].Blocks[i].State =
                                              BlockViewModel.VisualStateE.ParityMatched;
                                      }
                                      else
                                      {
                                          AliceBlocks[_environment.Pass].Blocks[i].State =
                                              BobBlocks[_environment.Pass].Blocks[i].State =
                                              BlockViewModel.VisualStateE.ParityNotMatched;
                                      }
                                  }
                              }),
                          TypeSwitch.Case<SetOddErrorsBlocksStep>(step =>
                              {
                                  UpdateOddErrorsBlocks();

                                  foreach (var block in GetAllBlocks(AliceBlocks))
                                  {
                                      block.State = BlockViewModel.VisualStateE.Normal;
                                  }
                              }),
                          TypeSwitch.Case<FindSmallestOddErrorBlockStep>(step =>
                              {
                                  var workingBlock = GetWorkingBlock();
                                  workingBlock.State = BlockViewModel.VisualStateE.OddErrorSelected;
                              }),
                          TypeSwitch.Case<InitializeBinaryCorrectionStep>(step =>
                              {
                                  foreach (var item in GetWorkingBlock().Items)
                                  {
                                      item.State = KeyItemViewModel.VisualStateE.Error;
                                  }

                                  foreach (var item in GetSampleBlock().Items)
                                  {
                                      item.State = KeyItemViewModel.VisualStateE.Corrected;
                                  }
                              }),
                          TypeSwitch.Case<LookAtFirstHalfOfWorkingPositionsStep>(() =>
                              {
                                  ChangeVisualStateInBinaryProtocol(GetWorkingBlock());
                                  ChangeVisualStateInBinaryProtocol(GetSampleBlock());
                              }),
                          TypeSwitch.Case<CalculateWorkingPositionsParityStep>(() =>
                              {
                                  var workingBlock = GetWorkingBlock();
                                  var sampleBlock = GetSampleBlock();

                                  workingBlock.WorkingParity = _environment.BinaryEnvironment.WorkingParity;
                                  workingBlock.ShowWorkingParity = true;

                                  sampleBlock.WorkingParity = _environment.BinaryEnvironment.SampleParity;
                                  sampleBlock.ShowWorkingParity = true;

                                  workingBlock.State = BlockViewModel.VisualStateE.ParityTextVisible;
                                  sampleBlock.State = BlockViewModel.VisualStateE.ParityTextVisible;
                              }),
                          TypeSwitch.Case<CompareWorkingPositionsParityStep>(() =>
                              {
                                  var workingBlock = GetWorkingBlock();
                                  var sampleBlock = GetSampleBlock();
                                  if (_environment.BinaryEnvironment.SampleParity ==
                                      _environment.BinaryEnvironment.WorkingParity)
                                  {
                                      workingBlock.State =
                                          sampleBlock.State = BlockViewModel.VisualStateE.ParityMatched;
                                  }
                                  else
                                  {
                                      workingBlock.State =
                                          sampleBlock.State = BlockViewModel.VisualStateE.ParityNotMatched;
                                  }
                              }),
                              TypeSwitch.Case<UpdateWorkingPositionsStep>(() =>
                                  {
                                      var workingBlock = GetWorkingBlock();
                                      var sampleBlock = GetSampleBlock();
                                      foreach (
                                          var item in
                                              workingBlock.Items.Except(
                                                  workingBlock.Items.Skip(_environment.BinaryEnvironment.StartPosition)
                                                              .Take(_environment.BinaryEnvironment.PositionsCount))
                                                          .Concat(
                                                              sampleBlock.Items.Except(
                                                                  sampleBlock.Items.Skip(_environment.BinaryEnvironment.StartPosition)
                                                                             .Take(_environment.BinaryEnvironment.PositionsCount))))
                                      {
                                          item.State = KeyItemViewModel.VisualStateE.Normal;
                                      }

                                      GetWorkingBlock().State = BlockViewModel.VisualStateE.Normal;
                                      GetSampleBlock().State = BlockViewModel.VisualStateE.Normal;
                                  }),
                                  TypeSwitch.Case<CorrectErrorInFoundPositionStep>(() =>
                                      {
                                          var workingBlock = GetWorkingBlock();
                                          var sampleBlock = GetSampleBlock();

                                          var correctedPosition = _environment.BinaryEnvironment.StartPosition;
                                          workingBlock.Items[correctedPosition].Value =
                                              sampleBlock.Items[correctedPosition].Value;
                                          workingBlock.Items[correctedPosition].State =
                                              KeyItemViewModel.VisualStateE.Corrected;
                                          sampleBlock.Items[correctedPosition].State = KeyItemViewModel.VisualStateE.Normal;
                                          ErrorItems.Single(model => model.Position == workingBlock.Items[correctedPosition].Position).State =
                                              KeyItemViewModel.VisualStateE.Corrected;

                                          _environment.BinaryEnvironment.StartPosition = 0;
                                          _environment.BinaryEnvironment.PositionsCount = workingBlock.Size * 2;
                                          ChangeVisualStateInBinaryProtocol(workingBlock);
                                          ChangeVisualStateInBinaryProtocol(sampleBlock);

                                          workingBlock.ShowWorkingParity = false;
                                          sampleBlock.ShowWorkingParity = false;

                                          workingBlock.State = BlockViewModel.VisualStateE.ParityVisible;
                                          sampleBlock.State = BlockViewModel.VisualStateE.ParityVisible;
                                      }),
                                      TypeSwitch.Case<BackTrackCorrectedErrorStep>(UpdateOddErrorsBlocks),
                                      TypeSwitch.Case<OnePassStep>(() =>
                                          {
                                              foreach (var block in BobKey.Where(item => item.State == KeyItemViewModel.VisualStateE.Corrected))
                                              {
                                                  block.State = KeyItemViewModel.VisualStateE.Normal;
                                              }
                                          }),
                                      TypeSwitch.Case<WholeProtocolStep>(() =>
                                          {
                                              foreach (var blockSet in AliceBlocks.Concat(BobBlocks))
                                              {
                                                  blockSet.State = BlockSetViewModel.VisualStateE.Collapsed;
                                              }
                                          }));

            StateManager.WaitAnimations();
            protocolStepFinishedEventArgs.Handle.Set();

            _screenCapture.CaptureWindowToFile(
                Process.GetCurrentProcess().MainWindowHandle,
                DateTime.Now.ToString("hhmmss_") + protocolStepFinishedEventArgs.Step + "_finished.png", ImageFormat.Png);
            _runner.NextStep();
        }