private oval_results TryToGetOvalResultsDocumentFromCollectedAnalysis(CollectRequest collectRequest, string definitionsText, Result collectResult)
        {
            IEnumerable<string> errors;
            var scMS = new MemoryStream(Encoding.UTF8.GetBytes(collectResult.SystemCharacteristics));
            var collectedSC = oval_system_characteristics.GetOvalSystemCharacteristicsFromStream(scMS, out errors);

            var docMS = new MemoryStream(Encoding.UTF8.GetBytes(definitionsText));
            var definitions = oval_definitions.GetOvalDefinitionsFromStream(docMS, out errors);
            if (definitions == null || (definitions != null && definitions.definitions == null))
            {
                return null;
            }
            
            oval_variables externalVariables;
            if (collectRequest.ExternalVariables != null)
            {
                externalVariables = oval_variables.GetOvalVariablesFromText(collectRequest.ExternalVariables, out errors);
            }
            else
            {
                externalVariables = null;
            }

            return oval_results.CreateFromDocuments(definitions, collectedSC, externalVariables);
        }
Esempio n. 2
0
        public CollectRequest CreateCollectRequestFromDTO(Request collectRequestDTO, string definitionId)
        {
            var collectRequest = new CollectRequest();
            targetAssembler.AddTargetInCollectRequest(collectRequestDTO, collectRequest);
            collectRequest.OvalDefinitionsId = definitionId;
            collectRequest.ExternalVariables = collectRequestDTO.ExternalVariables;

            return collectRequest;
        }
Esempio n. 3
0
        public void AddTargetInCollectRequest(Request collectRequestDTO, CollectRequest collectRequest)
        {
            Target target = new Target();
            target.Address = collectRequestDTO.Address;
            collectRequest.Target = target;

            this.AddCredentialToTarget(collectRequestDTO, target);
            this.AddTargetParametersInCollectRequest(collectRequestDTO, target);
        }
Esempio n. 4
0
 public Result CreateDTOFromCollectResult(IDocumentSession session, CollectRequest collectRequest)
 {
     var collectResultDTO = new Result();
     collectResultDTO.Date = collectRequest.Result.Date;
     collectResultDTO.SystemCharacteristics = collectRequest.Result.SystemCharacteristics;
     collectResultDTO.Status = collectRequest.Result.Status;
     collectResultDTO.ExecutionLogs = this.GetExecutionErrorLogs(session, collectRequest).ToArray();
     return collectResultDTO;
 }
Esempio n. 5
0
        public CollectExecution CreateCollectExecution(IDocumentSession session, CollectRequest collectRequest)
        {
            CollectExecution collect = new CollectExecution();
            collect.RequestId = collectRequest.Oid;

            session.Store(collect);
            session.SaveChanges();

            return collect;
        }
Esempio n. 6
0
        public CollectInfo CreateCollectInfoFromCollectRequest(CollectRequest collectRequest)
        {
            CollectInfo collectInfoDTO = new CollectInfo();
            collectInfoDTO.Address = collectRequest.Target.Address;
            collectInfoDTO.ReceivedOn = collectRequest.ReceivedOn;
            collectInfoDTO.CollectRequestId = collectRequest.Oid.ToString();
            collectInfoDTO.ClientId = collectRequest.ClientId;
            collectInfoDTO.Status = collectRequest.Status;

            return collectInfoDTO;
        }
Esempio n. 7
0
        public CollectExecution CreateCollectExecution(IDocumentSession session, CollectRequest collectRequest)
        {
            CollectExecution collect = new CollectExecution();

            collect.RequestId = collectRequest.Oid;

            session.Store(collect);
            session.SaveChanges();

            return(collect);
        }
        public oval_results GetDocument(CollectRequest collectRequest, string definitions, Result collectResult)
        {
            if ((collectRequest != null) && (collectRequest.HasResult()))
            {
                var ovalResults = TryToGetOvalResultsDocumentFromCollectedAnalysis(collectRequest, definitions, collectResult);
                if (ovalResults != null)
                {
                    ovalResults.Analyze();
                    return ovalResults;
                }
            }

            return null;
        }
