Example #1
0
        public OperationReport UpdatePropertyDefinition(ISupportDefaultPropertyValues domainObject, DefaultPropertyValue propDefValue)
        {
            OperationReport newOperationReport = new OperationReport {
                Success = true
            };

            if (!domainObject.HasProperty(propDefValue.StaticInstanceID))
            {
                newOperationReport.Success = false;

                newOperationReport.AddNotification(string.Format("The domain object {0} does not contain the property definition value {1}", domainObject.Name, propDefValue.Name));

                return(newOperationReport);
            }

            //get the transaction for the worktype name or id? need to be consistent.
            try
            {
                var Trans = GetPersistTransactionFor(domainObject.Id);

                Trans.SaveOrUpdate(propDefValue); //save the newly defined propertydefinition value object (to get the id) and add to the worktype
            }
            catch (Exception ex)
            {
                newOperationReport.AddNotification(ex.Message, ex);
            }

            return(newOperationReport);
        }
Example #2
0
        private OperationReport ValidateCanAssociateDefaultPropertyValueToObject(ISupportDefaultPropertyValues dynamicPropertyObject, PropertyDefinition PropertyDef)
        {
            OperationReport report = new OperationReport();

            report.Success = true;



            //ISupportDefaultPropertyValues dynamicPropertyObject = dynamicPropertyObject.As<ISupportDefaultPropertyValues>();


            if (!PropertyDef.IsPublished)
            {
                //var ex =  ;
                report.AddNotification(string.Format("The property Definition {0} has not been published", PropertyDef.Name), new PropertyDefinitionMustBePublishedException(PropertyDef.Name));
                report.Success = false;
            }



            if (HasDefaultPropertyValue(dynamicPropertyObject, PropertyDef))
            {
                report.AddNotification(string.Format("The domain object {0} already has the property {1} .", dynamicPropertyObject.Name, PropertyDef.Name), new PropertyAlreadyExistException(PropertyDef.Name, dynamicPropertyObject.Name));
                report.Success = false;
            }
            return(report);
        }
Example #3
0
        private DefaultPropertyValue CreateAndAssignDefaultPropertyValue(ISupportDefaultPropertyValues supportPropertiesObject, PropertyDefinition propertyDef, OperationReport operationReport)
        {
            OperationReport report = GuardAgainstNulls.ArgsContainsNull(new object[] { supportPropertiesObject, propertyDef });

            if (!report.Success)
            {
                operationReport.SetValues(report);
                return(null);
            }

            report = ValidateCanAssociateDefaultPropertyValueToObject(supportPropertiesObject, propertyDef);

            if (!report.Success)
            {
                operationReport.SetValues(report);

                return(null);
            }

            var propDefaultValue = new DefaultPropertyValue(propertyDef);



            supportPropertiesObject.AddDefaultPropertyValue(propDefaultValue);

            lock (typeProperties)
            {
                typeProperties[supportPropertiesObject.UserTypeID].Add(propDefaultValue.Name, propDefaultValue);
            }

            return(propDefaultValue);
        }
Example #4
0
        private OperationReport RemoveDefaultPropertyValue(ISupportDefaultPropertyValues supportPropertiesObject, PropertyDefinition PropertyDef)
        {
            OperationReport result = new OperationReport();

            var defaultPropValue = GetDefaultPropertyValue(supportPropertiesObject, PropertyDef);

            if (defaultPropValue == null)
            {
                result.Success = false;
                result.AddNotification(string.Format("The {0} domain object does not contain the property {1}", supportPropertiesObject.Name, PropertyDef.Name));
                return(result);
            }


            supportPropertiesObject.RemoveDefaultPropertyValue(defaultPropValue);

            var trans = persistor.GetTransaction(supportPropertiesObject.Id);

            trans.Delete(defaultPropValue);

            result.Success = true;

            lock (typeProperties)
            {
                typeProperties[supportPropertiesObject.UserTypeID].Remove(defaultPropValue.Name);
            }

            return(result);
        }
