/// <summary>
        /// Gets the recipients of the specified exit event
        /// </summary>
        /// <param name="exitEventRecipients">A list of reference attributes to obtain recipients from</param>
        /// <returns>A list of MAObjectHologram to send the specified exit event to</returns>
        private IList <MAObjectHologram> GetEventRecipientsFromAttributes(MAObjectHologram hologram)
        {
            List <MAObjectHologram> recipients = new List <MAObjectHologram>();

            foreach (AcmaSchemaAttribute recipientAttribute in this.Recipients)
            {
                AttributeValues values = hologram.GetAttributeValues(recipientAttribute);

                if (!values.IsEmptyOrNull)
                {
                    foreach (AttributeValue value in values)
                    {
                        MAObjectHologram recipient = ActiveConfig.DB.GetMAObjectOrDefault(value.ValueGuid);
                        if (recipient == null)
                        {
                            hologram.MarkMissingReference(value.ValueGuid, recipientAttribute);
                        }
                        else
                        {
                            recipients.Add(recipient);
                        }
                    }
                }
            }

            return(recipients);
        }
Exemple #2
0
        /// <summary>
        /// Gets the value of the declared attribute from the specified hologram
        /// </summary>
        /// <param name="hologram">The hologram to extract the values from</param>
        /// <returns>The values expanded from the hologram</returns>
        private IList <object> GetAttributeValues(MAObjectHologram hologram)
        {
            List <object> values = new List <object>();

            AttributeValues attributeValues = hologram.GetAttributeValues(this.Attribute, this.View);

            //if (this.Attribute.Name == "mail" && this.View == HologramView.Current)
            //{
            //    System.Diagnostics.Debugger.Launch();
            //}

            if (!attributeValues.IsEmptyOrNull)
            {
                foreach (AttributeValue attributeValue in attributeValues)
                {
                    values.Add(attributeValue.Value);
                }
            }

            if (values.Count == 0 && this.Attribute.Type == ExtendedAttributeType.Boolean)
            {
                values.Add(false);
            }

            return(values);
        }
        /// <summary>
        /// Contributes to a CSEntryChange for the specified MA_Delta_Object by populating newly added object and its attributes
        /// </summary>
        /// <param name="maObject">The MAObject to construct the CSEntry for</param>
        /// <param name="csentry">The CSEntryChange object to contribute to</param>
        private static void GetObject(MAObjectHologram maObject, CSEntryChange csentry, IEnumerable <AcmaSchemaAttribute> requiredAttributes)
        {
            try
            {
                foreach (AcmaSchemaAttribute maAttribute in requiredAttributes)
                {
                    List <object>   values   = new List <object>();
                    AttributeValues dbvalues = maObject.GetAttributeValues(maAttribute);
                    values.AddRange(dbvalues.Where(t => !t.IsNull).Select(t => t.Value));

                    if (values.Count > 0)
                    {
                        if (maAttribute.Type == ExtendedAttributeType.Reference)
                        {
                            csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values.Select(t => t.ToString()).ToList <object>()));
                        }
                        else if (maAttribute.Type == ExtendedAttributeType.DateTime)
                        {
                            csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values.Select(t => ((DateTime)t).ToResourceManagementServiceDateFormat()).ToList <object>()));
                        }
                        else
                        {
                            csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(maAttribute.Name, values));
                        }
                    }
                }
            }
            catch (SafetyRuleViolationException ex)
            {
                csentry.ErrorCodeImport = MAImportError.ImportErrorCustomContinueRun;
                csentry.ErrorName       = ex.Message;
                csentry.ErrorDetail     = ex.Message + "\n" + ex.StackTrace;
            }
        }
Exemple #4
0
        private bool EvaluateReferencedAttribute(MAObjectHologram sourceObject)
        {
            if (this.ReferencedObjectAttribute == null)
            {
                throw new InvalidOperationException("The value comparison rule does not have a reference attribute specified");
            }

            if (this.ReferencedObjectAttribute.IsMultivalued)
            {
                throw new InvalidOperationException("Cannot perform a presence comparison on a multivalued reference source attribute");
            }

            AttributeValues references = sourceObject.GetAttributeValues(this.ReferencedObjectAttribute);

            if (references.IsEmptyOrNull)
            {
                this.RaiseRuleFailure(string.Format("The reference attribute {{{0}}} was null", this.ReferencedObjectAttribute.Name));
                return(false);
            }

            Guid refGuid = references.First().ValueGuid;

            MAObjectHologram referenceSource = ActiveConfig.DB.GetMAObjectOrDefault(refGuid);

            if (referenceSource == null)
            {
                this.RaiseRuleFailure(string.Format("The reference attribute {{{0}}} referred to object {1} which did not exist in the database", this.ReferencedObjectAttribute.Name, refGuid));
                return(false);
            }
            else
            {
                return(this.EvaluateAttributeValue(referenceSource));
            }
        }
Exemple #5
0
        protected AttributeValue DBGetSVAttributeValue(AcmaSchemaAttribute attribute)
        {
            if (attribute.IsMultivalued)
            {
                throw new ArgumentException("The specified attribute is a multivalued attribute");
            }

            AttributeValues values = this.DBGetAttributeValues(attribute);

            return(values.FirstOrDefault() ?? new AttributeValue(attribute));
        }