Esempio n. 9
0
        private IEnumerable<VariableValue> GetVariableValuesFrom(CollectRequest collectRequest, IDocumentSession session)
        {
            List<VariableValue> variableValues = new List<VariableValue>();
            VariableType[] variables = collectRequest.GetOvalVariables(session).ToArray();
            VariableEvaluator variableEvaluator = new VariableEvaluator(variables, collectRequest.GetSystemCharacteristics(session), collectRequest.GetExternalVariables());
            foreach (VariableType variable in collectRequest.GetOvalVariables(session))
            {
                IEnumerable<string> valuesOfVariable = variableEvaluator.EvaluateVariable(variable.id);
                IEnumerable<ObjectType> objectsByVariable = collectRequest.GetObjectTypesByVariableId(session, variable.id);
                variableValues.AddRange(this.CreateVariableValuesFrom(objectsByVariable, variable.id, valuesOfVariable));

                IEnumerable<StateType> statesByVariable = collectRequest.GetStateTypeByVariableId(session, variable.id);
                variableValues.AddRange(this.CreateVariableValuesFrom(statesByVariable, variable.id, valuesOfVariable));
            }
            return variableValues;
        }
Esempio n. 10
0
        /// <summary>
        /// This method is responsible to start of collect process.        
        /// </summary>
        /// <param name="objectTypes">The object types.</param>
        public void ExecuteCollect(IDocumentSession session, CollectRequest collectRequest, FamilyEnumeration plataform)
        {
            ExecutionLogBuilder executionLog = new ExecutionLogBuilder();

            this.SetStatusToExecuting(collectRequest);

            CollectExecution collectExecution = this.CreateCollectExecution(session, collectRequest);
            try
            {
                collectExecution.SetDateStartCollect();
                this.StartCollect(session, collectRequest, collectExecution, plataform, executionLog);
                this.EndCollect(session, collectRequest, collectExecution);
            }
            catch (Exception ex)
            {
                var logMessage = String.Format(EXECUTION_ERROR_MESSAGE, ex.Message, ex.StackTrace);
                Logger.Error(logMessage);
                this.EndsACollectRequestBecauseThisErrorIsUnrecoverable(collectRequest, "Collect Manager", collectExecution, ex, executionLog);
            }

            session.SaveChanges();
        }
 private void EndCollect(IDocumentSession session, CollectRequest collectRequest, CollectExecution collectExecution)
 {
     if (collectTimeOut.IsExceededTheMaxOfExecutionsDefined(collectRequest.GetNumberOfExecutions(session)))
     {
         collectRequest.Close();
     }
     else
     {
         if (!collectRequest.isClosed())
         {
             if (!collectExecution.ExistsExecutionsWithError())
             {
                 collectRequest.TryClose(session);
             }
             else
             {
                 collectRequest.Reopen();
             }
         }
     }
     collectExecution.SetDateEndCollect();
     session.SaveChanges();
 }
 /// <summary>
 /// Ends the request collect because this error is unrecoverable.
 /// This request was not execute because exists some error that is not possible perform the collect.
 /// Ex.: Invalid credentials, bad format of oval xmls, etc.
 /// </summary>
 /// <param name="collectRequest">The request collect.</param>
 /// <param name="probe">The probe.</param>
 /// <param name="collectExecution">the Collect execution object.</param>
 /// <param name="error">the exception that represents an error.</param>
 private void EndsACollectRequestBecauseThisErrorIsUnrecoverable(CollectRequest collectRequest, string probeCapability, CollectExecution collectExecution, Exception error, ExecutionLogBuilder executionLog)
 {
     ConfigureTheCollectRequestWithAnErrorProbeExecute(collectRequest, probeCapability, collectExecution, error, executionLog);
     collectRequest.Close();
 }
 private CollectExecution CreateCollectExecution(IDocumentSession session, CollectRequest collectRequest)
 {
     collectFactory = new CollectFactory();
     CollectExecution collectExecution = collectFactory.CreateCollectExecution(session, collectRequest);
     return collectExecution;
 }
 private void CreateCollectionExcutionWithError(IDocumentSession session, CollectRequest collectRequest, string capability, Exception ex, ExecutionLogBuilder executionLog)
 {
     CollectExecution collectExecution = this.CreateCollectExecution(session, collectRequest);
     collectExecution.SetDateStartCollect();
     EndsACollectRequestBecauseThisErrorIsUnrecoverable(collectRequest, capability, collectExecution, ex, executionLog);
 }
 /// <summary>
 /// Configures the request collect with one probeExecute with the error status.
 /// </summary>
 /// <param name="collectRequest">The request collect.</param>
 /// <param name="probe">The probe.</param>
 /// <param name="collectExecution">The collect execution.</param>
 /// <param name="error">The error.</param>
 private void ConfigureTheCollectRequestWithAnErrorProbeExecute(CollectRequest collectRequest, string probeCapability, CollectExecution collectExecution, Exception error, ExecutionLogBuilder executionLog)
 {
     executionLog.AnErrorOccurred(error.Message);
     executionLog.EndCollect();
     ProbeExecution executionWithError = collectFactory.CreateAProbeExecutionWithError(probeCapability, executionLog.BuildExecutionLogs());
     collectExecution.ProbeExecutions.Add(executionWithError);
 }
        private void CreateCollectedObjectsForNotSupportedObjects(IDocumentSession session, IEnumerable<SelectedProbe> objectsNotSupported, CollectRequest collectRequest, CollectExecution collectExecution)
        {
            foreach (var probe in objectsNotSupported)
            {
                ProbeResult probeResult = probe.CreateCollectedObjectForNotSupportedObjects(probe.ObjectTypes);
                ProbeExecution probeExecution = this.CreateTheProbeExecution(probeResult, probe);
                collectRequest.UpdateSystemCharacteristics(session);
                collectExecution.ProbeExecutions.Add(probeExecution);

                session.SaveChanges();
            }
        }
        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();
        }
