示例#1
0
        /// <summary>
        /// returns a determination of the applicability of the Concept to a given entity
        /// </summary>
        /// <param name="entity">the Entity of reference.</param>
        /// <returns>false if the passed entity is null</returns>
        public bool AppliesTo(IPersistEntity entity)
        {
            if (string.IsNullOrEmpty(applicableRootEntity))
            {
                return(false);
            }
            try
            {
                var filterType = ParentModelView.ParentMvdXml.Engine.GetExpressType(
                    ParentModelView.applicableSchema,
                    applicableRootEntity);
                var contains = filterType.NonAbstractSubTypes.Contains(entity.ExpressType);
                if (!contains)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"applicableRootEntity {applicableRootEntity} not recognised in ConceptRoot '{name}' (uuid: {uuid})", ex);
                return(false);
            }

            // now evaluate applicability rules or return true
            return(Applicability == null ||
                   Applicability.IsApplicable(entity));
        }
示例#2
0
        public override int GetHashCode()
        {
            int hashCode = 1516578759;

            hashCode = (hashCode * -1521134295) + IsSponsorSpot.GetHashCode();
            hashCode = (hashCode * -1521134295) + Applicability.GetHashCode();
            hashCode = (hashCode * -1521134295) + CompetitorType.GetHashCode();
            hashCode = (hashCode * -1521134295) + RestrictionType.GetHashCode();
            return(hashCode);
        }
示例#3
0
    public static void Main(string[] args)
    {
        CsdbObject    dm  = new CsdbObject("test.xml");
        Applicability app = new Applicability();

        app.Assign("version", "prodattr", "A");

        Console.WriteLine(dm.Filter(app, FilterMode.Default).XmlDocument.OuterXml);
        Console.WriteLine(dm.Filter(app, FilterMode.Reduce).XmlDocument.OuterXml);
        Console.WriteLine(dm.Filter(app, FilterMode.Simplify).XmlDocument.OuterXml);
        Console.WriteLine(dm.Filter(app, FilterMode.Prune).XmlDocument.OuterXml);
    }
示例#4
0
 internal void SetParent(ModelView modelView)
 {
     ParentModelView = modelView;
     ParentModelView.ParentMvdXml?.Engine?.AddConceptRootLookup(this);
     if (Concepts != null)
     {
         foreach (var concept in Concepts)
         {
             concept.SetParent(this);
         }
     }
     Applicability?.SetParent(modelView, this);
 }
示例#5
0
        public void Setup()
        {
            var ruleList = new List <Rule>();


            _mappings = new Dictionary <int, string>
            {
                { 1, "i" },
                { 2, "ii" },
                { 3, "iii" },
                { 4, "iv" },
                { 5, "v" },
                { 6, "vi" },
                { 7, "vii" },
                { 8, "viii" },
                { 9, "ix" },
                { 10, "x" },
                { 50, "l" },
            };

            Func <int, bool> IsLessThanorEqualTo10 = i => i <= 10 && i > 0;
            Func <int, bool> isLessThan11          = _mappings.ContainsKey;

            var applicability = new Applicability(isLessThan11);
            Func <int, RuleResult> arabicNumeralToRomanNumeral = i => _mappings.ContainsKey(i) ? new RuleResult(_mappings[i], 0) : new RuleResult("", 0);
            var lessThan11 = new Rule(applicability, arabicNumeralToRomanNumeral);


            var between11and40 = new Applicability(i => i > 10 && i < 40);
            Func <int, RuleResult> printNumber11To40 = i => new RuleResult(arabicNumeralToRomanNumeral(10).GetStringOutput() + arabicNumeralToRomanNumeral(i).GetStringOutput(), i - 10);
            var ElevenToTwentyRule = new Rule(between11and40, printNumber11To40);


            var from40To49 = new Applicability(i => i >= 40 && i <= 49);
            Func <int, RuleResult> print40to50 = i => new RuleResult(arabicNumeralToRomanNumeral(10).GetStringOutput() + arabicNumeralToRomanNumeral(50).GetStringOutput() +
                                                                     arabicNumeralToRomanNumeral(i - 40).GetStringOutput(), 0);

            var FourtytoFourtyNineRule = new Rule(from40To49, print40to50);


            ruleList.Add(FourtytoFourtyNineRule);
            ruleList.Add(ElevenToTwentyRule);
            ruleList.Add(lessThan11);

            var numeralConverter = new NumeralConverter(ruleList);

            _subject = new NumeralPrinter(numeralConverter);
        }