private void AddExperimentResultAndFinishItIfNeeded(LeftoverChunks[] chunks)
        {
            _log.Info("adding experiment result");
            _dal.AddExperimentResult(_conf.DetailsOfAttack.MissionId, chunks);

            if (chunks.All(x => x.PercentageCompleted < 1.0)) // No More than 40 bytes...
            {
                _dal.SetMissionAsFinished(_conf.DetailsOfAttack.MissionId);

                _locator = null;

                _conf.DetailsOfAttack      = new AttackDetails();
                _conf.InTheMiddleOfMission = false;
                Configuration.Serialize(_conf, AppDomain.CurrentDomain.BaseDirectory);
                _dal.SetAgentStatus(AgentStatus.Idle);

                _updateTimer.Change(Timeout.Infinite, Timeout.Infinite);
                _mainTimer.Change(TIME_FOR_CHECKING_DB_AGAIN, TIME_FOR_CHECKING_DB_AGAIN);
                _log.Info("Experiment finished");
                foreach (var chunk in chunks)
                {
                    _log.Debug(string.Format("LCN: {0}, Percent: {1}, IsAllocated:{2}", chunk.Lcn, chunk.PercentageCompleted, chunk.IsAllocated));
                }
            }
            else
            {
                _filesLocatorTimer.Change(_conf.DetailsOfAttack.TimeGap, _conf.DetailsOfAttack.TimeGap);

                _dal.SetAgentStatus(AgentStatus.IdleInTheMiddleOfExperiment);
            }
        }
        public void Run()
        {
            _log.Info("Running Mission Manager");
            // If no mission is in progress.
            if (!_conf.InTheMiddleOfMission || _conf.DetailsOfAttack == null)
            {
                _log.Info("No recent missions found.");
                _mainTimer.Change(0, TIME_FOR_CHECKING_DB_AGAIN);
            }
            else
            {
                _updateTimer.Change(TIME_FOR_CHECKING_DB_AGAIN_FOR_UPDATE_ONLY, TIME_FOR_CHECKING_DB_AGAIN_FOR_UPDATE_ONLY);

                _log.Info("Mission already in progress.");
                if (_conf.DetailsOfAttack.InTheMiddleOfScan)
                {
                    _log.Info("Checking if files still exist.");
                    _locator = new FilesLocatorNG(_conf.DetailsOfAttack.FileLocationData, _conf.DetailsOfAttack.DataToSearchFor, _log);
                    CheckHd(null);
                }
                else
                {
                    if (_conf.DetailsOfAttack.WhenToStart < DateTime.Now)
                    {
                        _deleteFileAndStartExperimentTimer.Change(0, Timeout.Infinite);
                    }
                    else
                    {
                        _deleteFileAndStartExperimentTimer.Change((long)(_conf.DetailsOfAttack.WhenToStart - DateTime.Now).TotalMilliseconds, Timeout.Infinite);
                        _dal.SetAgentStatus(AgentStatus.ExperimentCreatedAndWaitingToStart);
                    }
                }
            }
        }
        private void StartExperiment(object state)
        {
            _dal.SetAgentStatus(AgentStatus.CreatingExperiment);
            _conf.DetailsOfAttack.FileLocationData = NtfsHelper.GetFileMap(_conf.DetailsOfAttack.FilePath);
            _locator = new FilesLocatorNG(_conf.DetailsOfAttack.FileLocationData, _conf.DetailsOfAttack.DataToSearchFor, _log);

            try
            {
                File.Delete(_conf.DetailsOfAttack.FilePath);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                _dal.WriteError("Error while deleting incriminating file! " + ex.ToString());
                throw;
            }

            _conf.DetailsOfAttack.InTheMiddleOfScan = true;
            Configuration.Serialize(_conf, AppDomain.CurrentDomain.BaseDirectory);

            CheckHd(null);
        }