public EntityModel(EntityModel em) : this(em.Name) { IsNomenclature = em.IsNomenclature; foreach (var pm in em.Properties) Properties.Add(pm); foreach (var rel in em.Relations) Relations.Add(rel); foreach (var rule in em.Rules) Rules.Add(rule); }
private void EnsureCreatedOn(EntityModel em) { var createdOn = em.Properties[Properties.CreatedOn]; if (createdOn == null) { var mb = new ModelBuilder(em); mb.AddDateTime(Properties.CreatedOn); //mb.Rules.AddRequired(Properties.CreatedOn);//TODO-History: make createdon not null } else if (createdOn.Type != PropertyType.Datetime || createdOn.DefaultValue != null) throw new NotSupportedException(string.Format("Entity <{0}> contains property <{1}> which is system for the HistoryModule.", em.Name, createdOn.Name)); }
private void EnsureCreatedBy(EntityModel em) { var createdBy = em.Properties[Properties.CreatedBy]; if (createdBy == null) { var mb = new ModelBuilder(em); mb.AddInteger(Properties.CreatedBy); //mb.Rules.AddRequired(Properties.CreatedBy);//TODO-History: make createdby not null } else if (createdBy.Type != PropertyType.Number || createdBy.DefaultValue != null || (createdBy as NumberPropertyModel).IsInteger != true) throw new NotSupportedException(string.Format("Entity <{0}> contains property <{1}> which is system for the HistoryModule.", em.Name, createdBy.Name)); }
public RelationModel(EntityModel entity1, EntityModel entity2, RelationType type, string role) { var isLeft = entity1.Name.ToLower().CompareTo(entity2.Name.ToLower()) < 0; Left = isLeft ? entity1 : entity2; Right = isLeft ? entity2 : entity1; if (!isLeft) { if (type == RelationType.OneToMany) type = RelationType.ManyToOne; else if (type == RelationType.ManyToOne) type = RelationType.OneToMany; } Type = type; Role = role; Name = string.Format("{0}_{1}_{2}", Left.Name, Right.Name, Role); }
private XmlNode createEntity(EntityModel em) { var entity = xml.CreateElement("Entity"); entity.Attributes.Append(attr("name", em.Name)); entity.Attributes.Append(attr("isNomenclature", em.IsNomenclature)); var properties = xml.CreateElement("Properties"); entity.AppendChild(properties); foreach (var pm in em.Properties) { properties.AppendChild(createProperty(pm)); } var rules = xml.CreateElement("Rules"); entity.AppendChild(rules); foreach (var rule in em.Rules) { rules.AppendChild(createRule(rule)); } return entity; }
public RelationModel(EntityModel entity1, EntityModel entity2, RelationType type, string role) { var isLeft = entity1.Name.ToLower().CompareTo(entity2.Name.ToLower()) < 0; Left = isLeft ? entity1 : entity2; Right = isLeft ? entity2 : entity1; if (!isLeft) { if (type == RelationType.OneToMany) { type = RelationType.ManyToOne; } else if (type == RelationType.ManyToOne) { type = RelationType.OneToMany; } } Type = type; Role = role; Name = string.Format("{0}_{1}_{2}", Left.Name, Right.Name, Role); }
void IDomainChangeListener.BeforeSave(EntityModel entityModel) { if (!entityModel.Properties.Contains("Id")) { ModelBuilder mb = new ModelBuilder(entityModel); mb.AddIdentity("Id"); } }
void IDomainChangeListener.AfterSave(EntityModel entityModel) { }
private EntityRuleModel readRule(XmlElement el, EntityModel em) { var type = el.Attributes["type"].Value; switch (type) { case "RequiredRuleModel": return new RequiredRuleModel(em.Properties[el.Attributes["property"].Value]); case "UniqueRuleModel": var propNodes = el.SelectNodes("Property"); PropertyModel[] pms = new PropertyModel[propNodes.Count]; int i = 0; foreach (XmlElement pn in propNodes) { pms[i] = em.Properties[pn.Attributes["name"].Value]; } return new UniqueRuleModel(pms); case "FutureOrPastDateRuleModel": return new FutureOrPastDateRuleModel(em.Properties[el.Attributes["property"].Value] as DateTimePropertyModel, TimeSpan.Parse(el.Attributes["offset"].Value), bool.Parse(el.Attributes["future"].Value)); default: throw new NotImplementedException(string.Format("Deserialization of EntityRule of type {0} is not implemented.", type)); } }
private EntityModel readEntity(XmlElement el) { var entity = new EntityModel(el.Attributes["name"].Value); entity.IsNomenclature = bool.Parse(el.Attributes["isNomenclature"].Value); var properties = el.SelectNodes("Properties/Property"); foreach (var pe in properties) { if (pe is XmlElement) entity.Properties.Add(readProperty(pe as XmlElement)); } foreach (var re in el.SelectNodes("Rules/Rule")) { if (re is XmlElement) entity.Rules.Add(readRule(re as XmlElement, entity)); } return entity; }
public EntityModelJson(EntityModel em) { Name = em.Name; IsNomenclature = em.IsNomenclature; Properties = em.Properties.ToList(); Relations = em.Relations.Select(rm => new RelationModelJson(rm)).ToList(); Rules = em.Rules.ToList(); }
public void BeforeSave(EntityModel entityModel) { if (entityModel.IsNomenclature) return; if (!entityModel.Properties.Contains("CreatedOn")) { var mb = new ModelBuilder(entityModel); mb.AddDateTime("CreatedOn"); } }
public void AfterSave(EntityModel entityModel) { }
public RulesBuilder(EntityModel model) { EntityModel = model; }
public ModelBuilder(EntityModel model) { _model = model; Rules = new RulesBuilder(_model); }