Exemple #1
0
 /// <summary>
 /// Returns true if the filtering expressions for this rule match true for the given CO.
 /// </summary>
 /// <param name="co"></param>
 /// <returns></returns>
 private bool IsCOFiltered(ClassificationObject co)
 {
     return(filteringExpressionMethods.TrueForAll(filter => filter.Invoke(co)));
 }
Exemple #2
0
        void IOutputWriter.WriteEntry(ClassificationObject co, IEnumerable <OutputEntryForOneRule> output)
        {
            var coNode = new XElement("co", new XAttribute("key", co.Key.ToString()));

            _outputDoc.Root.Add(coNode);

            var propsNode = new XElement("props");

            coNode.Add(propsNode);
            IEnumerable <byte> propIdsToWrite;

            if (Object.ReferenceEquals(_propertiesToWrite, null))
            {
                propIdsToWrite = co.EnabledProperties;
            }
            else
            {
                propIdsToWrite = _propertiesToWrite.Select(name => co.PropertyEnumManager.GetIdFromName(name));
            }
            foreach (Property property in co.Properties.GetPropertySet(propIdsToWrite))
            {
                var propertyNode = new XElement("property",
                                                new XAttribute("key", property.Name),
                                                new XAttribute("name", property.Name));
                propsNode.Add(propertyNode);
                string value = null;
                try
                {
                    value = property.ToString();
                }
                catch (Exception)
                {
                    propertyNode.Add(new XAttribute("error", "Obtaining string from Property threw an exception. Check your code."));
                }
                if (value == null)
                {
                    value = String.Empty;
                }
                propertyNode.Add(new XElement("value", value));
            }
            var rulesNode = new XElement("rules");

            coNode.Add(rulesNode);
            //only write OutputEntries for Rules that have matched
            foreach (OutputEntryForOneRule oefor in output)
            {
                var ruleNode = new XElement("rule");
                rulesNode.Add(ruleNode);
                ruleNode.Add(
                    new XAttribute("checks", oefor.OutputItems.Count.ToString()),
                    new XAttribute("result", oefor.Result.ToString()),
                    new XAttribute("name", oefor.Rule.GetType().Name),
                    new XAttribute("severity", oefor.Severity.ToString())
                    );


                foreach (OutputItem oi in oefor.OutputItems)
                {
                    var itemNode = new XElement("item");
                    ruleNode.Add(itemNode);
                    itemNode.Add(
                        new XAttribute("result", oi.Result.ToString()),
                        new XAttribute("message", oi.Message),
                        new XAttribute("severity", oi.Severity.ToString())
                        );
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// This method will be called by the engine (via RuleManager) for every
        /// <see cref="ClassificationObject"/> that enters the engine's processing pipe.
        /// NOTE: by design, one rule can only be processing one CO at a time! in multi thread scenario the same rule
        /// must not run on more than 1 thread!
        /// </summary>
        /// <param name="co">ClassificationObject to classify</param>
        private OutputEntryForOneRule ClassifyOneObject(ClassificationObject co)
        {
            try
            {
                if (this.TypeOfClassificationObject != co.GetType())
                {
                    return(null);
                }

                // Skip COs that do not match the filtering expression
                if (!this.IsCOFiltered(co))
                {
                    return(null);
                }

                _currentCO = co;

                currentOutputEntry = new OutputEntryForOneRule {
                    Rule = this, Result = false, CO = co
                };

                if (RuleStartsProcessingObject != null)
                {
                    RuleStartsProcessingObject(this, null);
                }

                MyPerformance.StartMeasuring();

                Run();

                // stopping perf measuring in the finally block
                if (RuleFinishedProcessingObject != null)
                {
                    RuleFinishedProcessingObject(this, null);
                }

                if (currentOutputEntry != null)
                {
                    currentOutputEntry.SetTrueOrFalse();
                }
            }
            catch (OutOfMemoryException)
            {
                throw;
            }
            catch (StackOverflowException)
            {
                throw;
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Error while executing rule {0} on ClassificationObject: {1}.\n{2}",
                                       this.GetType().FullName,
                                       co.ToString(),
                                       e.GetExceptionDetails(false));
                this.OwningManager._owningEngine.Monitor.LogException(e);
            }
            finally
            {
                // stoping performance measurment
                MyPerformance.StopMeasuring();
            }

            return(currentOutputEntry);
        }