private void CheckAggregation(XrmEntityPlugin plugin)
        {
            if (plugin.TargetType != RecordTypeAggregated)
            {
                return;
            }
            if (
                (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update ||
                 plugin.MessageName == PluginMessage.Delete) &&
                plugin.Stage == PluginStage.PostEvent &&
                plugin.Mode == PluginMode.Synchronous
                )
            {
                var isDependencyChanging = false;

                switch (plugin.MessageName)
                {
                case PluginMessage.Delete:
                {
                    isDependencyChanging = plugin.PreImageEntity.Contains(LookupName) &&
                                           plugin.MeetsConditionsChanging(Filters);
                    break;
                }

                case PluginMessage.Update:
                {
                    if (plugin.FieldChanging(LookupName) ||
                        (AggregatedField != null && plugin.FieldChanging(AggregatedField)) ||
                        (LinkEntity != null && plugin.FieldChanging(LinkEntity.LinkFromAttributeName)))
                    {
                        isDependencyChanging = true;
                    }
                    else
                    {
                        isDependencyChanging = plugin.MeetsConditionsChanging(Filters);
                    }
                    break;
                }

                case PluginMessage.Create:
                {
                    isDependencyChanging =
                        plugin.TargetEntity.Contains(LookupName) &&
                        (AggregatedField == null || plugin.TargetEntity.Contains(AggregatedField)) &&
                        plugin.MeetsConditionsChanging(Filters);
                    break;
                }
                }
                if (isDependencyChanging)
                {
                    object preImageLookup = plugin.PreImageEntity.GetLookupGuid(LookupName);
                    object contextLookup  = null;
                    if (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update)
                    {
                        contextLookup = plugin.TargetEntity.GetLookupGuid(LookupName);
                    }
                    var processPreImage    = false;
                    var processContextGuid = false;
                    //If they aren't the same do both
                    if (!XrmEntity.FieldsEqual(preImageLookup, contextLookup))
                    {
                        processPreImage    = true;
                        processContextGuid = true;
                    }
                    //else just do the first not null one
                    else
                    {
                        if (preImageLookup != null)
                        {
                            processPreImage = true;
                        }
                        else
                        {
                            processContextGuid = true;
                        }
                    }
                    if (processPreImage && preImageLookup != null)
                    {
                        RefreshAggregate((Guid)preImageLookup, plugin.XrmService, plugin.Controller);
                    }
                    if (processContextGuid && contextLookup != null)
                    {
                        RefreshAggregate((Guid)contextLookup, plugin.XrmService, plugin.Controller);
                    }
                }
            }
        }
        private void CheckAggregation(XrmEntityPlugin plugin)
        {
            if (plugin.TargetType != RecordTypeAggregated)
                return;
            if (
                (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update ||
                 plugin.MessageName == PluginMessage.Delete)
                && plugin.Stage == PluginStage.PostEvent
                && plugin.Mode == PluginMode.Synchronous
                )
            {
                var isDependencyChanging = false;

                switch (plugin.MessageName)
                {
                    case PluginMessage.Delete:
                        {
                            isDependencyChanging = plugin.PreImageEntity.Contains(LookupName) &&
                                                   plugin.MeetsConditionsChanging(Filters);
                            break;
                        }
                    case PluginMessage.Update:
                        {
                            if (plugin.FieldChanging(LookupName)
                                || (AggregatedField != null && plugin.FieldChanging(AggregatedField))
                                || (LinkEntity != null && plugin.FieldChanging(LinkEntity.LinkFromAttributeName)))
                                isDependencyChanging = true;
                            else
                                isDependencyChanging = plugin.MeetsConditionsChanging(Filters);
                            break;
                        }
                    case PluginMessage.Create:
                        {
                            isDependencyChanging =
                                plugin.TargetEntity.Contains(LookupName)
                                && (AggregatedField == null || plugin.TargetEntity.Contains(AggregatedField))
                                && plugin.MeetsConditionsChanging(Filters);
                            break;
                        }
                }

                if (isDependencyChanging)
                {
                    object preImageLookup = plugin.PreImageEntity.GetLookupGuid(LookupName);
                    object contextLookup = null;
                    if (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update)
                        contextLookup = plugin.TargetEntity.GetLookupGuid(LookupName);
                    var processPreImage = false;
                    var processContextGuid = false;
                    //If they aren't the same do both
                    if (!XrmEntity.FieldsEqual(preImageLookup, contextLookup))
                    {
                        processPreImage = true;
                        processContextGuid = true;
                    }
                    //else just do the first not null one
                    else
                    {
                        if (preImageLookup != null)
                            processPreImage = true;
                        else
                            processContextGuid = true;
                    }
                    if (processPreImage && preImageLookup != null)
                        RefreshAggregate((Guid)preImageLookup, plugin.XrmService, plugin.Controller);
                    if (processContextGuid && contextLookup != null)
                        RefreshAggregate((Guid)contextLookup, plugin.XrmService, plugin.Controller);
                }
            }
        }
