Example #1
0
 public Fact(FactType factType, DateInfo date, PlaceReference place, String value)
 {
     SetType(factType);
     SetDate(date);
     SetPlace(place);
     SetValue(value);
 }
Example #2
0
    public WorkingMemoryFact AddFact(FactType type, object target, Vector3 lastKnownPos, float confidence, float dropRate)
    {
        WorkingMemoryFact fact = new WorkingMemoryFact();
        fact.Confidence = confidence;
        fact.ConfidenceDropRate = dropRate;
        fact.FactType = type;
        fact.Target = target;
        Facts.Add(fact);

        return fact;
    }
Example #3
0
    public WorkingMemoryFact FindExistingFact(FactType type, object target)
    {
        foreach(WorkingMemoryFact f in Facts)
        {
            if(type == f.FactType && target == f.Target)
            {
                return f;
            }
        }

        return null;
    }
Example #4
0
        public void Fire_OneMatchingFactAssertedAndRetractedAndAssertedAgain_FiresOnce()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Valid Value 1"
            };

            Session.Insert(fact);
            Session.Retract(fact);
            Session.Insert(fact);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
        }
Example #5
0
        public void Fire_InsertThenFireThenUpdateThenFireThenUpdateThenFire_FiresOnMatchAndOnRematchTwice()
        {
            //Arrange
            var fact = new FactType();

            //Act
            Session.Insert(fact);
            Session.Fire();
            Session.Update(fact);
            Session.Fire();
            Session.Update(fact);
            Session.Fire();

            //Assert
            Assert.Equal(1, _matchActionCount);
            Assert.Equal(0, _unmatchActionCount);
        }
Example #6
0
        public void Fire_InsertThenFireThenUpdateThenFilterOffThenUpdateThenFire_FiresOnMatch()
        {
            //Arrange
            var fact = new FactType();

            //Act
            Session.Insert(fact);
            Session.Fire();
            Session.Update(fact);
            fact.AcceptFilter = false;
            Session.Update(fact);
            Session.Fire();

            //Assert
            Assert.Equal(1, _matchActionCount);
            Assert.Equal(0, _unmatchActionCount);
        }
Example #7
0
        public void Fire_InsertThenFireThenRetractThenInsertThenFire_FiresOnMatchTwiceAndOnUnmatch()
        {
            //Arrange
            var fact = new FactType();

            //Act
            Session.Insert(fact);
            Session.Fire();
            Session.Retract(fact);
            Session.Insert(fact);
            Session.Fire();

            //Assert
            Assert.Equal(2, _matchActionCount);
            Assert.Equal(0, _rematchActionCount);
            Assert.Equal(1, _unmatchActionCount);
        }
Example #8
0
        /// <summary>See <see cref="ElementTypeDescriptor.ShouldCreatePropertyDescriptor"/>.</summary>
        protected override bool ShouldCreatePropertyDescriptor(ModelElement requestor, DomainPropertyInfo domainProperty)
        {
            Guid propertyId = domainProperty.Id;

            if (propertyId == Role.MultiplicityDomainPropertyId)
            {
                FactType        factType = ModelElement.FactType;
                Objectification objectification;
                LinkedElementCollection <RoleBase> roles;
                // Display for binary fact types
                if (factType != null &&
                    !(factType is QueryBase) &&
                    (roles = factType.RoleCollection).Count == 2)
                {
                    if (null != (objectification = factType.ImpliedByObjectification))
                    {
                        roles = objectification.NestedFactType.RoleCollection;
                        if (roles.Count != 2)
                        {
                            return(false);
                        }
                    }
                    return(!FactType.GetUnaryRoleIndex(roles).HasValue);
                }
                return(false);
            }
            else if (propertyId == Role.IsMandatoryDomainPropertyId ||
                     propertyId == Role.ValueRangeTextDomainPropertyId)
            {
                if (ModelElement.FactType is QueryBase)
                {
                    return(false);
                }
            }
            else if (propertyId == Role.MandatoryConstraintNameDomainPropertyId ||
                     propertyId == Role.MandatoryConstraintModalityDomainPropertyId)
            {
                return(ModelElement.SimpleMandatoryConstraint != null);
            }
            else if (propertyId == Role.ObjectificationOppositeRoleNameDomainPropertyId)
            {
                FactType fact = ModelElement.FactType;
                return(fact != null && fact.Objectification != null);
            }
            return(base.ShouldCreatePropertyDescriptor(requestor, domainProperty));
        }
