コード例 #1
0
        private void ExecuteStep(Dictionary <string, object> inputParameters, int stage, string message, string primaryentityname, string logicalName, Guid id, bool isAsync, Action finalize, Action onDone)
        {
            var methods = this.pluginMethodCache.ForPlugin(this.plugin.GetType(), stage, message, logicalName, isAsync, false);

            if (methods.Length > 0)
            {
                if (inputParameters != null && inputParameters.Count > 0)
                {
                    var pluginExecutionContext = new Services.PluginExecutionContext(stage, 1, message, primaryentityname, id, isAsync);
                    foreach (var key in inputParameters.Keys)
                    {
                        pluginExecutionContext.InputParameters.Add(key, inputParameters[key]);
                    }

                    var serviceProvider = new Services.ServiceProvider(pluginExecutionContext, this, this.plugin.GetType().Assembly);
                    this.plugin.Execute(serviceProvider);
                    finalize?.Invoke();
                    onDone?.Invoke();
                }
            }
            else
            {
                if (onDone != null)
                {
                    throw new Exceptions.UnexpectedEventListenerException(plugin.GetType(), message, stage);
                }
                else
                {
                    finalize?.Invoke();
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target">The tarket entity</param>
        /// <param name="stage">10=validate,20=pre,40=post</param>
        /// <param name="message">Create,Update,Delete,??</param>
        /// <param name="isAsync">false or true, only apply to stage 40</param>
        /// <param name="finalize">Will be executed end of step, regardless of any plugin execution</param>
        /// <param name="onDone">the valide method provided by the test library</param>
        private void ExecuteStep(Microsoft.Xrm.Sdk.Entity target, int stage, string message, bool isAsync, Action finalize, Action onDone)
        {
            if (message != "Create" && stage == 10)
            {
                var key = target.LogicalName + target.Id.ToString();
                this.preImage = this.entities[key].Clone();
            }

            var methods = this.pluginMethodCache.ForPlugin(this.plugin.GetType(), stage, message, target.LogicalName, isAsync, false);

            if (methods.Length > 0)
            {
                var pluginExecutionContext = new Services.PluginExecutionContext(stage, 1, message, target.LogicalName, target.Id, isAsync);
                pluginExecutionContext.InputParameters.Add("Target", target);

                if (message != "Create")
                {
                    var imagePre = this.ResolveImage(target.LogicalName, target.Id, 1, methods, preImage);
                    if (imagePre != null)
                    {
                        var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(1, stage, isAsync);
                        pluginExecutionContext.PreEntityImages.Add(imgName, imagePre);
                    }
                }

                if (stage == 40 && message != "Delete")
                {
                    var imagePost = this.ResolveImage(target.LogicalName, target.Id, 2, methods, null);
                    if (imagePost != null)
                    {
                        var imgName = Kipon.Fake.Xrm.Reflection.PluginMethod.ImageSuffixFor(2, stage, isAsync);
                        pluginExecutionContext.PostEntityImages.Add(imgName, imagePost);
                    }
                }

                var serviceProvider = new Services.ServiceProvider(pluginExecutionContext, this, this.plugin.GetType().Assembly);
                this.plugin.Execute(serviceProvider);

                finalize?.Invoke();

                onDone?.Invoke();
            }
            else
            {
                if (onDone != null)
                {
                    throw new Exceptions.UnexpectedEventListenerException(plugin.GetType(), message, stage);
                }
                else
                {
                    finalize?.Invoke();
                }
            }
        }