Ejemplo n.º 1
0
        public override void OnModify(DbPropertyValues originalValues, DbPropertyValues currentValues)
        {
            base.OnModify(originalValues, currentValues);

            var reflectionHelper     = new ReflectionHelper <IncidentDO>();
            var priorityPropertyName = reflectionHelper.GetPropertyName(i => i.Priority);

            if (!MiscUtils.AreEqual(originalValues[priorityPropertyName], currentValues[priorityPropertyName]) &&
                IsHighPriority)
            {
                EventManager.HighPriorityIncidentCreated(Id);
            }
        }
Ejemplo n.º 2
0
        public override void OnModify(DbPropertyValues originalValues, DbPropertyValues currentValues)
        {
            base.OnModify(originalValues, currentValues);

            var reflectionHelper  = new ReflectionHelper <BookingRequestDO>();
            var statePropertyName = reflectionHelper.GetPropertyName(br => br.State);

            if (!MiscUtils.AreEqual(originalValues[statePropertyName], currentValues[statePropertyName]))
            {
                var state = (int)currentValues[statePropertyName];
                switch (state)
                {
                case BookingRequestState.NeedsBooking:
                    AlertManager.BookingRequestNeedsProcessing(Id);
                    break;

                case BookingRequestState.Resolved:
                    AlertManager.BookingRequestMarkedProcessed(Id, BookerID);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Detects any updates on specified entity and tracks them via AlertManager.TrackablePropertyUpdated alert.
        /// </summary>
        /// <param name="entity">entity</param>
        /// <param name="originalValues">original properties values</param>
        /// <param name="currentValues">current properties values</param>
        /// <param name="properties">properties to track</param>
        /// <param name="updateCallback">action to call when update is detected. If it is null it defaults to AlertManager.TrackablePropertyChanged.</param>
        /// <remarks>
        /// This method would likely be called from <see cref="IModifyHook.OnModify">OnModify</see> implementation to track properties.
        /// For tracking enum typed (state) properties see <see cref="DetectStateUpdates">DetectStateUpdates</see> method.
        /// </remarks>
        public static void DetectUpdates(this IBaseDO entity,
                                         DbPropertyValues originalValues, DbPropertyValues currentValues, PropertyInfo[] properties,
                                         Action <string, object, PropertyInfo> updateCallback = null)
        {
            if (properties == null || properties.Length == 0)
            {
                return;
            }
            if (updateCallback == null)
            {
                updateCallback =
                    (entityName, idValue, property) =>
                    EventManager.TrackablePropertyUpdated(entityName, property.Name, idValue, currentValues[property.Name]);
            }
            var type       = entity.GetType();
            var idProperty = type.GetProperty("Id");
            var id         = idProperty != null?idProperty.GetValue(entity) : null;

            foreach (var property in properties)
            {
                if (!MiscUtils.AreEqual(originalValues[property.Name], currentValues[property.Name]))
                {
                    string entityName;
                    if (type.Name.EndsWith("DO", StringComparison.Ordinal))
                    {
                        entityName = type.Name.Remove(type.Name.Length - 2);
                    }
                    else if (type.BaseType != null && type.BaseType.Name.EndsWith("DO", StringComparison.Ordinal))
                    {
                        entityName = type.BaseType.Name.Remove(type.BaseType.Name.Length - 2);
                    }
                    else
                    {
                        entityName = type.Name;
                    }
                    updateCallback(entityName, id, property);
                }
            }
        }