Esempio n. 18
0
 private IEnumerable<ExecutionLog> GetExecutionErrorLogs(IDocumentSession session, CollectRequest collectRequest)
 {
     var logs = collectRequest.GetExecutionLog(session).Where(x=>x.Type == LogType.Error);
     return this.executionLogAssembler.CreateDTOsFromCollectionOfExecutionLogs(logs);
 }
Esempio n. 19
0
 public string CreateCompressedSerializedExecutionLog(IDocumentSession session, CollectRequest collectRequest)
 {
     return CreateSerializedExecutionLog(session, collectRequest).ToCompressedBase64String();
 }
 private void GetSystemInformationFromTarget(CollectRequest collectRequest, ISystemInformationService systemInformationService)
 {
     SystemInformation systemInformation = systemInformationService.GetSystemInformationFrom(Target);
     SystemInfo systemInfo = new SystemInfoFactory().CreateSystemInfo(systemInformation);
     collectRequest.Target.SystemInformation = systemInfo;
 }
Esempio n. 21
0
 private string SaveCollectRequest(CollectRequest collectRequest, IDocumentSession session)
 {
     // using (UnitOfWork uow = new UnitOfWork())
     //{
         //try
         //{
        //     collectRequest.Save();
          //   uow.CommitChanges();
             session.SaveChanges();
             return collectRequest.Oid;
         //}
         //catch (Exception ex)
         //{
         //   // uow.ReloadChangedObjects();
         //    throw new Exception(ex.Message, ex);
         //}
     //}
 }
 public ProbeResult GetResultForFamily(CollectRequest collectRequest, List<string> resultsForObjects)
 {
     ProbeResultFactory factory = new ProbeResultFactory();
     IEnumerable<ObjectType> familyObjects = collectRequest.GetObjectTypes(session).OfType<family_object>();
     return factory.CreateProbeResultForFamilyWithSpecificObjectTypes(familyObjects, resultsForObjects);
 }
Esempio n. 23
0
 private DateTime GetCollectionStartDate(IDocumentSession session, CollectRequest collectRequest)
 {
     var firstExecution = collectRequest.GetCollectExecutions(session).FirstOrDefault();
     if (firstExecution != null)
         return firstExecution.StartDate.ToUniversalTime();
     
     var collectPackage = Repository.GetCollectPackages(session, new[] { collectRequest.CollectPackageId }).First();
     return collectPackage.ScheduleInformation.ExecutionDate;
 }
        /// <summary>
        /// Executes the collect for the one probe.
        /// </summary>
        /// <param name="collectRequest">The request collect.</param>
        /// <param name="probe">The probe.</param>
        /// <param name="collectExecution">the object that represents the execution of a collect</param>
        /// <returns></returns>
        private ProbeExecution ExecuteCollect(IDocumentSession session, SelectedProbe probe, CollectRequest collectRequest, VariablesEvaluated variables,
                                              IEnumerable<StateType> states, ExecutionLogBuilder executionLog)
        {
            ProbeResult probeResult = null;

            executionLog.StartCollectOf(probe.Capability.OvalObject);

            var initialTimeStamp = DateTime.Now;
            this.SetStartInstrumentationLog(executionLog, initialTimeStamp, probe.Capability.OvalObject);

            probeResult = probe.Execute(connectionContext, Target, variables, collectRequest.GetSystemCharacteristics(session), states);

            this.SetEndInstrumentationLog(executionLog, initialTimeStamp, probe.Capability.OvalObject);

            this.MergeExecutionLogs(executionLog, probe, probeResult);
            return this.CreateTheProbeExecution(probeResult, probe);
        }