示例#3
0
        private void ExecuteDependencyPluginRefresh(XrmEntityPlugin plugin, LookupRollup rollup)
        {
            var idsRequireRefresh = new List <Guid>();

            var isDependencyChanging = false;

            if (
                (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update ||
                 plugin.MessageName == PluginMessage.Delete) &&
                plugin.Stage == PluginStage.PostEvent &&
                plugin.Mode == PluginMode.Synchronous
                )
            {
                switch (plugin.MessageName)
                {
                case PluginMessage.Delete:
                {
                    isDependencyChanging = plugin.PreImageEntity.Contains(rollup.LookupName) &&
                                           plugin.MeetsConditionsChanging(rollup.Filters);
                    break;
                }

                case PluginMessage.Update:
                {
                    if (plugin.FieldChanging(rollup.LookupName) ||
                        (rollup.FieldRolledup != null && plugin.FieldChanging(rollup.FieldRolledup)) ||
                        (rollup.LinkEntity != null && plugin.FieldChanging(rollup.LinkEntity.LinkFromAttributeName)))
                    {
                        isDependencyChanging = true;
                    }
                    else
                    {
                        isDependencyChanging = plugin.MeetsConditionsChanging(rollup.Filters);
                    }
                    break;
                }

                case PluginMessage.Create:
                {
                    isDependencyChanging =
                        plugin.TargetEntity.Contains(rollup.LookupName) &&
                        (rollup.FieldRolledup == null || plugin.TargetEntity.Contains(rollup.FieldRolledup)) &&
                        plugin.MeetsConditionsChanging(rollup.Filters);
                    break;
                }
                }
                if (isDependencyChanging)
                {
                    object preImageLookup = plugin.PreImageEntity.GetLookupGuid(rollup.LookupName);
                    object contextLookup  = null;
                    if (plugin.MessageName == PluginMessage.Create || plugin.MessageName == PluginMessage.Update)
                    {
                        contextLookup = plugin.TargetEntity.GetLookupGuid(rollup.LookupName);
                    }
                    var processPreImage    = false;
                    var processContextGuid = false;
                    //If they aren't the same do both
                    if (!XrmEntity.FieldsEqual(preImageLookup, contextLookup))
                    {
                        processPreImage    = true;
                        processContextGuid = true;
                    }
                    //else just do the first not null one
                    else
                    {
                        if (preImageLookup != null)
                        {
                            processPreImage = true;
                        }
                        else
                        {
                            processContextGuid = true;
                        }
                    }
                    if (processPreImage && preImageLookup != null)
                    {
                        idsRequireRefresh.Add((Guid)preImageLookup);
                    }
                    if (processContextGuid && contextLookup != null)
                    {
                        idsRequireRefresh.Add((Guid)contextLookup);
                    }
                }
            }
            foreach (var id in idsRequireRefresh)
            {
                RefreshRollup(id, rollup);
            }
        }