private void StartCollect(IDocumentSession session, CollectRequest collectRequest, CollectExecution collectExecution, FamilyEnumeration plataform, ExecutionLogBuilder executionLog) { int attemptsOfEvaluateVariables = 1; bool anErrorOccured = false; bool allObjectWasCollect = false; IEnumerable <ObjectType> objectTypes = collectRequest.GetObjectTypesWasNotCollected(session); session.SaveChanges(); while (!collectTimeOut.IsExceededTheMaxAttemptsOfEvaluateVariables(attemptsOfEvaluateVariables) && !allObjectWasCollect && !anErrorOccured && !Interrupted) { IEnumerable <StateType> states = collectRequest.GetStates(session); IEnumerable <SelectedProbe> selectedProbes = ProbeManager.GetProbesFor(objectTypes, plataform); VariablesEvaluated variables = variableEvaluatorService.Evaluate(collectRequest, session); session.SaveChanges(); try { this.UpdateSystemInformationOfTarget(session, collectRequest, plataform, executionLog); this.ExecuteCollectWithProbes(session, selectedProbes, collectRequest, variables, states, collectExecution, executionLog); session.SaveChanges(); } catch (SystemInformationException ex) { string logMessage; if (ex.InnerException == null) { logMessage = String.Format(EXECUTION_ERROR_MESSAGE, ex.Message, ex.StackTrace); } else { logMessage = String.Format(EXECUTION_ERROR_MESSAGE_WITH_INNER_EXCEPTION, ex.Message, ex.InnerException.StackTrace, ex.StackTrace); } Logger.Error(logMessage); collectRequest.SetResultError(); collectRequest.Close(); anErrorOccured = true; session.SaveChanges(); break; } catch { // only ends the loop. The error already was treated anErrorOccured = true; } objectTypes = collectRequest.GetObjectTypesWasNotCollected(session); allObjectWasCollect = objectTypes.Count() == 0; attemptsOfEvaluateVariables++; } if (Interrupted) { collectRequest.Status = CollectRequestStatus.Canceled; } else { if ((!allObjectWasCollect) && (!anErrorOccured)) { CloseExecutionIfIncomplete(session, collectRequest, collectExecution, plataform, objectTypes); } } session.SaveChanges(); }