Exemplo n.º 1
0
        /// <summary>
        /// Makes an attempt to extract event from payload
        /// </summary>
        /// <param name="payload">Payload to extract from</param>
        /// <param name="extractedEvent">Extracted event</param>
        /// <returns>Status of extraction. True when <paramref name="extractedEvent"/> created and initialized. </returns>
        public virtual bool TryExtract(JObject payload, [MaybeNullWhen(returnValue: false)] out Event extractedEvent)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var validationResult = Validator.Validate(payload);

            if (!validationResult.IsValid)
            {
                logger.Debug("Event extraction interrupted with validation failure. {failure}", validationResult.Errors.Aggregate(
                                 new StringBuilder(),
                                 (builder, failure) => builder.AppendLine(failure.ErrorMessage)));

                extractedEvent = null;
                return(false);
            }

            var eventData = ExtractionRules.Aggregate(new JObject(),
                                                      (current, extractionRule) => extractionRule.ApplyRule(current, payload));

            extractedEvent = new Event(EventName, eventData);

            logger.Debug("Event extracted! {event}", extractedEvent);

            return(true);
        }
Exemplo n.º 2
0
 public CbrExtract(ExtractionRules extractionRules, IArchiveFactoryDecoupling archiveFactoryDecoupling, IDirectory directory, IPath path)
 {
     _extractionRules  = extractionRules;
     _directory        = directory;
     _path             = path;
     FactoryDecoupling = archiveFactoryDecoupling;
 }