Exemple #6
0
        /// <summary>
        /// Updates the values of the specified attribute according to the supplied ValueChange list
        /// </summary>
        /// <param name="attribute">The attribute to update</param>
        /// <param name="valueChanges">The value changes to apply</param>
        protected void DBUpdateAttribute(AcmaSchemaAttribute attribute, IList <ValueChange> valueChanges)
        {
            this.ThrowOnInheritedValueModification(attribute);

            if (attribute.Operation == AcmaAttributeOperation.AcmaInternalTemp)
            {
                return;
            }

            AttributeValues values = this.DBGetAttributeValues(attribute);

            values.ApplyValueChanges(valueChanges);
        }
Exemple #7
0
        /// <summary>
        /// Deletes all the values of the specified attribute
        /// </summary>
        /// <param name="attribute">The attribute to delete the values from</param>
        protected void DBDeleteAttribute(AcmaSchemaAttribute attribute)
        {
            this.ThrowOnInheritedValueModification(attribute);

            if (attribute.Operation == AcmaAttributeOperation.AcmaInternalTemp)
            {
                return;
            }

            AttributeValues values = this.DBGetAttributeValues(attribute);

            values.ClearValues();
        }
        /// <summary>
        /// Creates a CSEntryChange of the specified modification type for the supplied MAObjectHologram
        /// </summary>
        /// <param name="maObject">The MAObjectHologram to create the CSEntryChange from</param>
        /// <param name="objectModificationType">The object modification type to apply</param>
        /// <returns>A new CSEntryChange object representing the current state of the specified MAObjectHologram </returns>
        public static AcmaCSEntryChange CreateCSEntryChangeFromMAObjectHologram(this MAObjectHologram maObject, ObjectModificationType objectModificationType)
        {
            AcmaCSEntryChange csentry = new AcmaCSEntryChange();

            csentry.ObjectModificationType = objectModificationType;
            csentry.DN         = maObject.ObjectID.ToString();
            csentry.ObjectType = maObject.ObjectClass.Name;

            if (objectModificationType != ObjectModificationType.Delete)
            {
                AttributeModificationType attributeModificationType = objectModificationType == ObjectModificationType.Update ? AttributeModificationType.Replace : AttributeModificationType.Add;

                foreach (AcmaSchemaAttribute attribute in maObject.ObjectClass.Attributes.Where(t => t.Name != "objectId" && t.Name != "objectClass"))
                {
                    AttributeValues values = maObject.GetAttributeValues(attribute);

                    if (values.IsEmptyOrNull)
                    {
                        continue;
                    }

                    if (attributeModificationType == AttributeModificationType.Add)
                    {
                        AttributeChange change = AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList());
                        csentry.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, values.ToObjectList()));
                    }
                    else
                    {
                        csentry.AttributeChanges.Add(AttributeChange.CreateAttributeReplace(attribute.Name, values.ToObjectList()));
                    }
                }
            }

            if (csentry.ErrorCodeImport == MAImportError.Success)
            {
                MAStatistics.AddImportOperation();
            }
            else
            {
                MAStatistics.AddImportError();
            }

            return(csentry);
        }
Exemple #9
0
        private IList <object> GetAttributeValues(MAObjectHologram sourceObject)
        {
            List <object> values = new List <object>();

            AttributeValues attributeValues = sourceObject.GetAttributeValues(this.Attribute, this.View);

            if (!attributeValues.IsEmptyOrNull)
            {
                foreach (AttributeValue attributeValue in attributeValues)
                {
                    values.Add(attributeValue.Value);
                }
            }

            if (values.Count == 0 && this.Attribute.Type == ExtendedAttributeType.Boolean)
            {
                values.Add(false);
            }

            return(values);
        }
Exemple #10
0
        /// <summary>
        /// Evaluates the conditions of the rule
        /// </summary>
        /// <param name="sourceObject">The MAObject to evaluate</param>
        /// <param name="triggeringObject">The MAObject that is triggering the current evaluation event</param>
        /// <returns>A value indicating whether the rule's conditions were met</returns>
        public override bool Evaluate(MAObjectHologram sourceObject)
        {
            if (this.HasErrors)
            {
                throw new InvalidOperationException(string.Format("The EventRule '{0}' has the following errors that must be fixed:\n{1}", this.EventName, this.ErrorList.Select(t => string.Format("{0}: {1}", t.Key, t.Value)).ToNewLineSeparatedString()));
            }

            if (sourceObject.IncomingEvents == null)
            {
                this.RaiseRuleFailure(string.Format("The object had no incoming events"));
                return(false);
            }

            if (this.EventSource == null)
            {
                if (sourceObject.IncomingEvents.Any(t => t.EventID.Equals(this.EventName, StringComparison.CurrentCultureIgnoreCase)))
                {
                    return(true);
                }
                else
                {
                    this.RaiseRuleFailure("The event '{0}' was not present on the object", this.EventName);
                    return(false);
                }
            }
            else
            {
                AttributeValues sources = sourceObject.GetAttributeValues(this.EventSource);
                if (sourceObject.IncomingEvents.Any(t => t.EventID.Equals(this.EventName, StringComparison.CurrentCultureIgnoreCase) && sources.HasValue(t.Source.ObjectID)))
                {
                    return(true);
                }
                else
                {
                    this.RaiseRuleFailure("The event '{0}' from source {{{1}}} was not present on the object", this.EventName, this.EventSource.Name);
                    return(false);
                }
            }
        }