Example #5
0
        public void RegisterTemmplate(ISupportDefaultPropertyValues template)
        {
            if (propertiesForTemplateType.ContainsKey(template.Id))
            {
                return;
            }

            Type templateType = template.GetType( );



            TypeDescriptionProvider typeProvider = TypeDescriptor.GetProvider(templateType);

            HashSet <PropertyDescriptor> props = new HashSet <PropertyDescriptor>(propertyComparer);



            var propDescriptors = typeProvider.GetTypeDescriptor(typeof(ObjectType)).GetProperties( ).Cast <PropertyDescriptor>( );


            TypeDescriptionProvider templateTypeProvider = TypeDescriptor.GetProvider(templateType);

            var templatePropDescriptors = templateTypeProvider.GetTypeDescriptor(templateType, template).GetProperties( ).Cast <PropertyDescriptor>( );


            var propertyInfos = templatePropDescriptors.Where(p => !p.IsReadOnly);

            PopulateHashSet(props, propDescriptors);
            PopulateHashSet(props, propertyInfos);

            propertiesForTemplateType.Add(template.Id, props);
        }
        public virtual string GetValue(ISupportDefaultPropertyValues DomainObject)
        {
            if (!DomainObject.HasProperty(this.PropertyValueProvider.StaticInstanceID))
            {
                return(string.Empty);
            }

            return(DomainObject[PropertyValueProvider.StaticInstanceID].ToString( ));
        }
Example #7
0
        public OperationReport RemovePropertyValueFromDomainObject(ISupportDefaultPropertyValues UserTypeObject, PropertyDefinition PropertyDef)
        {
            OperationReport report = GuardAgainstNulls.ArgsContainsNull(new object[] { UserTypeObject, PropertyDef });

            if (!report.Success)
            {
                throw new OrcaArgumentNullException(report);
            }
            return(RemoveDefaultPropertyValue(UserTypeObject, PropertyDef));
        }
Example #8
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);
            //}
        }
Example #9
0
        public DefaultPropertyValue AddPropertyDefintionToDomainObject(ISupportDefaultPropertyValues DomainObjectForProperty, PropertyDefinition PropertyDef, OperationReport Report)
        {
            OperationReport validationReport = GuardAgainstNulls.ArgsContainsNull(new object[] { DomainObjectForProperty, PropertyDef });

            if (!validationReport.Success)
            {
                throw new OrcaArgumentNullException(validationReport);
            }

            return(CreateAndAssignDefaultPropertyValue(DomainObjectForProperty, PropertyDef, Report));
        }
Example #10
0
        public DefaultPropertyValue GetDefaultPropertyValue(ISupportDefaultPropertyValues dynamicPropertyObject, PropertyDefinition propertyDef)
        {
            OperationReport report = GuardAgainstNulls.ArgsContainsNull(new object[] { dynamicPropertyObject, propertyDef });

            if (!report.Success)
            {
                throw new OrcaArgumentNullException(report);
            }

            if (!typeProperties[dynamicPropertyObject.UserTypeID].ContainsKey(propertyDef.Name))
            {
                var result = _repository.GetFirst <DefaultPropertyValue>(x => x.PropertyDefinitionStaticID == propertyDef.StaticInstanceID && x.PropertyOwnerId == dynamicPropertyObject.Id);
                //                var result = _repository.Query<DefaultPropertyValue>().Where(
                //                x => x.PropertyDefinition.StaticInstanceID == propertyDef.StaticInstanceID && x.UserTypeID == dynamicPropertyObject.UserTypeID).FirstOrDefault();

                return(result);
            }

            return(typeProperties[dynamicPropertyObject.UserTypeID][propertyDef.Name]);
        }
Example #11
0
        public bool HasDefaultPropertyValue(ISupportDefaultPropertyValues dynamicPropertyObject, PropertyDefinition propertyDef)
        {
            OperationReport report = GuardAgainstNulls.ArgsContainsNull(new object[] { dynamicPropertyObject, propertyDef });

            if (!report.Success)
            {
                throw new OrcaArgumentNullException(report);
            }


            if (typeProperties[dynamicPropertyObject.UserTypeID].ContainsKey(propertyDef.Name))
            {
                return(true);
            }

            var count = _repository.GetCount <DefaultPropertyValue>(
                x => x.PropertyDefinitionStaticID == propertyDef.StaticInstanceID && x.PropertyOwnerId == dynamicPropertyObject.Id);


            return(count != 0);
        }
Example #12
0
        /// <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( ));
            }
        }