private async Task RegisterSingleStep(StringBuilder log, SdkMessageRepository repositoryMessage, SdkMessageFilterRepository repositoryFilter, SystemUserRepository repositorySystemUser, Entities.PluginType entPluginType, Model.Backup.PluginStep step)
        {
            var entMessage = await repositoryMessage.FindMessageAsync(step.Message);

            if (entMessage == null)
            {
                log.AppendFormat("Message {0} not founded in CRM.", step.Message).AppendLine();
                return;
            }

            var refMessageFilter = await repositoryFilter.FindFilterAsync(entMessage.Id, step.PrimaryEntity, step.SecondaryEntity);

            EntityReference refSecure     = null;
            EntityReference refSystemUser = null;

            if (!string.IsNullOrEmpty(step.SecureConfiguration))
            {
                var entSecure = new Entity(Entities.SdkMessageProcessingStepSecureConfig.EntityLogicalName);
                entSecure.Attributes[Entities.SdkMessageProcessingStepSecureConfig.Schema.Attributes.secureconfig] = step.SecureConfiguration;

                entSecure.Id = await _service.CreateAsync(entSecure);

                refSecure = entSecure.ToEntityReference();
            }

            if (!string.IsNullOrEmpty(step.RunInUserContext) && step.RunInUserContext != "Calling User")
            {
                refSystemUser = repositorySystemUser.FindUser(step.RunInUserContext);
            }

            var entStep = new Entity(Entities.SdkMessageProcessingStep.EntityLogicalName)
            {
                Id = step.Id
            };

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.asyncautodelete] = step.AsyncAutoDelete.GetValueOrDefault();
            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.name]            = step.Name;
            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.description]     = step.Description;
            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.rank]            = step.ExecutionOrder;

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.stage] = new OptionSetValue((int)step.Stage);
            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.mode]  = new OptionSetValue((int)step.ExecutionMode);

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.supporteddeployment] = new OptionSetValue((int)step.SupportedDeploymentCode);

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.configuration] = step.UnsecureConfiguration;

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.filteringattributes] = string.Join(",", step.FilteringAttributes.OrderBy(s => s));

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.plugintypeid] = entPluginType.ToEntityReference();

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.eventhandler] = entPluginType.ToEntityReference();

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.sdkmessageid] = entMessage.ToEntityReference();

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.sdkmessagefilterid] = refMessageFilter;

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.sdkmessageprocessingstepsecureconfigid] = refSecure;

            entStep.Attributes[Entities.SdkMessageProcessingStep.Schema.Attributes.impersonatinguserid] = refSystemUser;

            entStep.Id = await _service.CreateAsync(entStep);

            foreach (var image in step.PluginImages)
            {
                var entImage = new Entity(Entities.SdkMessageProcessingStepImage.EntityLogicalName)
                {
                    Id = image.Id
                };

                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.sdkmessageprocessingstepid] = entStep.ToEntityReference();

                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.imagetype] = new OptionSetValue(image.ImageType.Value);

                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.name]        = image.Name;
                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.entityalias] = image.EntityAlias;

                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.customizationlevel]   = image.CustomizationLevel;
                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.relatedattributename] = image.RelatedAttributeName;
                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.messagepropertyname]  = image.MessagePropertyName;

                entImage.Attributes[Entities.SdkMessageProcessingStepImage.Schema.Attributes.attributes] = string.Join(",", image.Attributes.OrderBy(s => s));

                entImage.Id = await _service.CreateAsync(entImage);
            }

            _service.Execute(new SetStateRequest()
            {
                EntityMoniker = entStep.ToEntityReference(),

                State  = new OptionSetValue(step.StateCode.Value),
                Status = new OptionSetValue(step.StatusCode.Value),
            });
        }