/// <summary> /// Creates a constraint tree for a set of components from a domain constraint. /// </summary> /// <param name="parent">The parent of the current constraint tree</param> /// <param name="derivedFrom">The domain constraint from which the tree is derived</param> /// <param name="components">The components for which to apply the relevant DomainConstraint</param> /// <param name="log">The processing log</param> internal ConfigurationConstraintTree(ConfigurationConstraintTree parent, DomainConstraint derivedFrom, List <GKOComponent> components, Log log) { if (derivedFrom == null) { throw new ArgumentNullException("The derived from domain constraints has to be set for a configuration constraints tree!"); } this.Parent = parent; // assigning the right DomainConstraint if (derivedFrom is ITransformDomainConstraint) { this.derivedFrom = (derivedFrom as ITransformDomainConstraint).TransformConstraint(); } else { this.derivedFrom = derivedFrom; } if (this.DerivedFrom is DomainConstraintCombination) { this.CreateFromCombinationConstraint((DomainConstraintCombination)this.DerivedFrom, components, log); } else { this.CreateFromNormalConstraint(this.DerivedFrom, components, log); } }
private void CreateDifferentPositionsConstr() { string domainConstraintName = "All with different positions"; BinaryRelation relation; ComponentFilter comp1Filter; ComponentFilter comp2Filter; GKOAttribute attribute; DomainConstraint domConstraint; // For all components / no filter comp1Filter = new ComponentFilter() { Filter = null, ComponentTypeFilter = null }; comp2Filter = new ComponentFilter() { Filter = null, ComponentTypeFilter = null }; // For the "Position" attribute attribute = this.KnowledgeBase.Attributes[7]; // Not equals relations must apply relation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.NotEquals); // Creating the domain constraint domConstraint = new DomainConstraint(domainConstraintName, relation, false); domConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(comp1Filter, attribute)); domConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(comp2Filter, attribute)); this.DomainConstraints.Add(domConstraint); }
// effects: Given a term expression, extracts the BoolLiteral from it internal static BoolLiteral GetBoolLiteral(DomainTermExpr term) { DomainConstraint <BoolLiteral, Constant> domainConstraint = term.Identifier; DomainVariable <BoolLiteral, Constant> variable = domainConstraint.Variable; return(variable.Identifier); }
public ActionResult OpenEditResourceStructureAttribute(long id) { using (ResourceStructureAttributeManager rsaManager = new ResourceStructureAttributeManager()) { ResourceStructureAttribute rsa = rsaManager.GetResourceStructureAttributesById(id); EditResourceStructureAttributeModel model = new EditResourceStructureAttributeModel(); model.Id = id; model.AttributeName = rsa.Name; model.AttributeDescription = rsa.Description; if (rsa.Constraints != null) { foreach (Constraint c in rsa.Constraints) { if (c is DomainConstraint) { DomainConstraint dc = (DomainConstraint)c; dc.Materialize(); List <DomainItemModel> domainItemModelList = new List <DomainItemModel>(); dc.Items.ToList().ForEach(r => domainItemModelList.Add(new DomainItemModel(r))); model.DomainItems = domainItemModelList; } } } return(PartialView("_createResourceStructureAttribute", model)); } }
private void CreateNoGapsConstr() { string domainConstraintName = "No position gaps"; BinaryRelation relation; ComponentFilter comp1Filter; GKOAttribute attribute; DomainConstraint domConstraint; // For all components / no filter comp1Filter = new ComponentFilter() { Filter = null, ComponentTypeFilter = null }; // For the "Position" attribute attribute = this.KnowledgeBase.Attributes[7]; // Less than relations must apply relation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.LessOrEqualsN); // Creating the domain constraint domConstraint = new DomainConstraint(domainConstraintName, relation, false); domConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(comp1Filter, attribute)); domConstraint.DomainRelationParts.Add(new MetricDomainRelationPart(SpecialMetricValue.ComponentsCount)); this.DomainConstraints.Add(domConstraint); }
public void CreateDomainConstraint(ResourceStructureAttribute attr, List <DomainItem> domainItems) { using (DataContainerManager dcManager = new DataContainerManager()) { DomainConstraint c3 = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, domainItems); dcManager.AddConstraint(c3, attr); } }
public JsonResult getDomainConstraintFormalDescription(bool invert, string Terms) { List <DomainItem> items = createDomainItems(Terms.Trim()); DomainConstraint Temp = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, "", invert, null, null, null, items); return(Json((Temp.FormalDescription), JsonRequestBehavior.AllowGet)); }
private void CreateIntervalStartEndConstraint() { GKOAttribute startAttr = this.KnowledgeBase.Attributes[8]; GKOAttribute endAttr = this.KnowledgeBase.Attributes[9]; DomainConstraint domConstraint = DomainConstraint.IntervalStartBeforeEndConstraint(startAttr, endAttr, false); this.DomainConstraints.Add(domConstraint); }
//private Relation activeRelation; public ConfigurationConstraint(DomainConstraint domainConstraint) { if (domainConstraint == null) { throw new ArgumentNullException("The domain constraint is not set!"); } this.DomainConstraint = domainConstraint; }
private void CreateFromNormalConstraint(DomainConstraint derivedFrom, List <GKOComponent> components, Log log) { this.ConfigurationConstraints = derivedFrom.GenerateConfigurationConstraints(components, log); foreach (var constraint in this.ConfigurationConstraints) { constraint.OwningTree = this; } }
private void CompareDomainConstraints(DomainConstraint dc1, DomainConstraint dc2) { Assert.IsNotNull(dc1.Domain); Assert.AreEqual(dc1.Domain, dc2.Domain); Assert.AreEqual(dc1.IsDeferrable, dc2.IsDeferrable); Assert.AreEqual(dc1.IsInitiallyDeferred, dc2.IsInitiallyDeferred); Assert.IsNotNull(dc1.Owner); Assert.AreEqual(dc1.Owner.Name, dc2.Owner.Name); }
public static void Open(string StartUrl, bool Modal = false, params string[] DomainConstraint) { var conf = new WebBrowserConfig(); conf.StarUrl = StartUrl; conf.Modal = Modal; conf.DomainConstraint = DomainConstraint.ToList(); Open(conf); }
/// <summary> /// Creates a term expression of the form: "<paramref name="literal"/> in <paramref name="range"/> with all possible values being <paramref name="domain"/>". /// </summary> internal static DomainTermExpr MakeTermExpression(BoolLiteral literal, Set <Constant> domain, Set <Constant> range) { domain.MakeReadOnly(); range.MakeReadOnly(); DomainVariable variable = new DomainVariable(literal, domain, EqualityIdentifierComparer); DomainConstraint constraint = new DomainConstraint(variable, range); DomainTermExpr result = new DomainTermExpr(EqualityComparer <DomainConstraint> .Default, constraint); return(result); }
private static ConstraintNode CreateDomainValueConstraint( [NotNull] IField field, [NotNull] DomainConstraint domainConstraint) { string description = string.Format("Domain {0}", domainConstraint.DomainName); return(new ConstraintNode( domainConstraint.GetConstraint(field), description, Codes[GdbConstraintIssueCodes.ValueNotValidForDomain], field.Name)); }
// creates "derived" views that may be helpful for answering the query // for example, view = SELECT ID WHERE B=2, query = SELECT ID,B WHERE B=2 // Created derived view: SELECT ID,B WHERE B=2 by adding the attribute whose value is determined by the where clause to projected list internal override FragmentQuery CreateDerivedViewBySelectingConstantAttributes(FragmentQuery view) { var newProjectedAttributes = new HashSet <MemberPath>(); // collect all variables from the view var variables = view.Condition.Variables; foreach (var var in variables) { var variableCondition = var.Identifier as MemberRestriction; if (variableCondition != null) { // Is this attribute not already projected? var conditionMember = variableCondition.RestrictedMemberSlot.MemberPath; // Iterating through the variable domain var.Domain could be wasteful // Instead, consider the actual condition values on the variable. Usually, they don't get repeated (if not, we could cache and check) var conditionValues = variableCondition.Domain; if ((false == view.Attributes.Contains(conditionMember)) && !(conditionValues.AllPossibleValues.Any(it => it.HasNotNull()))) //Don't add member to the projected list if the condition involves a { foreach (var value in conditionValues.Values) { // construct constraint: X = value var constraint = new DomainConstraint <BoolLiteral, Constant>( var, new Set <Constant>(new[] { value }, Constant.EqualityComparer)); // is this constraint implied by the where clause? var exclusion = view.Condition.Create( new AndExpr <DomainConstraint <BoolLiteral, Constant> >( view.Condition.Tree, new NotExpr <DomainConstraint <BoolLiteral, Constant> >( new TermExpr <DomainConstraint <BoolLiteral, Constant> >(constraint)))); var isImplied = false == IsSatisfiable(exclusion); if (isImplied) { // add this variable to the projection, if it is used in the query newProjectedAttributes.Add(conditionMember); } } } } } if (newProjectedAttributes.Count > 0) { newProjectedAttributes.UnionWith(view.Attributes); var derivedView = new FragmentQuery( String.Format(CultureInfo.InvariantCulture, "project({0})", view.Description), view.FromVariable, newProjectedAttributes, view.Condition); return(derivedView); } return(null); }
public DomainConstraintModel(DomainConstraint dc) { dc.Materialize(); AttributeName = dc.DataContainer.Name; Items = new List <DomainItemModel>(); if (dc.Items != null) { foreach (DomainItem i in dc.Items) { Items.Add(new DomainItemModel(i)); } } }
public static ResourceStructureAttributeModel Convert(RS.ResourceStructureAttribute attribute) { DomainConstraint dc = (DomainConstraint)attribute.Constraints.Where(p => p.GetType().Equals(typeof(DomainConstraint))); return(new ResourceStructureAttributeModel() { AttributeId = attribute.Id, AttributeName = attribute.Name, AttributeDescription = attribute.Description, //Constraints = attribute.Constraints.ToList() DomainConstraint = new DomainConstraintModel(dc) }); }
private void Create6thBefore10th() { string domainConstraintName = "Every 6th Before every 10th"; BinaryRelation relation; ComponentFilter comp1Filter; ComponentFilter comp2Filter; GKOAttribute attribute; DomainConstraint domConstraint; // For all components / no filter comp1Filter = new ComponentFilter() { Filter = null, ComponentTypeFilter = null, AttributeFilters = new List <AttributeFilter>() { new AttributeFilter(this.KnowledgeBase.Attributes[3], new List <string>() { true.ToString() }) } }; comp2Filter = new ComponentFilter() { Filter = null, ComponentTypeFilter = null, AttributeFilters = new List <AttributeFilter>() { new AttributeFilter(this.KnowledgeBase.Attributes[0], new List <string>() { true.ToString() }), new AttributeFilter(this.KnowledgeBase.Attributes[2], new List <string>() { true.ToString() }), } }; // For the "Position" attribute attribute = this.KnowledgeBase.Attributes[7]; // Not equals relations must apply relation = StructuralRelationsManager.GetRelation(RelationFamilyNames.MetricRelationsName, MetricRelationNames.GreaterThan); // Creating the domain constraint domConstraint = new DomainConstraint(domainConstraintName, relation, false); domConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(comp1Filter, attribute)); domConstraint.DomainRelationParts.Add(new AttributeDomainRelationPart(comp2Filter, attribute)); //domConstraint.DomainRelationParts.Add(new MetricDomainRelationPart(SpecialMetricValue.ComponentsCount)); this.DomainConstraints.Add(domConstraint); }
internal static ConstraintNetwork GenerateQualitativeConstraintNetwork(GKOStructuringContext strContext, RelationFamily calculus, Log log) { ConstraintNetwork resultNetwork = new ConstraintNetwork(calculus, strContext.Id + "_" + calculus.Name, log); List <ConfigurationConstraintTree> constraintTrees = strContext.StructuralConstraints.Where(x => x.RelationFamily == calculus).ToList(); // Creating the constraints restricting that self edges should be labeled with the Equals relation from the calculus DomainConstraint equalsDomainConstraint = DomainConstraint.SelfEqualsConstraint(calculus); ConfigurationConstraintTree equalsConstraint = new ConfigurationConstraintTree(null, equalsDomainConstraint, strContext.Components.Where(x => x.Active).ToList(), log); // Adding the constraints restricting that self edges should be labeled with the Equals relation from the calculus constraintTrees.Add(equalsConstraint); resultNetwork.Context = strContext; // Adding all components as nodes in the constraint network strContext.Components.Where(x => x.Active).ToList().ForEach(x => resultNetwork.Nodes.Add(new Node(x))); // Creating all edges in the constraint network, so it is a complete graph foreach (var startNode in resultNetwork.Nodes) { foreach (var endNode in resultNetwork.Nodes) { QualitativeEdge edge = new QualitativeEdge(resultNetwork, startNode, endNode); resultNetwork.Edges.Add(new Tuple <Node, Node>(startNode, endNode), edge); } } // Each constraint tree has a number of configuration constraints foreach (var constraintTree in constraintTrees) { List <ConfigurationConstraint> constraints = constraintTree.GetAllConfigurationConstraints(); // ToDo: Add check for equal constraints to avoid redundancy // Adding all constraints as edges in the networks constraints.ForEach(x => { // Hack: this uses the fact that each constraint has at least one allowed relation and all have the same signature and logic (i.e. start and end node) Node startNode = x.AllowedRelations[0].GetStartNode(x); Node endNode = x.AllowedRelations[0].GetEndNode(x); Tuple <Node, Node> edgeKey = new Tuple <Node, Node>(startNode, endNode); QualitativeEdge edge = resultNetwork.Edges[edgeKey] as QualitativeEdge; // Adding the constraint to the edge edge.Constraints.Add(x); }); } return(resultNetwork); }
private void CompareDomains(Xtensive.Sql.Model.Domain d1, Xtensive.Sql.Model.Domain d2) { Assert.IsNotNull(d1.Name); Assert.IsNotNull(d2.Name); Assert.AreEqual(d1.Name, d2.Name); CompareSqlValueTypes(d1.DataType, d2.DataType); Assert.AreEqual(d1.Schema.Name, d2.Schema.Name); foreach (DomainConstraint dc1 in d1.DomainConstraints) { DomainConstraint dc2 = d2.DomainConstraints[dc1.Name]; Assert.IsNotNull(dc2); CompareDomainConstraints(dc1, dc2); } }
private static List <object> createDomainContraintList(MetadataAttribute attribute) { List <object> list = new List <object>(); foreach (Constraint constraint in attribute.Constraints) { if (constraint is DomainConstraint) { DomainConstraint domainConstraint = (DomainConstraint)constraint; domainConstraint.Materialize(); domainConstraint.Items.ForEach(i => list.Add(i.Value)); } } return(list); }
public DataAttribute storeDomainConstraint(DomainConstraintModel constraintModel) { DataContainerManager dcManager = null; try { dcManager = new DataContainerManager(); DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId); List <DomainItem> items = new List <DomainItem>(); if (constraintModel.Terms != null && constraintModel.Terms.Trim() != "") { items = createDomainItems(constraintModel.Terms.Trim()); } if (items.Any()) { if (constraintModel.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = constraintModel.Description; temp.Negated = constraintModel.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } return(dataAttribute); } finally { dcManager.Dispose(); } }
public List <VariableStruct> getOrderedVariableStructs(StructuredDataStructure structuredDataStructure) { List <VariableStruct> variableStructs = new List <VariableStruct>(); List <Variable> variables = getOrderedVariables(structuredDataStructure); DataContainerManager dataAttributeManager = null; VariableStruct temp = new VariableStruct(); List <BExIS.Dlm.Entities.DataStructure.Constraint> tempconstraints; UnitDimenstionModel unitDimenstionModel = new UnitDimenstionModel(); foreach (Variable v in variables) { try { unitDimenstionModel = new UnitDimenstionModel(); temp.variable = v; temp.unitStructs = unitDimenstionModel.getUnitListByDimenstionAndDataType(v.DataAttribute.Unit.Dimension.Id, v.DataAttribute.DataType.Id); dataAttributeManager = new DataContainerManager(); tempconstraints = dataAttributeManager.DataAttributeRepo.Get(v.DataAttribute.Id).Constraints.ToList(); temp.rangeConstraints = new List <RangeConstraint>(); temp.domainConstraints = new List <DomainConstraint>(); temp.patternConstraints = new List <PatternConstraint>(); foreach (BExIS.Dlm.Entities.DataStructure.Constraint c in tempconstraints) { if (c is DomainConstraint) { DomainConstraint tempDomainConstraint = (DomainConstraint)c; tempDomainConstraint.Materialize(); temp.domainConstraints.Add(tempDomainConstraint); } if (c is PatternConstraint) { temp.patternConstraints.Add((PatternConstraint)c); } if (c is RangeConstraint) { temp.rangeConstraints.Add((RangeConstraint)c); } } variableStructs.Add(temp); } finally { dataAttributeManager.Dispose(); } } return(variableStructs); }
//public IReadOnlyRepository<DefaultValueConstraint> DefaultValueRepo { get; private set; } //public IReadOnlyRepository<DomainValueConstraint> DomainValueRepo { get; private set; } //public IReadOnlyRepository<ValidatorConstraint> ValidatorRepo { get; private set; } #endregion #region DomainConstraint internal DomainConstraint SaveConstraint(DomainConstraint constraint, DataContainer container) { Contract.Requires(constraint.Items != null); Contract.Requires(constraint.Items.Count > 0); Contract.Requires(container != null); Contract.Ensures(Contract.Result <DomainConstraint>() != null && Contract.Result <DomainConstraint>().Id >= 0); constraint.Dematerialize(); constraint.DataContainer = container; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <DomainConstraint> repo = uow.GetRepository <DomainConstraint>(); repo.Put(constraint); uow.Commit(); } return(constraint); }
public ResourceStructureAttributeModel(ResourceStructureAttribute attribute) { AttributeId = attribute.Id; AttributeName = attribute.Name; AttributeDescription = attribute.Description; foreach (Constraint constraint in attribute.Constraints) { if (constraint is DomainConstraint) { DomainConstraint dc = (DomainConstraint)constraint; dc.Materialize(); DomainConstraint = new DomainConstraintModel(dc); } } }
internal DomainConstraint Update(DomainConstraint entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result <DomainConstraint>() != null && Contract.Result <DomainConstraint>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <DomainConstraint> repo = uow.GetRepository <DomainConstraint>(); repo.Merge(entity); var merged = repo.Get(entity.Id); repo.Put(merged); uow.Commit(); } return(entity); }
internal bool Delete(DomainConstraint entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DomainConstraint> repo = uow.GetRepository<DomainConstraint>(); entity = repo.Reload(entity); //delete the unit repo.Delete(entity); // commit changes uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return (true); }
internal bool Delete(DomainConstraint entity) { Contract.Requires(entity != null); Contract.Requires(entity.Id >= 0); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <DomainConstraint> repo = uow.GetRepository <DomainConstraint>(); entity = repo.Reload(entity); //delete the unit repo.Delete(entity); // commit changes uow.Commit(); } // if any problem was detected during the commit, an exception will be thrown! return(true); }
public static DomainConstraintModel Convert(DomainConstraint domainConstraint, long attributeId) { domainConstraint.Materialize(); string terms = ""; if (domainConstraint.Items != null) { foreach (DomainItem i in domainConstraint.Items) { if (String.IsNullOrEmpty(i.Value)) { if (terms == "") { terms = i.Key; } else { terms = terms + ", " + i.Key; } } else { if (terms == "") { terms = i.Key + ", " + i.Value; } else { terms = terms + "; " + i.Key + ", " + i.Value; } } } } return(new DomainConstraintModel(attributeId) { Id = domainConstraint.Id, Negated = domainConstraint.Negated, Description = domainConstraint.Description, Terms = terms, FormalDescription = domainConstraint.FormalDescription }); }
public TextValueModel(TextValue value) { Id = value.Id; Value = value.Value; ResourceId = value.Resource.Id; ResourceAttributeUsageId = value.ResourceAttributeUsage.Id; ResourceAttributeUsage = new ResourceAttributeUsageModel(value.ResourceAttributeUsage); AttributeName = value.ResourceAttributeUsage.ResourceStructureAttribute.Name; foreach (Constraint constraint in value.ResourceAttributeUsage.ResourceStructureAttribute.Constraints) { if (constraint is DomainConstraint) { DomainConstraint dc = (DomainConstraint)constraint; dc.Materialize(); DomainConstraint = new DomainConstraintModel(dc); } } }
internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitTerm( TermExpr <DomainConstraint <BoolLiteral, Constant> > expression) { DomainConstraint <BoolLiteral, Constant> domainConstraint = expression.Identifier.InvertDomainConstraint(); if (domainConstraint.Range.Count == 0) { return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >)FalseExpr <DomainConstraint <BoolLiteral, Constant> > .Value); } List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > boolExprList = new List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >(); DomainVariable <BoolLiteral, Constant> variable = domainConstraint.Variable; foreach (Constant constant in domainConstraint.Range) { boolExprList.Add((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new DomainConstraint <BoolLiteral, Constant>(variable, new Set <Constant>((IEnumerable <Constant>) new Constant[1] { constant }, Constant.EqualityComparer))); } return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)boolExprList)); }
private DomainConstraint GetDomainConstraint(XmlSchemaObject restriction, MetadataAttribute attr, string restrictionDescription) { XmlSchemaObjectCollection facets = new XmlSchemaObjectCollection(); if (restriction is XmlSchemaSimpleTypeRestriction) facets = ((XmlSchemaSimpleTypeRestriction)restriction).Facets; if (restriction is XmlSchemaSimpleContentRestriction) facets = ((XmlSchemaSimpleContentRestriction)restriction).Facets; List<DomainItem> items = new List<DomainItem>(); foreach (XmlSchemaEnumerationFacet facet in facets) { if (facet != null) items.Add(new DomainItem(){Key = facet.Value, Value = facet.Value }); } DomainConstraint domainConstraint = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", restrictionDescription, false, null, null, null, items); domainConstraint.Materialize(); dataContainerManager.AddConstraint(domainConstraint,attr); return domainConstraint; }
public void AddConstraint(DomainConstraint constraint, DataContainer container) { helper.SaveConstraint(constraint, container); }
public void RemoveConstraint(DomainConstraint constraint) { constraint.DataContainer = null; helper.Delete(constraint); }
private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute) { DataContainerManager dcManager = new DataContainerManager(); if (constraintModel is RangeConstraintModel) { RangeConstraintModel rcm = (RangeConstraintModel)constraintModel; if (rcm.Id == 0) { RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, rcm.Description, rcm.Negated, null, null, null, rcm.Min, rcm.MinInclude, rcm.Max, rcm.MaxInclude); dcManager.AddConstraint(constraint, dataAttribute); } else { for(int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == rcm.Id) { ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = rcm.Description; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = rcm.Negated; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = rcm.Min; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = rcm.MinInclude; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = rcm.Max; ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = rcm.MaxInclude; break; } } } } if (constraintModel is PatternConstraintModel) { PatternConstraintModel pcm = (PatternConstraintModel)constraintModel; if (pcm.Id == 0) { PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, pcm.Description, pcm.Negated, null, null, null, pcm.MatchingPhrase, false); dcManager.AddConstraint(constraint, dataAttribute); } else { for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == pcm.Id) { ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description = pcm.Description; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = pcm.Negated; ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = pcm.MatchingPhrase; break; } } } } if (constraintModel is DomainConstraintModel) { DomainConstraintModel dcm = (DomainConstraintModel)constraintModel; List<DomainItem> items = createDomainItems(dcm.Terms); dcm.Terms = cutSpaces(dcm.Terms); if (items.Count > 0) { if (dcm.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, dcm.Description, dcm.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == dcm.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = dcm.Description; temp.Negated = dcm.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } } return dataAttribute; }
public JsonResult getDomainConstraintFormalDescription(string invert, string Terms) { List<DomainItem> items = createDomainItems(Terms); DomainConstraint Temp = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, "", Convert.ToBoolean(invert), null, null, null, items); return Json((Temp.FormalDescription), JsonRequestBehavior.AllowGet); }
public DataAttribute storeDomainConstraint(DomainConstraintModel constraintModel) { DataContainerManager dcManager = new DataContainerManager(); DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId); List<DomainItem> items = new List<DomainItem>(); if (constraintModel.Terms != null && constraintModel.Terms.Trim() != "") items = createDomainItems(constraintModel.Terms.Trim()); if (items.Count > 0) { if (constraintModel.Id == 0) { DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, items); dcManager.AddConstraint(constraint, dataAttribute); } else { DomainConstraint temp = new DomainConstraint(); for (int i = 0; i < dataAttribute.Constraints.Count; i++) { if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id) { temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i); temp.Materialize(); temp.Description = constraintModel.Description; temp.Negated = constraintModel.Negated; temp.Items = items; dcManager.AddConstraint(temp, dataAttribute); break; } } } } return dataAttribute; }
public static DomainConstraintModel Convert(DomainConstraint domainConstraint, long attributeId) { domainConstraint.Materialize(); string terms = ""; if (domainConstraint.Items != null) { foreach(DomainItem i in domainConstraint.Items) { if (String.IsNullOrEmpty(i.Value)) { if (terms == "") terms = i.Key; else terms = terms + ", " + i.Key; } else { if (terms == "") terms = i.Key + ", " + i.Value; else terms = terms + "; " + i.Key + ", " + i.Value; } } } return new DomainConstraintModel(attributeId) { Id = domainConstraint.Id, Negated = domainConstraint.Negated, Description = domainConstraint.Description, Terms = terms, FormalDescription = domainConstraint.FormalDescription }; }
private void addConstraintsTo() { DataContainerManager dcManager = new DataContainerManager(); var attr = dcManager.DataAttributeRepo.Get(1); var c1 = new RangeConstraint(ConstraintProviderSource.Internal, "", "en-US", "should be between 1 and 12 meter", true, null, null, null, 1.00, true, 12.00, true); dcManager.AddConstraint(c1, attr); var v1 = c1.IsSatisfied(14); var c2 = new PatternConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple email validation constraint", false, null, null, null, @"^\S+@\S+$", false); dcManager.AddConstraint(c2, attr); var v2 = c2.IsSatisfied("*****@*****.**"); List<DomainItem> items = new List<DomainItem>() { new DomainItem () {Key = "A", Value = "This is A" }, new DomainItem () {Key = "B", Value = "This is B" }, new DomainItem () {Key = "C", Value = "This is C" }, new DomainItem () {Key = "D", Value = "This is D" }, }; var c3 = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, items); dcManager.AddConstraint(c3, attr); var v3 = c3.IsSatisfied("A"); v3 = c3.IsSatisfied("E"); c3.Negated = true; v3 = c3.IsSatisfied("A"); var c4 = new ComparisonConstraint(ConstraintProviderSource.Internal, "", "en-US", "a comparison validation constraint", false, null, null, null , ComparisonOperator.GreaterThanOrEqual, ComparisonTargetType.Value, "", ComparisonOffsetType.Ratio, 1.25); dcManager.AddConstraint(c4, attr); var v4 = c4.IsSatisfied(14, 10); }
public void RemoveConstraint(DomainConstraint constraint) { helper.Delete(constraint); }
internal DomainConstraint Update(DomainConstraint entity) { Contract.Requires(entity != null, "provided entity can not be null"); Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID"); Contract.Ensures(Contract.Result<DomainConstraint>() != null && Contract.Result<DomainConstraint>().Id >= 0, "No entity is persisted!"); using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DomainConstraint> repo = uow.GetRepository<DomainConstraint>(); repo.Put(entity); // Merge is required here!!!! uow.Commit(); } return (entity); }
internal DomainConstraint SaveConstraint(DomainConstraint constraint, DataContainer container) { Contract.Requires(constraint.Items != null); Contract.Requires(constraint.Items.Count > 0); Contract.Requires(container != null); Contract.Ensures(Contract.Result<DomainConstraint>() != null && Contract.Result<DomainConstraint>().Id >= 0); constraint.Dematerialize(); constraint.DataContainer = container; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository<DomainConstraint> repo = uow.GetRepository<DomainConstraint>(); repo.Put(constraint); uow.Commit(); } return (constraint); }