Exemplo n.º 1
0
        /// <summary>
        /// Deletes the property definition and removes it from the database.
        /// </summary>
        /// <param name="PropDef">The prop def.</param>
        /// <returns></returns>
        public OperationReport DeletePropertyDefinition(PropertyDefinition PropDef)
        {
            OperationReport validationReport = GuardAgainstNulls.ArgsContainsNull(new object[] { PropDef });

            if (!validationReport.Success)
            {
                throw new OrcaArgumentNullException(validationReport);
            }
            if (PropDef.IsPublished)
            {
                throw new CanNotDeletePublishedDomainObject(PropDef.Name);
            }

            if (newPropertyDefintions.ContainsKey(PropDef.Id))
            {
                newPropertyDefintions.Remove(PropDef.Id);
                persistor.CancelTransaction(PropDef.Id);

                return(new OperationReport("", true));
            }


            var trans = GetPersistTransactionFor(PropDef.Id);

            trans.Delete(PropDef);

            return(persistor.ProcessCommandsTransaction(trans));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
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);
        }
 public void ConstructorSetsValues()
 {
     var message = "Some Message";
     var report = new OperationReport(true, message);
     Assert.IsTrue(report.WasSuccess);
     Assert.AreEqual(message, report.Message);
 }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public PropertyDefinition DefinePropertyDefinition(object DefaultValue, string Name)
        {
            OperationReport validationReport = GuardAgainstNulls.ArgsContainsNull(new object[] { DefaultValue, Name });

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

            OperationReport result = new OperationReport();

            PropertyDefinition def = new PropertyDefinition(Name, DefaultValue);

            persistor.AssignNewID(def);

            //the save only saves to the session, not persisted to the db
            //so the only way to get the object again is by its id
            //to allow for lookup by name we need to keep an assocation of name to id
            //when the object has been persisted out to the db then we remove it from the collection.
            lock (newPropertyDefintions)
            {
                newPropertyDefintions.Add(def.Id, def);
            }

            return(def);
        }
Exemplo n.º 8
0
        /// <summary>Runs a delegate in a seperate thread.</summary>
        /// <param name="run">The delegate to run in the background with reporting.</param>
        /// <param name="report">The delegate for reporting</param>
        /// <param name="resolve">The delegate for handling the completion of the background thread.</param>
        public static IAsyncResult Thread(
            OperationReport run,
            Callback report,
            Resolve resolve)
        {
            if (run == null)
            {
                throw new System.ArgumentNullException("run");
            }
            if (report == null)
            {
                throw new System.ArgumentNullException("report");
            }
            if (resolve == null)
            {
                throw new System.ArgumentNullException("resolve");
            }

            SynchronizationContext context = SynchronizationContext.Current;

            return(run.BeginInvoke(
                       () => { context.Post((object state) => { report(); }, null); },
                       (IAsyncResult ar) => { context.Post((object state) => { resolve(ar); }, null); },
                       null));
        }
        public void ConstructorSetsValues()
        {
            var message = "Some Message";
            var report  = new OperationReport(true, message);

            Assert.IsTrue(report.WasSuccess);
            Assert.AreEqual(message, report.Message);
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        public OperationReport CanPublish(PropertyDefinition propertyDef)
        {
            OperationReport validationReport = GuardAgainstNulls.ArgsContainsNull(new object[] { propertyDef });

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

            return(publishService.CanPublish(propertyDef));
        }
Exemplo n.º 13
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));
        }
 public void ValuesArePassedCorrectly()
 {
     var message = "Some Message";
     var report = new OperationReport
                      {
                          WasSuccess = false,
                          Message = message
                      };
     var result = report.DoRoundTripTest();
     Assert.IsFalse(result.WasSuccess);
     Assert.AreEqual(message, result.Message);
 }
        public void ValuesArePassedCorrectly()
        {
            var message = "Some Message";
            var report  = new OperationReport
            {
                WasSuccess = false,
                Message    = message
            };
            var result = report.DoRoundTripTest();

            Assert.IsFalse(result.WasSuccess);
            Assert.AreEqual(message, result.Message);
        }
Exemplo n.º 16
0
        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);
            }
        }
Exemplo n.º 17
0
        public object BeforeCall(string operationName, object[] inputs)
        {
            _stopwatch = Stopwatch.StartNew();

            _paramatersInspectorMetricsReport = new OperationReport()
            {
                OperationName     = operationName,
                MetricsReportType = MetricsReportTypes.Operation,
                Tags = new List <Tag>()
                {
                    new Tag()
                    {
                        Key   = TagsKeyTypes.SourceName.ToString(),
                        Value = nameof(ParametersInspector)
                    }
                }
            };

            return(null);
        }
Exemplo n.º 18
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]);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>Runs a delegate in a seperate thread.</summary>
        /// <param name="run">The delegate to run in the background with reporting.</param>
        /// <param name="report">The delegate for reporting</param>
        public static IAsyncResult Thread(
            OperationReport run,
            Callback report)
        {
            if (run is null)
            {
                throw new ArgumentNullException(nameof(run));
            }
            if (report is null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            SynchronizationContext context = SynchronizationContext.Current;

            return(run.BeginInvoke(
                       () =>
            {
                context.Post((object state) => { report(); }, null);
            },
                       (IAsyncResult ar) => { },
                       null));
        }
Exemplo n.º 21
0
 public OrcaArgumentNullException(OperationReport report)
     : base(report.GetNotifications())
 {
 }
Exemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance of the MethodFailureMessageCommand class.
 /// </summary>
 public MethodFailureMessageCommand(OperationReport operationResult)
 {
     ClassName       = string.Empty;
     MethodName      = string.Empty;
     OperationResult = operationResult;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the MethodFailureMessageCommand class.
 /// </summary>
 public MethodFailureMessageCommand(OperationReport operationResult, string className, string methodName)
     : this(operationResult)
 {
     ClassName  = className;
     MethodName = methodName;
 }