Example #9
0
        public void Fire_MatchingFactInsertedAndUpdatedToInvalid_DoesNotFire()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Valid value"
            };

            Session.Insert(fact);
            fact.TestProperty = "Invalid value";
            Session.Update(fact);

            //Act
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
Example #10
0
        public void Fire_FactInserted_EachRuleFires()
        {
            //Arrange
            var order = new FactType {
                Value = "Value1"
            };

            Session.Insert(order);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce <FactToCalc1Rule>();
            AssertFiredOnce <Calc1ToCalc2Rule>();
            AssertFiredOnce <Calc1Calc2ToCalc3Rule>();
        }
        public void Fire_OneMatchingFactInsertedThenUpdated_FiresOnce()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Valid Value 1"
            };

            Session.Insert(fact);
            Session.Update(fact);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
            Assert.Equal(fact.TestProperty, GetFiredFact <FactProjection>().Value);
        }
Example #12
0
        public void Insert_FilterErrorHasErrorHandler_DoesNotFire()
        {
            //Arrange
            GetRuleInstance <TestRule>().FilterCondition = ThrowFilter;

            Session.Events.AgendaFilterFailedEvent += (sender, args) => args.IsHandled = true;
            var fact = new FactType {
                TestProperty = "Valid Value"
            };

            //Act
            Session.Insert(fact);
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
        public FactType GetById(int id)
        {
            FactType result = null;

            StringBuilder sqlStr = new StringBuilder();

            sqlStr.AppendLine("select *");
            sqlStr.AppendLine("from " + TableNameWithScheme);
            sqlStr.AppendLine(string.Format("where {0} = :p_codepol", tableFieldID));

            if (this.session != null && this.session.Connection != null && this.session.Connection.State == ConnectionState.Open)
            {
                SqlCommand command = new SqlCommand(sqlStr.ToString(), this.session.Connection);
                command.Parameters.AddWithValue("p_id", id);

                DataSet        dataSet     = new DataSet();
                SqlDataAdapter dataAdapter = new SqlDataAdapter(command);

                DataTable table;

                try
                {
                    dataAdapter.Fill(dataSet);

                    if (dataSet.Tables.Count > 0)
                    {
                        table = dataSet.Tables[0];

                        if (table.Rows.Count == 1)
                        {
                            DataRow row = table.Rows[0];

                            result = new FactType();

                            ReadFields(result, row);
                        }
                    }
                }
                catch (Exception)
                {
                }
            }

            return(result);
        }
Example #14
0
        public void Fire_OneMatchingFactAssertedAndRetractedAndAssertedAgain_FiresOnce()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Valid Value 1"
            };

            Session.Insert(fact);
            Session.Retract(fact);
            Session.Insert(fact);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
            Assert.AreEqual(fact.TestProperty, GetFiredFact <FactProjection>().Value);
        }
Example #15
0
        /// <summary>
        ///根据SQL语句获取集合
        /// </summary>
        public static IList <FactType> getFactTypesBySql(string sql)
        {
            IList <FactType> list = new List <FactType>();
            DataTable        dt   = DBHelper.GetDataSet(sql);

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    FactType facttype = new FactType();
                    facttype.Id         = Convert.ToInt32(dr["id"]);
                    facttype.TypeName   = Convert.ToString(dr["typeName"]);
                    facttype.Typeremark = Convert.ToString(dr["typeremark"]);
                    list.Add(facttype);
                }
            }
            return(list);
        }
Example #16
0
        public void Fire_OneMatchingFactAssertedAndModifiedAndRetracted_DoesNotFire()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Valid Value 1"
            };

            Session.Insert(fact);

            fact.TestProperty = "Invalid Value 1";
            Session.Retract(fact);

            //Act
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
Example #17
0
        public void Fire_OneFactUpdatedFromInvalidToMatching_FiresOnce()
        {
            //Arrange
            var fact = new FactType {
                TestProperty = "Invalid Value 1"
            };

            Session.Insert(fact);

            fact.TestProperty = "Valid Value 1";
            Session.Update(fact);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
        }
            public override void Define()
            {
                FactType      fact     = null;
                ITestService1 service1 = null;
                ITestService2 service2 = null;

                Dependency()
                .Resolve(() => service1)
                .Resolve(() => service2);

                When()
                .Match <FactType>(() => fact, f => f.TestProperty.StartsWith("Valid"));
                Then()
                .Do(ctx => Action(ctx))
                .Do(ctx => service1.Action(fact.TestProperty))
                .Do(ctx => service2.Action(fact.TestProperty))
                .Do(ctx => SomeAction(fact, service1, service2));
            }
