Пример #1
0
 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);
             }
         }
     }
 }
Пример #2
0
        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();
        }
Пример #3
0
        public void MyTestInitialize()
        {
            var mocks = new MockRepository();
            Func<IProbe> registryMethod = delegate() { return new RegistryProber(); };
            Func<IProbe> familyProberWindowsMethod = delegate { return new FamilyProberWindows(); };
            Func<IProbe> familyProberUnixMethod = delegate { return new FamilyProberUnix(); };
            Func<IProbe> lineProberCiscoIosMethod = delegate { return new LineProber(); };
            Func<ISystemInformationService> systemInformationMethod = delegate() { return new WindowsSystemInformationService(); };

            var registryProbe =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    registryMethod, GetProbeCapability("registry", FamilyEnumeration.windows));
            var familyProberWindows =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    familyProberWindowsMethod, GetProbeCapability("family", FamilyEnumeration.windows));
            var familyProberUnix =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    familyProberUnixMethod, GetProbeCapability("family", FamilyEnumeration.unix));
            var lineProberCiscoIOS =
                mocks.StrictMock<Lazy<IProbe, IProbeCapabilities>>(
                    lineProberCiscoIosMethod, GetProbeCapability("line", FamilyEnumeration.ios));

            var probes = GetProbeCapabilities(registryProbe, familyProberWindows, familyProberUnix, lineProberCiscoIOS);

            var windowsInformationService =
                mocks.StrictMock<Lazy<ISystemInformationService, ISystemInformationServicePlataform>>(
                    systemInformationMethod, GetSystemInformationSvcForWindows());

            var systemInformations =
                new Lazy<ISystemInformationService, ISystemInformationServicePlataform>[] { windowsInformationService };

            ProbeManager = new ProbeManager() { probes = probes, systemInformationServices = systemInformations };
        }
Пример #4
0
        /// <summary>
        /// TO BE RELEASED...
        /// Return all capabilities of the collect service. A Capabilitie is defined by
        /// the type of Oval Object and the plataform.
        /// </summary>
        /// <returns>A dictionary with the format [OvalType],[Plataform] </returns>
        public Dictionary <string, string> GetCapabilities()
        {
            var probeCababilities = ProbeManager.GetCapabilities();

            return(this.CreateADictionaryOfProbeCapabilities(probeCababilities));
        }
Пример #5
0
        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();
        }