Esempio n. 25
0
 public string CreateSerializedExecutionLog(IDocumentSession session, CollectRequest collectRequest)
 {
     var executionLogs = this.GetExecutionLogs(session, collectRequest).ToArray();
     return JsonConvert.SerializeObject(executionLogs);
 }
        /// <summary>
        /// Execute the collect for the probes selected
        /// </summary>
        /// <param name="selectedProbes">The selected probes.</param>
        /// <param name="collectRequest">The request collect.</param>
        private void ExecuteCollectWithProbes(IDocumentSession session, IEnumerable<SelectedProbe> selectedProbes, CollectRequest collectRequest,
                                              VariablesEvaluated variables, IEnumerable<StateType> states, CollectExecution collectExecution, ExecutionLogBuilder executionLog)
        {
            foreach (SelectedProbe probe in selectedProbes)
            {
                if (Interrupted)
                {
                    break;
                }

                try
                {
                    ProbeExecution probeExecution = this.ExecuteCollect(session, probe, collectRequest, variables, states, executionLog);
                    collectExecution.ProbeExecutions.Add(probeExecution);
                }
                catch (RecoverableProbeException ex)
                {
                    this.ConfigureTheCollectRequestWithAnErrorProbeExecute(collectRequest, probe.Capability.OvalObject, collectExecution, ex, executionLog);
                    session.SaveChanges();
                    throw ex;
                }
                catch (Exception ex)
                {
                    EndsACollectRequestBecauseThisErrorIsUnrecoverable(collectRequest, probe.Capability.OvalObject, collectExecution, ex, executionLog);
                    session.SaveChanges();
                    throw ex;
                }
            }

            session.SaveChanges();
        }
Esempio n. 27
0
 private IEnumerable<ExecutionLog> GetExecutionLogs(IDocumentSession session, CollectRequest collectRequest)
 {
     var logs = collectRequest.GetExecutionLog(session);
     return this.executionLogAssembler.CreateDTOsFromCollectionOfExecutionLogs(logs);               
 }       
 private void SetStatusToExecuting(CollectRequest collectRequest)
 {
     collectRequest.SetExecutingStatus();
 }
Esempio n. 29
0
 private string SaveCollectRequest(CollectRequest collectRequest)
 {
     try
     {
         return collectRequest.Oid;
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex);
     }
 }
        private void UpdateSystemInformationOfTarget(IDocumentSession session, CollectRequest collectRequest, FamilyEnumeration plataform, ExecutionLogBuilder executionLog)
        {
            if (!collectRequest.Target.IsSystemInformationDefined())
            {
                executionLog.CollectSystemInformation();
                ISystemInformationService systemInformationService = ProbeManager.GetSystemInformationService(plataform);
                if (systemInformationService != null)
                {
                    try
                    {
                        this.GetSystemInformationFromTarget(collectRequest, systemInformationService);
                        session.SaveChanges();
                    }
                    catch (RecoverableProbeException ex)
                    {
                        CollectExecution collectExecution = this.CreateCollectExecution(session, collectRequest);
                        collectExecution.SetDateStartCollect();
                        this.ConfigureTheCollectRequestWithAnErrorProbeExecute(collectRequest, "SystemInformation", collectExecution, ex, executionLog);
                        session.SaveChanges();
                        throw new SystemInformationException(ex.Message, ex);
                    }
                    catch (Exception ex)
                    {
                        CreateCollectionExcutionWithError(session, collectRequest, "SystemInformation", ex, executionLog);
                        session.SaveChanges();
                        throw new SystemInformationException(ex.Message, ex);
                    }

                }
            }
        }
 private void CloseExecutionIfIncomplete(IDocumentSession session, CollectRequest collectRequest, CollectExecution collectExecution, FamilyEnumeration plataform, IEnumerable<ObjectType> objectTypes)
 {
     IEnumerable<SelectedProbe> objectsNotSupported = ProbeManager.GetNotSupportedObjects(objectTypes, plataform);
     var objectNotSupported = this.GetObjectTypesFromSelectedProbes(objectsNotSupported);
     var objectSupportedNotCollect = objectTypes.Except(objectNotSupported);
     this.CreateCollectedObjectsForNotSupportedObjects(session, objectsNotSupported, collectRequest, collectExecution);
     if (objectSupportedNotCollect.Count() > 0)
     {
         IEnumerable<SelectedProbe> objectsSupportedNotCollected = ProbeManager.GetProbesFor(objectSupportedNotCollect, plataform);
         this.CreateCollectedObjectsForNotSupportedObjects(session, objectsSupportedNotCollected, collectRequest, collectExecution);
     }
     collectRequest.SetResultComplete(session);
     collectRequest.Close();
     session.SaveChanges();
 }