public IEnumerable <PropertyDescriptor> GetPropertyDescriptors(ISupportPropertyValues domainObject) { if (!propertiesForTemplateType.ContainsKey(domainObject.TemplateId)) { throw new Exception(string.Format("The template with id {0} has not been registered with the type service", domainObject.Id)); } else { return(propertiesForTemplateType[domainObject.TemplateId]); } }
public void BuildPropertyValuesForObject(ISupportPropertyValues domainObject) { OperationReport report = GuardAgainstNulls.ArgsContainsNull(new object[] { domainObject }); if (!report.Success) { throw new OrcaArgumentNullException(report); } foreach (DefaultPropertyValue propertyDef in GetDefaultPropertyValuesDomainObject(domainObject.Id)) { if (domainObject.HasProperty(propertyDef.StaticInstanceID)) { continue; } CreateAndAssignPropertyValue(domainObject, propertyDef); } }
/// <summary> /// Initializes a new instance of the <see cref="PropertyTypeDescriptor"/> class. /// </summary> /// <param name="defaultDescriptor">The default descriptor.</param> /// <param name="instance">The instance.</param> /// public PropertyTypeDescriptor(ICustomTypeDescriptor defaultDescriptor, object instance) //public PropertyTypeDescriptor( ICustomTypeDescriptor defaultDescriptor, object instance, DynamicPropertyManager dynamicPropertyManager ) { _propertyCollections = defaultDescriptor.GetProperties( ); _dynamicPropertyDescriptors.AddRange(_propertyCollections.Cast <PropertyDescriptor>( )); //add the properties found to the collection if (instance is ISupportPropertyValues) { ISupportPropertyValues domainObject = instance as ISupportPropertyValues; foreach (PropertyValue item in domainObject.PropertyValues) { var found = _dynamicPropertyDescriptors.FirstOrDefault(x => x.Name == item.Name); if (found == null) { _dynamicPropertyDescriptors.Add(new PropertyValueDescriptor(item)); } } _propertyCollections = new PropertyDescriptorCollection(_dynamicPropertyDescriptors.ToArray( )); } if (instance is ISupportDefaultPropertyValues) { ISupportDefaultPropertyValues domainObject = instance as ISupportDefaultPropertyValues; foreach (DefaultPropertyValue item in domainObject.DefaultPropertyValues) { var found = _dynamicPropertyDescriptors.FirstOrDefault(x => x.Name == item.Name); if (found == null) { _dynamicPropertyDescriptors.Add(new DefaultPropertyValueDescriptor(item)); } } _propertyCollections = new PropertyDescriptorCollection(_dynamicPropertyDescriptors.ToArray( )); } }
private bool ValidateDomainObjectInstance(ISupportPropertyValues DomainObjectInstance) { return(DomainObjectInstance.PropertyValues.Count == 0); }
public void ApplyProperties(ISupportDefaultPropertyValues DefaultPropertyObject, ISupportPropertyValues DomainObjectInstance) { if (DefaultPropertyObject == null) { throw new ArgumentNullException("The DefaultPropertyObject parameter can not be null"); } if (DomainObjectInstance == null) { throw new ArgumentNullException("The DomainObjectInstance parameter can not be null"); } if (!ValidateDomainObjectInstance(DomainObjectInstance)) { throw new PropertiesAlreadyAssignedExistException(DomainObjectInstance.Name); } // var trans = persistor.GetTransaction(DomainObjectInstance.Id); foreach (DefaultPropertyValue item in DefaultPropertyObject.DefaultPropertyValues) { PropertyValue propValue = item.CreatePropertyValue(); // trans.Save(propValue); try { DomainObjectInstance.AddPropertyValue(propValue); } catch (Exception ex) { throw new PropertyValueException(string.Format("Exception adding PropertyValue {0} to domain object {1}", item.Name, DomainObjectInstance.Name), ex); } } if (DomainObjectInstance is IHasTemplate) { DomainObjectInstance.As <IHasTemplate>().TemplateId = DefaultPropertyObject.Id; } //trans.Save(DomainObjectInstance); //OperationReport report = persistor.ProcessCommandsTransaction(trans); //if (!report.Success) //{ // Exception ex = null; // if (report.ExceptionCount > 0) // { // ex = report.Exceptions.First(); // } // throw new PropertyValueException(string.Format("Exception persisting PropertyValue to the db for {0} domain object", DomainObjectInstance.Name), ex); //} }
private void CreateAndAssignPropertyValue(ISupportPropertyValues dynamicPropertyObject, DefaultPropertyValue propertyDefValue) { dynamicPropertyObject.AddPropertyValue(propertyDefValue.CreatePropertyValue()); }