private void Update(Models.Plugin plugin, Models.Step step, Entities.SdkMessageProcessingStep crmStep)
        {
            var updated = false;
            var clean   = new Entities.SdkMessageProcessingStep
            {
                SdkMessageProcessingStepId = crmStep.SdkMessageProcessingStepId
            };

            if (crmStep.FilteringAttributes != null && step.FilteringAttributesString == null)
            {
                clean.FilteringAttributes = null;
                updated = true;
            }

            if (step.FilteringAttributesString != null && step.FilteringAttributesString != crmStep.FilteringAttributes)
            {
                clean.FilteringAttributes = step.FilteringAttributesString;
                updated = true;
            }

            if (updated)
            {
                uow.Update(clean);
                this.messageService.Inform($"Updated step {crmStep.Name} on {crmStep.LogicalName}.");
            }

            this.UpdateImage(crmStep, 1, step.Stage, step.IsAsync, step.Message, step.PreImage);
            this.UpdateImage(crmStep, 2, step.Stage, step.IsAsync, step.Message, step.PostImage);
        }
        private Entities.SdkMessageProcessingStep Create(Models.Plugin plugin, Models.Step step, string name)
        {
            var next = new Entities.SdkMessageProcessingStep
            {
                SdkMessageProcessingStepId = Guid.NewGuid(),
                Name  = name,
                Mode  = step.IsAsync ? new Microsoft.Xrm.Sdk.OptionSetValue(1) : new Microsoft.Xrm.Sdk.OptionSetValue(0),
                Rank  = step.ExecutionOrder <= 0 ? 1 : step.ExecutionOrder,
                Stage = new Microsoft.Xrm.Sdk.OptionSetValue(step.Stage),
                SupportedDeployment = new Microsoft.Xrm.Sdk.OptionSetValue(0),
                EventHandler        = new Microsoft.Xrm.Sdk.EntityReference(Entities.PluginType.EntityLogicalName, plugin.CurrentCrmInstance.PluginTypeId.Value),
                SdkMessageId        = this.GetSdkMessage(step.Message).ToEntityReference(),
                SdkMessageFilterId  = this.GetFilterFor(this.GetSdkMessage(step.Message), step.PrimaryEntityLogicalName)
            };

            if (next.Mode.Value == 1)
            {
                next.AsyncAutoDelete = true;
            }

            if (step.FilteringAttributes != null && step.FilteringAttributes.Length > 0)
            {
                next.FilteringAttributes = string.Join(",", step.FilteringAttributes);
            }

            uow.Create(next);
            this.messageService.Inform($"Created step: {next.Name}");

            if (step.PreImage != null)
            {
                CreateImage(next, 1, step.Stage, step.IsAsync, step.Message, step.PreImage);
            }

            if (step.PostImage != null)
            {
                CreateImage(next, 2, step.Stage, step.IsAsync, step.Message, step.PostImage);
            }
            return(next);
        }