public CollectRequest CreateCollectRequestCompleteAfterCollect(IDocumentSession session) { CollectRequest collectRequest = new CollectRequest(); session.Store(collectRequest); CollectExecution collectExecution = new CollectExecution(); session.Store(collectExecution); collectExecution.RequestId = collectRequest.Oid; collectExecution.SetDateStartCollect(); collectExecution.SetDateEndCollect(); ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); CollectFactory collectFactory = new CollectFactory(session); ProbeExecution probeExecution = collectFactory.CreateAProbeExecution(probeResult, "registry"); CollectResult collectResult = new CollectResultFactory().CreateCollectResultForTheProbeExecution(probeResult); collectRequest.Result = collectResult; string systemCharacteristicsXml = this.GetSystemCharacteristicsInXML(".system_characteristics.oval.org.mitre.oval.sc.5368.xml"); collectResult.SystemCharacteristics = systemCharacteristicsXml; probeExecution.SystemCharacteristics = collectResult.SystemCharacteristics; collectExecution.ProbeExecutions.Add(probeExecution); this.CreateTarget(session, collectRequest); //session.Store(collectRequest); collectExecution.RequestId = collectRequest.Oid; return(collectRequest); }
/// <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(); }
/// <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); }
public ProbeExecution CreateProbeExecution(IDocumentSession session, string capability) { ProbeExecution registryProbe = new ProbeExecution() { Capability = capability, }; return(registryProbe); }
/// <summary> /// Creates the probe execution with his collect result /// </summary> /// <param name="probeResult">The probe result.</param> /// <param name="probe">The probe.</param> /// <param name="session">The session.</param> /// <returns></returns> private ProbeExecution CreateTheProbeExecution(ProbeResult probeResult, SelectedProbe probe) { CollectResultFactory collectResultFactory = new CollectResultFactory(); ProbeExecution executionOfCurrentProbe = collectFactory.CreateAProbeExecution(probeResult, probe.Capability.OvalObject); CollectResult probeExecutionResult = collectResultFactory.CreateCollectResultForTheProbeExecution(probeResult); executionOfCurrentProbe.SystemCharacteristics = probeExecutionResult.SystemCharacteristics; return(executionOfCurrentProbe); }
public CollectExecution CreateACollectExecutionWithError(IDocumentSession session) { CollectExecution collectExecution = new CollectExecution(); collectExecution.SetDateStartCollect(); ProbeExecution probeExecution = this.GetProbeExecutionWithError(session); collectExecution.ProbeExecutions.Add(probeExecution); collectExecution.SetDateEndCollect(); return(collectExecution); }
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(); } }
public void Should_be_possible_to_build_a_probeExecution_from_collectedObject() { CollectFactory collectFactory = new CollectFactory(provider.GetSession()); ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegistryCollect(); ProbeExecution probeExecution = collectFactory.CreateAProbeExecution(probeResult, "registry"); Assert.IsNotNull(probeExecution); Assert.AreEqual("registry", probeExecution.Capability); Assert.IsTrue(probeExecution.ExecutionLogs.Count == 8, "the probe execution not have executionLogs expecteds"); Assert.IsTrue(probeExecution.IsComplete(), "the probe execution not have a status expected"); }
public void Shoud_be_possible_to_build_a_probeExecution_with_the_error_status_if_not_collect_was_executed() { CollectFactory collectFactory = new CollectFactory(provider.GetSession()); ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegostryCollectWithError(); ProbeExecution probeExecution = collectFactory.CreateAProbeExecutionWithError("registry", "Erro connecting to host"); Assert.IsNotNull(probeExecution); Assert.AreEqual("registry", probeExecution.Capability); Assert.IsTrue(probeExecution.ExecutionLogs.Count == 1, "the probe execution not have executionLogs expecteds"); Assert.IsTrue(probeExecution.HasErrors(), "the probe execution not have a status expected"); }
public void Should_be_possible_to_build_a_probeExecution_with_error_status_and_execution_logs_if_not_collect_was_executed() { CollectFactory collectFactory = new CollectFactory(provider.GetSession()); ProbeResult probeResult = probeResultFactory.CreateProbeResultForRegostryCollectWithError(); ExecutionLogBuilder executionLog = new ExecutionLogBuilder(); executionLog.StartCollectOf("registry"); executionLog.TryConnectToHost("176.16.3.22"); executionLog.AnErrorOccurred("Error connecting to host"); executionLog.EndCollect(); ProbeExecution probeExecution = collectFactory.CreateAProbeExecutionWithError("registry", executionLog.BuildExecutionLogs()); Assert.IsNotNull(probeExecution); Assert.AreEqual("registry", probeExecution.Capability); Assert.IsTrue(probeExecution.ExecutionLogs.Count == 4, "the probe execution not have executionLogs expecteds"); Assert.IsTrue(probeExecution.HasErrors(), "the probe execution not have a status expected"); }
public CollectRequest CreateCollectRequestIncompleteAfterCollect(IDocumentSession session) { CollectRequest collectRequest = new CollectRequest(); string definitionsInXml = GetOvalObjectInXML(".definitions.fdcc_xpfirewall_oval.xml"); StringBuilder builder = new StringBuilder(definitionsInXml); var newDefinitiondoc = new DefinitionDocument() { OriginalId = "01", Text = builder.ToString() }; session.Store(newDefinitiondoc); collectRequest.OvalDefinitionsId = newDefinitiondoc.Oid; session.Store(collectRequest); CollectExecution collectExecution = new CollectExecution(); collectExecution.RequestId = collectRequest.Oid; session.Store(collectExecution); collectExecution.SetDateStartCollect(); collectExecution.SetDateEndCollect(); //collectRequest.Collects.Add(collectExecution); ProbeResult probeResult = new ProbeResultFactory().CreateProbeResultForRegistryCollect(); CollectFactory collectFactory = new CollectFactory(session); ProbeExecution probeExecution = collectFactory.CreateAProbeExecution(probeResult, "registry"); CollectResult collectResult = new CollectResultFactory().CreateCollectResultForTheProbeExecution(probeResult); string systemCharacteristicsXml = this.GetSystemCharacteristicsInXML(".system_characteristics.fdcc_xpfirewall_oval.sc_incomplete.xml"); collectResult.SystemCharacteristics = systemCharacteristicsXml; probeExecution.SystemCharacteristics = collectResult.SystemCharacteristics; collectExecution.ProbeExecutions.Add(probeExecution); // collectRequest.Collects.Add(collectExecution); this.CreateTarget(session, collectRequest); session.SaveChanges(); return(collectRequest); }