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)); } }
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)); } } }
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 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); } } }
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); } } }
public AttributeDomainItemsModel(ResourceStructureAttribute attr) { AttrId = attr.Id; AttrName = attr.Name; DomainItems = new List <DomainItemModel>(); if (attr.Constraints != null) { foreach (Constraint constraint in attr.Constraints) { if (constraint is DomainConstraint) { DomainConstraint dc = (DomainConstraint)constraint; dc.Materialize(); List <DomainItemModel> domainItemModelList = new List <DomainItemModel>(); dc.Items.ToList().ForEach(r => domainItemModelList.Add(new DomainItemModel(r))); DomainItems = domainItemModelList; } } } }
public ResourceStructureAttributeUsageModel(long usageId, long resourceAttributeId, string parentName) { UsageId = usageId; ResourceAttributeId = resourceAttributeId; //set Parent if exsits if (parentName != null) { ParentAttributeName = parentName; } else { ParentAttributeName = ""; } using (ResourceStructureAttributeManager rsaManager = new ResourceStructureAttributeManager()) { ResourceAttributeUsage usage = rsaManager.GetResourceAttributeUsageById(usageId); IsValueOptional = usage.IsValueOptional; IsFileDataType = usage.IsFileDataType; RS.ResourceStructureAttribute attr = rsaManager.GetResourceStructureAttributesById(resourceAttributeId); foreach (Constraint constraint in attr.Constraints) { if (constraint is DomainConstraint) { DomainConstraint dc = (DomainConstraint)constraint; dc.Materialize(); DomainConstraint = new DomainConstraintModel(dc); } } ResourceAttributeName = attr.Name; ResourceAttributeDescription = attr.Description; } }
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 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 ActionResult SaveResourceStructureAttribute(EditResourceStructureAttributeModel model, string[] keys) { using (var rsaManager = new ResourceStructureAttributeManager()) { //check name if (model.AttributeName != null) { ResourceStructureAttribute tempRS = rsaManager.GetResourceStructureAttributesByName(StringHelper.CutSpaces(model.AttributeName)); if (tempRS != null && tempRS.Id != model.Id) { ModelState.AddModelError("NameExist", "Name already exist."); } } //check domain items if (keys != null) { List <DomainItemModel> tempList = new List <DomainItemModel>(); foreach (string k in keys) { DomainItemModel d = new DomainItemModel(); d.Key = k; d.Value = k; tempList.Add(d); if (string.IsNullOrEmpty(k)) { ModelState.AddModelError("DomainItem", "One domain item has no value."); } } model.DomainItems = tempList; } if (ModelState.IsValid) { ResourceStructureAttribute rsa = new ResourceStructureAttribute(); using (var rsManager = new ResourceStructureManager()) { if (model.Id == 0) { rsa = rsaManager.CreateResourceStructureAttribute(model.AttributeName, model.AttributeDescription); } else { rsa = rsaManager.GetResourceStructureAttributesById(model.Id); rsa.Name = model.AttributeName; rsa.Description = model.AttributeDescription; rsaManager.UpdateResourceStructureAttribute(rsa); } if (rsa != null && model.Id == 0) { //Start -> add security ---------------------------------------- using (EntityPermissionManager pManager = new EntityPermissionManager()) using (var entityTypeManager = new EntityManager()) using (UserManager userManager = new UserManager()) { var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name); userTask.Wait(); var user = userTask.Result; Entity entityType = entityTypeManager.FindByName("ResourceStructureAttribute"); pManager.Create(user, entityType, rsa.Id, 31); } //End -> add security ------------------------------------------ } if (keys != null) { List <DomainItem> domainItems = CreateDomainItems(keys); using (var dcManager = new DataContainerManager()) { if (model.Id == 0 || rsa.Constraints.Count() == 0) { DomainConstraint dc = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, domainItems); dcManager.AddConstraint(dc, rsa); } else { DomainConstraint temp = (DomainConstraint)rsa.Constraints.ElementAt(0); temp.Materialize(); temp.Items = domainItems; dcManager.AddConstraint(temp, rsa); } } } //Creation with usage if (model.rsID != 0) { ResourceStructure resourceStructure = rsManager.GetResourceStructureById(model.rsID); rsaManager.CreateResourceAttributeUsage(rsa, resourceStructure, true, false); //resourceStructure.ResourceStructureAttributes.Add(rsa); //rsManager.Update(resourceStructure); //return View("_editResourceStructure", new ResourceStructureModel(resourceStructure)); return(Json(new { success = true })); } else { return(Json(new { success = true })); } } } else { return(PartialView("_createResourceStructureAttribute", model)); } } }
private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute) { DataContainerManager dcManager = null; try { 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, true); 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); } finally { dcManager.Dispose(); } }
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 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; }