Example #19
0
        public void Fire_MatchingNotPatternFactAssertedThenUpdatedToInvalid_FiresOnce()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };

            Session.Insert(fact1);

            fact1.TestProperty = "Invalid Value 1";
            Session.Update(fact1);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
        }
Example #20
0
        public void Fire_TwoMatchingFacts_FiresOnceAndHalts()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Valid Value 2"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
        }
Example #21
0
        public void Fire_TwoMatchingFactsInsertedTwoRetracted_FiresOnceWithEmptyCollection()
        {
            // Arrange
            var fact1 = new FactType(5, "A");
            var fact2 = new FactType(10, "A");

            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);
            Session.Retract(fact1);
            Session.Retract(fact2);

            // Act
            Session.Fire();

            // Assert
            AssertFiredOnce();
            Assert.Empty(GetFiredFact <IEnumerable <FactType> >());
        }
Example #22
0
        public void Fire_FirstMatchingFactSecondInvalid_DoesNotFire()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Valid Value 2"
            };

            Session.Insert(fact1);
            Session.Insert(fact2);

            //Act
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
Example #23
0
        public void Fire_TwoMatchingFacts_FiresTwice()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid value"
            };
            var fact2 = new FactType {
                TestProperty = "Valid value"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();

            //Assert
            AssertFiredTwice();
        }
        public void Fire_ConditionFailedInsert_DoesNotFire()
        {
            //Arrange
            GetRuleInstance <TestRule>().Condition = ThrowCondition;

            Session.Events.LhsExpressionFailedEvent += (sender, args) => args.IsHandled = true;

            var fact = new FactType {
                TestProperty = "Valid Value"
            };

            Session.Insert(fact);

            //Act
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
Example #25
0
        /// <summary>
        /// Creates a FactTypeMapsTowardsRole link in the same Partition as the given FactType
        /// </summary>
        /// <param name="source">FactType to use as the source of the relationship.</param>
        /// <param name="target">RoleBase to use as the target of the relationship.</param>
        /// <param name="depth">Initial value for the <see cref="Depth"/> property.</param>
        public static FactTypeMapsTowardsRole Create(FactType source, RoleBase target, MappingDepth depth)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            MappingMandatoryPattern  mandatoryPattern;
            MappingUniquenessPattern uniquenessPattern;

            GetMappingPatterns(target, out uniquenessPattern, out mandatoryPattern);
            return(new FactTypeMapsTowardsRole(
                       source.Partition,
                       new RoleAssignment[] { new RoleAssignment(FactTypeMapsTowardsRole.FactTypeDomainRoleId, source), new RoleAssignment(FactTypeMapsTowardsRole.TowardsRoleDomainRoleId, target) },
                       new PropertyAssignment[] { new PropertyAssignment(DepthDomainPropertyId, depth), new PropertyAssignment(UniquenessPatternDomainPropertyId, uniquenessPattern), new PropertyAssignment(MandatoryPatternDomainPropertyId, mandatoryPattern) }));
        }
Example #26
0
 /// <summary>
 /// Place a newly added role name shape
 /// </summary>
 /// <param name="parent">Parent FactTypeShape</param>
 /// <param name="createdDuringViewFixup">Whether this shape was created as part of a view fixup</param>
 public override void PlaceAsChildOf(NodeShape parent, bool createdDuringViewFixup)
 {
     if (createdDuringViewFixup)
     {
         FactTypeShape factShape = (FactTypeShape)parent;
         double        x         = -0.2;
         double        y         = -0.2;
         FactType      factType  = factShape.AssociatedFactType;
         // Cascades RoleNameShapes for facts that contain more than one role
         LinkedElementCollection <RoleBase> roles = factShape.DisplayedRoleOrder;
         int roleIndex = roles.IndexOf((RoleBase)ModelElement);
         if (roleIndex != -1)
         {
             x += roleIndex * 0.15;
             y -= roleIndex * 0.15;
         }
         Location = new PointD(x, y);
     }
 }
        public void Fire_FailedAssert_DoesNotFire()
        {
            //Arrange
            GetRuleInstance <TestRule>().Binding = ThrowBinding;

            Session.Events.BindingFailedEvent += (sender, args) => args.IsHandled = true;

            var fact = new FactType {
                TestProperty = "Valid value"
            };

            Session.Insert(fact);

            //Act
            Session.Fire();

            //Assert
            AssertDidNotFire();
        }
Example #28
0
        public void Fire_TwoMatchingFacts_FiresTwiceAndRetractsFacts()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Valid Value 2"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();

            //Assert
            AssertFiredTwice();
            Assert.Equal(0, Session.Query <FactType>().Count());
        }
