private static SdkMessageProcessingStep GetStepToRegister(Guid pluginTypeId, Model.Step step) { // Issue with CRM SDK / Description field max length = 256 characters var descriptionAttributeMaxLength = 256; var description = $"{step.PluginTypeName} : {step.Stage} {step.Message} of {step.EntityName} ({step.MethodsDisplayName})"; description = description.Length <= descriptionAttributeMaxLength ? description : description.Substring(0, descriptionAttributeMaxLength - 4) + "...)"; if (!string.IsNullOrEmpty(step.ImpersonationUsername)) { var count = _users.Count(u => u.Key == step.ImpersonationUsername); if (count == 0) { throw new Exception($"{description} : No user have fullname '{step.ImpersonationUsername}' in CRM."); } if (count > 1) { throw new Exception($"{description} : {count} users have the fullname '{step.ImpersonationUsername}' in CRM."); } } var t = new SdkMessageProcessingStep() { AsyncAutoDelete = step.Mode == Model.Modes.Asynchronous, Description = description, EventHandler = new EntityReference(PluginType.EntityLogicalName, pluginTypeId), FilteringAttributes = step.FilteringAttributes.Any() ? string.Join(",", step.FilteringAttributes) : null, ImpersonatingUserId = string.IsNullOrEmpty(step.ImpersonationUsername) ? null : new EntityReference("systemuser", _users.First(u => u.Key == step.ImpersonationUsername).Value), #pragma warning disable 0612 InvocationSource = new OptionSetValue((int)sdkmessageprocessingstep_invocationsource.Child), #pragma warning restore 0612 IsCustomizable = new BooleanManagedProperty(true), IsHidden = new BooleanManagedProperty(false), Mode = new OptionSetValue((int)step.Mode), Name = description, #pragma warning disable 0612 PluginTypeId = new EntityReference(PluginType.EntityLogicalName, pluginTypeId), #pragma warning restore 0612 Rank = step.Order, SdkMessageId = _messages[step.Message], //GetSdkMessageRef(service, step.Message), SdkMessageFilterId = _filters.Where(f => f.SdkMessageId.Name == step.Message && f.PrimaryObjectTypeCode == step.EntityName) .Select(f => f.ToEntityReference()).FirstOrDefault(), //GetSdkMessageFilterRef(service, step), //SdkMessageProcessingStepSecureConfigId = GetSdkMessageProcessingStepSecureConfigRef(service, step), Stage = new OptionSetValue((int)step.Stage), SupportedDeployment = new OptionSetValue((int)sdkmessageprocessingstep_supporteddeployment.ServerOnly), Configuration = step.UnsecureConfig }; return(t); }
private static SdkMessageProcessingStepImage GetImageToRegister(IOrganizationService service, Guid stepId, Model.Step step, bool isPreImage) { var isAllColumns = isPreImage ? step.PreImageAllAttributes : step.PostImageAllAttributes; var columns = isPreImage ? step.JoinedPreImageAttributes : step.JoinedPostImageAttributes; var name = isPreImage ? "PreImage" : "PostImage"; var messagePropertyName = "Target"; if (step.Message == Model.Messages.Create.ToString() && !isPreImage) { messagePropertyName = "Id"; } else if (step.Message == Model.Messages.SetState.ToString() || step.Message == Messages.SetStateDynamicEntity.ToString()) { messagePropertyName = "EntityMoniker"; } var t = new SdkMessageProcessingStepImage() { Attributes1 = isAllColumns ? null : columns, EntityAlias = name, ImageType = new OptionSetValue(isPreImage ? (int)sdkmessageprocessingstepimage_imagetype.PreImage : (int)sdkmessageprocessingstepimage_imagetype.PostImage), IsCustomizable = new BooleanManagedProperty(true), MessagePropertyName = messagePropertyName, Name = name, SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, stepId) }; return(t); }