Example #1
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 #2
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 #3
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 #4
0
        /// <summary>
        /// Saves the specified property definition and commits it to the database.
        /// </summary>
        /// <param name="PropertyDef">The PropertyDefinition.</param>
        /// <returns></returns>
        public OperationReport Save(PropertyDefinition PropertyDef)
        {
            OperationReport validationReport = GuardAgainstNulls.ArgsContainsNull(new object[] { PropertyDef });

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

            OperationReport result = new OperationReport();

            try
            {
                IPersistCommandsTransaction trans = GetPersistTransactionFor(PropertyDef.Id);
                if (trans != null)
                {
                    if (newPropertyDefintions.ContainsKey(PropertyDef.Id))
                    {
                        if (PropertyDefinitionNameAvaliable(PropertyDef.Name))
                        {
                            NameToTypeAssociation propertyDefNameRegistration = RegisterPropertyDefintionName(PropertyDef.Name);
                            trans.Save(propertyDefNameRegistration);
                        }
                        else
                        {
                            throw new PropertyNameAlreadyDefinedException(PropertyDef.Name);
                        }
                    }
                    else
                    {
                        trans.SaveOrUpdate(PropertyDef);
                    }
                    result = persistor.ProcessCommandsTransaction(trans);

                    if (result.Success)
                    {
                        lock (newPropertyDefintions)
                        {
                            newPropertyDefintions.Remove(PropertyDef.Id);
                        }
                    }
                    else
                    {
                        //not sure what to do
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.AddNotification(ex.Message, ex);
            }

            return(result);
        }