Example #29
0
        public void Fire_TwoMatchingFactsFireCalledTwice_FiresOnceThenHaltsThenResumesAndFiresAgain()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Valid Value 2"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();
            Session.Fire();

            //Assert
            AssertFiredTwice();
        }
Example #30
0
        public void ExclusionMandatoryContra_1a(Store store)
        {
            myTestServices.LogValidationErrors("No Errors Found Initialliy");

            ORMModel model = store.ElementDirectory.FindElements <ORMModel>()[0];

            // Input file(ExclusionMandatoryContra_1a.Load.orm) specific code.
            // Recommend finding a better method of retrieving the role in context.
            FactType factType = model.FactTypeCollection[2];
            Role     role     = (Role)factType.RoleCollection[0];

            using (Transaction t = store.TransactionManager.BeginTransaction("Add Mandatory Constraint"))
            {
                role.IsMandatory = true;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is Introduced");
            store.UndoManager.Undo();
            myTestServices.LogValidationErrors("Error is removed with Undo");
        }
Example #31
0
        public void Fire_OneMatchingFactTwoFactsToAggregate_FiresOnceWithTwoFactsInCollection()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Invalid Value 2"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();

            //Assert
            AssertFiredOnce();
            Assert.Equal(2, GetFiredFact <IEnumerable <FactType> >().Count());
        }
Example #32
0
        public void Fire_TwoMatchingFacts_FiresTwice()
        {
            //Arrange
            var fact1 = new FactType {
                TestProperty = "Valid Value 1"
            };
            var fact2 = new FactType {
                TestProperty = "Valid Value 2"
            };
            var facts = new[] { fact1, fact2 };

            Session.InsertAll(facts);

            //Act
            Session.Fire();

            //Assert
            AssertFiredTwice();
            Assert.Equal(fact1.TestProperty, GetFiredFact <FactProjection>(0).Value);
            Assert.Equal(fact2.TestProperty, GetFiredFact <FactProjection>(1).Value);
        }
Example #33
0
        public void Insert_ErrorInConditionNoErrorHandler_Throws()
        {
            //Arrange
            Expression    expression = null;
            IList <IFact> facts      = null;

            Session.Events.ConditionFailedEvent += (sender, args) => expression = args.Condition;
            Session.Events.ConditionFailedEvent += (sender, args) => facts = args.Facts.ToList();

            var fact = new FactType {
                TestProperty = null
            };

            //Act - Assert
            var ex = Assert.Throws <RuleConditionEvaluationException>(() => Session.Insert(fact));

            Assert.NotNull(expression);
            Assert.Equal(1, facts.Count());
            Assert.Same(fact, facts.First().Value);
            Assert.IsType <NullReferenceException>(ex.InnerException);
        }
Example #34
0
 public Fact(FactType factType, String value)
 {
     SetType(factType);
     SetValue(value);
 }
Example #35
0
	public void RemoveFact(FactType type, object target)
	{
		WorkingMemoryFact fact = null;
		foreach(WorkingMemoryFact f in Facts)
		{
			if(f.FactType == type && Object.Equals(f.Target, target))
			{
				fact = f;
			}
		}
		if(fact != null)
		{
			Facts.Remove(fact);
		}
	}
Example #36
0
 public Fact(FactType factType, DateInfo date, PlaceReference place)
     :this(factType, date, place, null)
 {
 }
Example #37
0
 public Fact(FactType factType, String date, String place)
     :this(factType, new DateInfo().SetOriginal(date), new PlaceReference().SetOriginal(place), null)
 {
 }
Example #38
0
 /**
  * Build up this fact with a type.
  *
  * @param type The type.
  * @return this
  */
 public Fact SetType(FactType type)
 {
     KnownType = type;
     return this;
 }
Example #39
0
	public List<WorkingMemoryFact> FindExistingFactOfType(FactType type)
	{
		List<WorkingMemoryFact> facts = new List<WorkingMemoryFact>();
		foreach(WorkingMemoryFact f in Facts)
		{
			if(type.Equals(f.FactType))
			{
				facts.Add(f);
			}
		}

		return facts;
	}
Example #40
0
	public void RemoveFact(FactType type)
	{
		HashSet<WorkingMemoryFact> copy = new HashSet<WorkingMemoryFact>(Facts);
		foreach(WorkingMemoryFact f in copy)
		{
			if(f.FactType == type)
			{
				Facts.Remove(f);
			}
		}
	}