private DB.GreenConstraint AddNewConstraint(ConstraintViewModel aNewConstraint) { DB.TemplateConstraint lUnderlyingConstraint = _tdb.TemplateConstraints.Single(tc => tc.Id == aNewConstraint.id); ConstraintXpathBuilder lXpathBuilder = new ConstraintXpathBuilder(_tdb); string lXpath = lXpathBuilder.GenerateXpath(lUnderlyingConstraint); DB.GreenConstraint lNewModel = new DB.GreenConstraint() { Description = aNewConstraint.businessName, Name = aNewConstraint.elementName, TemplateConstraintId = aNewConstraint.id, RootXpath = lXpath }; if (aNewConstraint.datatypeId.HasValue) { DB.ImplementationGuideTypeDataType lDataType = _tdb.ImplementationGuideTypeDataTypes.Single(dt => dt.Id == aNewConstraint.datatypeId.Value); lNewModel.ImplementationGuideTypeDataType = lDataType; } return(lNewModel); }
private void CreateIfRequiredGreenTemplateTree(ConstraintViewModel aStartConstraint) { if (aStartConstraint.hasGreenConstraint) { return; } if (aStartConstraint.conformance != "SHALL" && aStartConstraint.conformance != "SHOULD") { return; } if (!string.IsNullOrEmpty(aStartConstraint.value)) { return; } var lChildren = aStartConstraint.children .Where(c => c.conformance == "SHALL" || c.conformance == "SHOULD") .Where(c => string.IsNullOrEmpty(c.value)); foreach (ConstraintViewModel lChild in lChildren) { CreateIfRequiredGreenTemplateTree(lChild); } if (aStartConstraint.children.Count > 0) { return; //Leaf-level only } DB.TemplateConstraint lRootConstraint = _tdb.TemplateConstraints.Single(c => c.Id == aStartConstraint.id); aStartConstraint.Use(c => { c.businessName = c.elementName = lRootConstraint.Context; c.hasGreenConstraint = true; string lDataTypeToUse = null; // --- Identify data type to use, which will come from data types contained in the IG if (!string.IsNullOrEmpty(lRootConstraint.DataType) && lRootConstraint.DataType != "ANY") { lDataTypeToUse = lRootConstraint.DataType; } else { ConstraintXpathBuilder lBuilder = new ConstraintXpathBuilder(_tdb); string lXpath = lBuilder.GenerateXpath(lRootConstraint); ConstraintDataTypeResolver lResolver = new ConstraintDataTypeResolver(); string lDataType = lResolver.GetConstraintDataType(lRootConstraint, lXpath); lDataTypeToUse = lDataType; } // --- Load data type, only use if constraint is leaf-level DB.ImplementationGuideTypeDataType lUnderlyingType = _tdb.ImplementationGuideTypeDataTypes.SingleOrDefault(d => d.DataTypeName == lDataTypeToUse); if (lUnderlyingType != null && lRootConstraint.ChildConstraints.Count(y => !y.IsPrimitive) == 0) { c.datatypeId = lUnderlyingType.Id; c.datatype = lUnderlyingType.DataTypeName; } }); }