public void CreateAsyncPluginAttributeCode() { var attribute = new CrmPluginRegistrationAttribute( MessageNameEnum.Update, "account", StageEnum.PostOperation, ExecutionModeEnum.Asynchronous, "name,address1_line1", "Delete of account", 1, IsolationModeEnum.Sandbox) { Image1Name = "PreImage", Image1Attributes = "name,address1_line1", Image1Type = ImageTypeEnum.PreImage, Image2Name = "PostImage", Image2Attributes = "name,address1_line1", Image2Type = ImageTypeEnum.PostImage, DeleteAsyncOperation = true }; var code = attribute.GetAttributeCode(""); Debug.WriteLine(code); Assert.AreEqual(Normalise("[CrmPluginRegistration(\"Update\",\"account\",StageEnum.PostOperation,ExecutionModeEnum.Asynchronous,\"name, address1_line1\",\"Deleteofaccount\",1,IsolationModeEnum.Sandbox,Image1Type=ImageTypeEnum.PreImage,Image1Name=\"PreImage\",Image1Attributes=\"name, address1_line1\",Image2Type=ImageTypeEnum.PostImage,Image2Name=\"PostImage\",Image2Attributes=\"name, address1_line1\",DeleteAsyncOperation = True)]"), Normalise(code)); }
public void AddAttribute(CrmPluginRegistrationAttribute attribute, string className) { // Locate the start of the class and add the attribute above var classLocation = _pluginClasses.ContainsKey(className) ? _pluginClasses[className] : null; if (classLocation == null) { throw new Exception(String.Format("Cannot find class {0}", className)); } var pos = _code.IndexOf(classLocation.Value); // Find previouse line break var lineBreak = _code.LastIndexOf("\r\n", pos - 1); // Indentation var indentation = _code.Substring(lineBreak, pos - lineBreak); // Add the attribute var attributeCode = attribute.GetAttributeCode(indentation); // Insert _code = _code.Insert(lineBreak, attributeCode); }
private SdkMessageProcessingStepImage RegisterImage(CrmPluginRegistrationAttribute stepAttribute, SdkMessageProcessingStep step, SdkMessageProcessingStepImage[] existingImages, string imageName, ImageTypeEnum imagetype, string attributes) { if (String.IsNullOrWhiteSpace(imageName)) { return(null); } var image = existingImages.Where(a => a.SdkMessageProcessingStepId.Id == step.Id && a.EntityAlias == imageName && a.ImageType.Value == (int)imagetype).FirstOrDefault(); if (image == null) { image = new SdkMessageProcessingStepImage(); } image.Name = imageName; image.ImageType = new OptionSetValue((int)imagetype); image.SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, step.Id); image.Attributes1 = attributes; image.EntityAlias = imageName; image.MessagePropertyName = stepAttribute.Message == "Create" ? "Id" : "Target"; if (image.Id == Guid.Empty) { _trace.WriteLine("Registering Image '{0}'", image.Name); image.Id = _service.Create(image); } else { _trace.WriteLine("Updating Image '{0}'", image.Name); _ctx.UpdateObject(image); } return(image); }
/// <summary> /// Reads the CustomAttributeData to create a CrmPluginRegistrationAttribute object to use as a /// data object for settings on how a plugin is registered. /// </summary> /// <param name="data">The CustomAttributeData</param> /// <returns>CrmPluginRegistrationAttribute</returns> /// <remarks>Taken from Scott Durrow's spkl sourcecode: spkl/SparkleXrm.Tasks/CustomAttributeDataEx.cs - CreateFromData</remarks> public static CrmPluginRegistrationAttribute CreateRegistrationAttributeFromData(this CustomAttributeData data) { CrmPluginRegistrationAttribute attribute; var arguments = data.ConstructorArguments.ToArray(); // determine which constructor is being used by the first type if (data.ConstructorArguments.Count == 8 && data.ConstructorArguments[0].ArgumentType.Name == "String") { attribute = new CrmPluginRegistrationAttribute( (string)arguments[0].Value, (string)arguments[1].Value, (StageEnum)Enum.ToObject(typeof(StageEnum), (int)arguments[2].Value), (ExecutionModeEnum)Enum.ToObject(typeof(ExecutionModeEnum), (int)arguments[3].Value), (string)arguments[4].Value, (string)arguments[5].Value, (int)arguments[6].Value, (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)arguments[7].Value) ); } else if (data.ConstructorArguments.Count == 8 && data.ConstructorArguments[0].ArgumentType.Name == "MessageNameEnum") { attribute = new CrmPluginRegistrationAttribute( (MessageNameEnum)Enum.ToObject(typeof(MessageNameEnum), (int)arguments[0].Value), (string)arguments[1].Value, (StageEnum)Enum.ToObject(typeof(StageEnum), (int)arguments[2].Value), (ExecutionModeEnum)Enum.ToObject(typeof(ExecutionModeEnum), (int)arguments[3].Value), (string)arguments[4].Value, (string)arguments[5].Value, (int)arguments[6].Value, (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)arguments[7].Value) ); } else if (data.ConstructorArguments.Count == 5 && data.ConstructorArguments[0].ArgumentType.Name == "String") { attribute = new CrmPluginRegistrationAttribute( (string)arguments[0].Value, (string)arguments[1].Value, (string)arguments[2].Value, (string)arguments[3].Value, (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)arguments[4].Value) ); } else { return(null); } if (data.NamedArguments == null) { return(attribute); } foreach (var namedArgument in data.NamedArguments) { switch (namedArgument.MemberName) { case "Id": attribute.Id = (string)namedArgument.TypedValue.Value; break; case "FriendlyName": attribute.FriendlyName = (string)namedArgument.TypedValue.Value; break; case "GroupName": attribute.FriendlyName = (string)namedArgument.TypedValue.Value; break; case "Image1Name": attribute.Image1Name = (string)namedArgument.TypedValue.Value; break; case "Image1Attributes": attribute.Image1Attributes = (string)namedArgument.TypedValue.Value; break; case "Image2Name": attribute.Image2Name = (string)namedArgument.TypedValue.Value; break; case "Image2Attributes": attribute.Image2Attributes = (string)namedArgument.TypedValue.Value; break; case "Image1Type": attribute.Image1Type = (ImageTypeEnum)namedArgument.TypedValue.Value; break; case "Image2Type": attribute.Image2Type = (ImageTypeEnum)namedArgument.TypedValue.Value; break; case "Description": attribute.Description = (string)namedArgument.TypedValue.Value; break; case "DeleteAsyncOperaton": attribute.DeleteAsyncOperaton = (bool)namedArgument.TypedValue.Value; break; case "UnSecureConfiguration": attribute.UnSecureConfiguration = (string)namedArgument.TypedValue.Value; break; case "SecureConfiguration": attribute.SecureConfiguration = (string)namedArgument.TypedValue.Value; break; case "Offline": attribute.Offline = (bool)namedArgument.TypedValue.Value; break; case "Server": attribute.Server = (bool)namedArgument.TypedValue.Value; break; case "Action": attribute.Action = (PluginStepOperationEnum)namedArgument.TypedValue.Value; break; } } return(attribute); }
private void RegisterStep(PluginType sdkPluginType, List <SdkMessageProcessingStep> existingSteps, CrmPluginRegistrationAttribute pluginStep) { SdkMessageProcessingStep step = null; Guid stepId = Guid.Empty; if (pluginStep.Id != null) { stepId = new Guid(pluginStep.Id); // Get by ID step = existingSteps.Where(s => s.Id == stepId).FirstOrDefault(); } if (step == null) { // Get by Name step = existingSteps.Where(s => s.Name == pluginStep.Name && s.SdkMessageId.Name == pluginStep.Message).FirstOrDefault(); } // Register images if (step == null) { step = new SdkMessageProcessingStep(); } Guid?sdkMessageId = null; Guid?sdkMessagefilterId = null; if (pluginStep.EntityLogicalName == "none") { var message = ServiceLocator.Queries.GetMessage(_ctx, pluginStep.Message); sdkMessageId = message.SdkMessageId; } else { var messageFilter = ServiceLocator.Queries.GetMessageFilter(_ctx, pluginStep.EntityLogicalName, pluginStep.Message); if (messageFilter == null) { _trace.WriteLine("Warning: Cannot register step {0} on Entity {1}", pluginStep.Message, pluginStep.EntityLogicalName); return; } sdkMessageId = messageFilter.SdkMessageId.Id; sdkMessagefilterId = messageFilter.SdkMessageFilterId; } // Update attributes step.Name = pluginStep.Name; step.Configuration = pluginStep.UnSecureConfiguration; step.Description = pluginStep.Description; step.Mode = pluginStep.ExecutionMode == ExecutionModeEnum.Asynchronous ? sdkmessageprocessingstep_mode.Asynchronous : sdkmessageprocessingstep_mode.Synchronous; if (pluginStep.ExecutionMode == ExecutionModeEnum.Asynchronous) { step.AsyncAutoDelete = pluginStep.DeleteAsyncOperation; } else if (step.Attributes.ContainsKey("asyncautodelete")) { // If the attribute was set previously because we used to have an async step, reset it step.AsyncAutoDelete = false; } step.Rank = pluginStep.ExecutionOrder; int stage = 10; switch (pluginStep.Stage) { case StageEnum.PreValidation: stage = 10; break; case StageEnum.PreOperation: stage = 20; break; case StageEnum.PostOperation: stage = 40; break; } step.Stage = (sdkmessageprocessingstep_stage)stage; int supportDeployment = 0; if (pluginStep.Server == true && pluginStep.Offline == true) { supportDeployment = 2; // Both } else if (!pluginStep.Server == true && pluginStep.Offline == true) { supportDeployment = 1; // Offline only } else { supportDeployment = 0; // Server Only } step.SupportedDeployment = (sdkmessageprocessingstep_supporteddeployment)supportDeployment; step.PluginTypeId = sdkPluginType.ToEntityReference(); step.SdkMessageFilterId = sdkMessagefilterId != null ? new EntityReference(SdkMessageFilter.EntityLogicalName, sdkMessagefilterId.Value) : null; step.SdkMessageId = new EntityReference(SdkMessage.EntityLogicalName, sdkMessageId.Value); step.FilteringAttributes = normaliseCommaSeparatedString(pluginStep.FilteringAttributes); if (step.Id == Guid.Empty) { _trace.WriteLine("Registering Step '{0}'", step.Name); if (stepId != Guid.Empty) { step.Id = stepId; } // Create step.Id = _service.Create(step); } else { _trace.WriteLine("Updating Step '{0}'", step.Name); // Update _service.Update(step); existingSteps.Remove(step); } // Get existing Images List <SdkMessageProcessingStepImage> existingImages = ServiceLocator.Queries.GetPluginStepImages(_ctx, step); var image1 = RegisterImage(pluginStep, step, existingImages, pluginStep.Image1Name, pluginStep.Image1Type, pluginStep.Image1Attributes); var image2 = RegisterImage(pluginStep, step, existingImages, pluginStep.Image2Name, pluginStep.Image2Type, pluginStep.Image2Attributes); // Remove Images no longer being registered foreach (var image in existingImages) { _trace.WriteLine("Deleting Image {0}", image.Name); _service.Delete(SdkMessageProcessingStepImage.EntityLogicalName, image.Id); } if (SolutionUniqueName != null) { AddStepToSolution(SolutionUniqueName, step); } }
private void RegisterCustomApi(PluginType sdkPluginType, List <SdkMessageProcessingStep> existingSteps, CrmPluginRegistrationAttribute attribute) { // Register against a Custom Api // Check it exists using the unqiue message name var existingApi = (from s in _ctx.CreateQuery <CustomAPI>() where s.UniqueName == attribute.Message select new CustomAPI() { Id = s.Id, PluginTypeId = s.PluginTypeId }).ToList(); if (existingApi.Count > 0) { // Update Api Registration if it's a different type Id or null var customApi = existingApi.First(); if (customApi.PluginTypeId?.Id != sdkPluginType.Id) { customApi.PluginTypeId = sdkPluginType.ToEntityReference(); _service.Update(customApi); _trace.WriteLine($"Registered Plugin Type {sdkPluginType.Id} against Custom Api '{attribute.Message}'"); } else { _trace.WriteLine($"Plugin Type {sdkPluginType.Id} is already registered against Custom Api '{attribute.Message}'"); } } else { _trace.WriteLine($"Warning: Cannot find custom api with UniqueName '{attribute.Message}'"); } }
public static CrmPluginRegistrationAttribute CreateFromData(this CustomAttributeData data) { var attribute = new CrmPluginRegistrationAttribute(); var arguments = data.ConstructorArguments.ToArray(); var hasNamedArgumentPluginType = false; var isCodeActivity = false; var isPlugin = false; if (arguments.Length == 8) { attribute.Message = (string)arguments[0].Value; attribute.EntityLogicalName = (string)arguments[1].Value; attribute.Stage = (StageEnum)Enum.ToObject(typeof(StageEnum), (int)arguments[2].Value); attribute.ExecutionMode = (ExecutionModeEnum)Enum.ToObject(typeof(ExecutionModeEnum), (int)arguments[3].Value); attribute.FilteringAttributes = (string)arguments[4].Value; attribute.Name = (string)arguments[5].Value; attribute.ExecutionOrder = (int)arguments[6].Value; attribute.IsolationMode = (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)arguments[7].Value); isPlugin = true; } else if (arguments.Length == 5) { attribute.Name = (string)arguments[0].Value; attribute.FriendlyName = (string)arguments[1].Value; attribute.Description = (string)arguments[2].Value; attribute.GroupName = (string)arguments[3].Value; attribute.IsolationMode = (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)arguments[4].Value); isCodeActivity = true; } else if (arguments.Length == 3) { attribute.Name = (string)arguments[0].Value; attribute.Message = (string)arguments[1].Value; attribute.PluginType = (PluginType)Enum.ToObject(typeof(PluginType), (int)arguments[2].Value); } foreach (var namedArgument in data.NamedArguments) { switch (namedArgument.MemberName) { case "RunAs": attribute.RunAs = (string)namedArgument.TypedValue.Value; break; case "FriendlyName": attribute.FriendlyName = (string)namedArgument.TypedValue.Value; break; case "GroupName": attribute.GroupName = (string)namedArgument.TypedValue.Value; break; case "Description": attribute.Description = (string)namedArgument.TypedValue.Value; break; case "DeleteAsyncOperation": attribute.DeleteAsyncOperation = (bool)namedArgument.TypedValue.Value; break; case "Offline": attribute.Offline = (bool)namedArgument.TypedValue.Value; break; case "Server": attribute.Server = (bool)namedArgument.TypedValue.Value; break; case "Action": attribute.Action = (PluginStepOperationEnum)Enum.ToObject(typeof(PluginStepOperationEnum), (int)namedArgument.TypedValue.Value); break; case "IsolationMode": attribute.IsolationMode = (IsolationModeEnum)Enum.ToObject(typeof(IsolationModeEnum), (int)namedArgument.TypedValue.Value); break; case "Message": attribute.Message = (string)namedArgument.TypedValue.Value; break; case "EntityLogicalName": attribute.EntityLogicalName = (string)namedArgument.TypedValue.Value; break; case "FilteringAttributes": attribute.FilteringAttributes = (string)namedArgument.TypedValue.Value; break; case "Name": attribute.Name = (string)namedArgument.TypedValue.Value; break; case "ExecutionOrder": attribute.ExecutionOrder = (int)namedArgument.TypedValue.Value; break; case "Stage": attribute.Stage = (StageEnum)Enum.ToObject(typeof(StageEnum), (int)namedArgument.TypedValue.Value); break; case "ExecutionMode": attribute.ExecutionMode = (ExecutionModeEnum)Enum.ToObject(typeof(ExecutionModeEnum), (int)namedArgument.TypedValue.Value); break; case "UnSecureConfiguration": attribute.UnSecureConfiguration = (string)namedArgument.TypedValue.Value; break; case "SecureConfiguration": attribute.SecureConfiguration = (string)namedArgument.TypedValue.Value; break; case "Image1Name": attribute.Image1Name = (string)namedArgument.TypedValue.Value; break; case "Image1Alias": attribute.Image1Alias = (string)namedArgument.TypedValue.Value; break; case "Image1Type": attribute.Image1Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), (int)namedArgument.TypedValue.Value); break; case "Image1Attributes": attribute.Image1Attributes = (string)namedArgument.TypedValue.Value; break; case "Image2Name": attribute.Image2Name = (string)namedArgument.TypedValue.Value; break; case "Image2Alias": attribute.Image2Alias = (string)namedArgument.TypedValue.Value; break; case "Image2Type": attribute.Image2Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), (int)namedArgument.TypedValue.Value); break; case "Image2Attributes": attribute.Image2Attributes = (string)namedArgument.TypedValue.Value; break; case "Image3Name": attribute.Image3Name = (string)namedArgument.TypedValue.Value; break; case "Image3Alias": attribute.Image3Alias = (string)namedArgument.TypedValue.Value; break; case "Image3Type": attribute.Image3Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), (int)namedArgument.TypedValue.Value); break; case "Image3Attributes": attribute.Image3Attributes = (string)namedArgument.TypedValue.Value; break; case "Image4Name": attribute.Image4Name = (string)namedArgument.TypedValue.Value; break; case "Image4Alias": attribute.Image4Alias = (string)namedArgument.TypedValue.Value; break; case "Image4Type": attribute.Image4Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), (int)namedArgument.TypedValue.Value); break; case "Image4Attributes": attribute.Image4Attributes = (string)namedArgument.TypedValue.Value; break; case "PluginType": hasNamedArgumentPluginType = true; attribute.PluginType = (PluginType)Enum.ToObject(typeof(PluginType), (int)namedArgument.TypedValue.Value); break; case "DataSource": attribute.DataSource = (string)namedArgument.TypedValue.Value; break; } } if (!hasNamedArgumentPluginType) { if (isCodeActivity || attribute.GroupName.Length > 0) { attribute.PluginType = PluginType.Workflow; } if (isPlugin) { attribute.PluginType = PluginType.Plugin; } if (isPlugin && attribute.EntityLogicalName?.ToLower() == "none") { attribute.PluginType = PluginType.CustomAction; } } return(attribute); }
private void AddPluginAttributes(OrganizationServiceContext ctx, CodeParser parser, string pluginType) { // Get existing Steps var steps = ctx.GetPluginSteps(pluginType); // Check that there are no duplicates var duplicateNames = steps.GroupBy(s => s.Name).SelectMany(grp => grp.Skip(1)); if (duplicateNames.Count() > 0) { throw new SparkleTaskException(SparkleTaskException.ExceptionTypes.DUPLICATE_STEP, String.Format("More than one step found with the same name for plugin type {0} - {1}", pluginType, string.Join(",", duplicateNames.Select(a => a.Name)))); } if (steps != null) { _trace.WriteLine("Found Plugin Type Registration {0}", pluginType); // Get the steps foreach (var step in steps) { SdkMessageFilter filter = null; // If there is an entity filter then get it if (step.SdkMessageFilterId != null) { filter = ctx.GetMessageFilter(step.SdkMessageFilterId.Id); } // Get the images SdkMessageProcessingStepImage[] images = ctx.GetPluginStepImages(step); // Only support two images - Why would you need more?! if (images.Length > 2) { throw new Exception(String.Format("More than 2 images found on step {0}", step.Name)); } // Create attribute // we output the ID so that we can be independant of name - but it's not neededed for new attributes CrmPluginRegistrationAttribute attribute = new CrmPluginRegistrationAttribute( step.sdkmessageid_sdkmessageprocessingstep.Name, filter == null ? "none" : filter.PrimaryObjectTypeCode, (StageEnum)Enum.ToObject(typeof(StageEnum), step.Stage.Value), step.Mode.Value == 0 ? ExecutionModeEnum.Synchronous : ExecutionModeEnum.Asynchronous, step.FilteringAttributes, step.Name, step.Rank.HasValue ? step.Rank.Value : 1, step.plugintypeid_sdkmessageprocessingstep.pluginassembly_plugintype.IsolationMode.Value == 2 ? IsolationModeEnum.Sandbox : IsolationModeEnum.None ) { Id = step.Id.ToString() }; // Image 1 if (images.Length >= 1) { var image = images[0]; attribute.Image1Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), image.ImageType.Value); attribute.Image1Name = image.EntityAlias; attribute.Image1Attributes = image.Attributes1; } // Image 2 if (images.Length >= 2) { var image = images[1]; attribute.Image2Type = (ImageTypeEnum)Enum.ToObject(typeof(ImageTypeEnum), image.ImageType.Value); attribute.Image2Name = image.EntityAlias; attribute.Image2Attributes = image.Attributes1; } // Add config if (step.Configuration != null) { attribute.UnSecureConfiguration = step.Configuration; } if (step.Description != null) { attribute.Description = step.Description; } // Add attribute to code parser.AddAttribute(attribute, step.plugintypeid_sdkmessageprocessingstep.TypeName); } } }
private void RegisterStep(PluginType sdkPluginType, IEnumerable <SdkMessageProcessingStep> existingSteps, CrmPluginRegistrationAttribute pluginStep) { SdkMessageProcessingStep step = null; if (pluginStep.Id != null) { Guid stepId = new Guid(pluginStep.Id); // Get by ID step = existingSteps.Where(s => s.Id == stepId).FirstOrDefault(); } if (step == null) { // Get by Name step = existingSteps.Where(s => s.Name == pluginStep.Name && s.SdkMessageId.Name == pluginStep.Message).FirstOrDefault(); } // Register images if (step == null) { step = new SdkMessageProcessingStep(); } Guid?sdkMessageId = null; Guid?sdkMessagefilterId = null; if (pluginStep.EntityLogicalName == "none") { var message = _ctx.GetMessage(pluginStep.Message); sdkMessageId = message.SdkMessageId; } else { var messageFilter = _ctx.GetMessageFilter(pluginStep.EntityLogicalName, pluginStep.Message); if (messageFilter == null) { _trace.WriteLine("Warning: Cannot register step {0} on Entity {1}", pluginStep.Message, pluginStep.EntityLogicalName); return; } sdkMessageId = messageFilter.SdkMessageId.Id; sdkMessagefilterId = messageFilter.SdkMessageFilterId; } // Update attributes step.Name = pluginStep.Name; step.Configuration = pluginStep.UnSecureConfiguration; step.Description = pluginStep.Description; step.Mode = new OptionSetValue(pluginStep.ExecutionMode == ExecutionModeEnum.Asynchronous ? 1 : 0); step.Rank = pluginStep.ExecutionOrder; int stage = 10; switch (pluginStep.Stage) { case StageEnum.PreValidation: stage = 10; break; case StageEnum.PreOperation: stage = 20; break; case StageEnum.PostOperation: stage = 40; break; } step.Stage = new OptionSetValue(stage); int supportDeployment = 0; if (pluginStep.Server == true && pluginStep.Offline == true) { supportDeployment = 2; // Both } else if (!pluginStep.Server == true && pluginStep.Offline == true) { supportDeployment = 1; // Offline only } else { supportDeployment = 0; // Server Only } step.SupportedDeployment = new OptionSetValue(supportDeployment); step.PluginTypeId = sdkPluginType.ToEntityReference(); step.SdkMessageFilterId = sdkMessagefilterId != null ? new EntityReference(SdkMessageFilter.EntityLogicalName, sdkMessagefilterId.Value) : null; step.SdkMessageId = new EntityReference(SdkMessage.EntityLogicalName, sdkMessageId.Value); step.FilteringAttributes = pluginStep.FilteringAttributes; if (step.Id == Guid.Empty) { _trace.WriteLine("Registering Step '{0}'", step.Name); // Create step.Id = _service.Create(step); } else { _trace.WriteLine("Updating Step '{0}'", step.Name); // Update _ctx.UpdateObject(step); } // Get existing Images SdkMessageProcessingStepImage[] existingImages = _ctx.GetPluginStepImages(step); var image1 = RegisterImage(pluginStep, step, existingImages, pluginStep.Image1Name, pluginStep.Image1Type, pluginStep.Image1Attributes); var image2 = RegisterImage(pluginStep, step, existingImages, pluginStep.Image2Name, pluginStep.Image2Type, pluginStep.Image2Attributes); if (SolutionUniqueName != null) { AddStepToSolution(SolutionUniqueName, step); } }
public static string GetAttributeCode(this CrmPluginRegistrationAttribute attribute, string indentation) { var code = string.Empty; var targetType = (attribute.Stage != null) ? TargetType.Plugin : TargetType.WorkflowAcitivty; string additionalParmeters = ""; // Image 1 if (attribute.Image1Name != null) { additionalParmeters += ",Image1Type = ImageTypeEnum." + attribute.Image1Type; } if (attribute.Image1Name != null) { additionalParmeters += ",Image1Name = \"" + attribute.Image1Name + "\""; } if (attribute.Image1Name != null) { additionalParmeters += ",Image1Attributes = \"" + attribute.Image1Attributes + "\""; } // Image 2 if (attribute.Image2Name != null) { additionalParmeters += ",Image2Type = ImageTypeEnum." + attribute.Image2Type; } if (attribute.Image2Name != null) { additionalParmeters += ",Image2Name = \"" + attribute.Image2Name + "\""; } if (attribute.Image2Attributes != null) { additionalParmeters += ",Image2Attributes = \"" + attribute.Image2Attributes + "\""; } if (targetType == TargetType.Plugin) { // Description is only option for plugins if (attribute.Description != null) { additionalParmeters += ",Description = \"" + attribute.Description + "\""; } if (attribute.Offline) { additionalParmeters += ",Offline = " + attribute.Offline; } if (!attribute.Server) { additionalParmeters += ",Server = " + attribute.Server; } } if (attribute.Id != null) { additionalParmeters += ",Id = \"" + attribute.Id + "\""; } if (attribute.DeleteAsyncOperaton != null) { additionalParmeters += ",DeleteAsyncOperaton = " + attribute.DeleteAsyncOperaton; } if (attribute.UnSecureConfiguration != null) { additionalParmeters += ",UnSecureConfiguration = \"" + attribute.UnSecureConfiguration + "\""; } if (attribute.SecureConfiguration != null) { additionalParmeters += ",SecureConfiguration = \"" + attribute.SecureConfiguration + "\""; } if (attribute.Action != null) { additionalParmeters += ",Action = PluginStepOperationEnum." + attribute.Action; } string tab = " "; Regex parser = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); // determine which template to use if (targetType == TargetType.Plugin) { // Plugin Step string template = "\"{0}\",\"{1}\",StageEnum.{2},ExecutionModeEnum.{3},\"{4}\",\"{5}\",{6},IsolationModeEnum.{7}{8}"; code = String.Format(template, attribute.Message, attribute.EntityLogicalName, attribute.Stage, attribute.ExecutionMode, attribute.FilteringAttributes, attribute.Name, attribute.ExecutionOrder, attribute.IsolationMode, additionalParmeters); } else { // Workflow Step string template = "\"{0}\",\"{1}\",\"{2}\",\"{3}\",IsolationModeEnum.{4}{5}"; code = String.Format(template, attribute.Name, attribute.FriendlyName, attribute.Description, attribute.GroupName, attribute.IsolationMode, additionalParmeters); } String[] fields = parser.Split(code); code = String.Join($",{indentation}{tab}", fields); string regionName = targetType == TargetType.Plugin ? $"{attribute.Message} {attribute.EntityLogicalName}" : $"{attribute.Name}"; code = $"{indentation}#region {attribute.Message}{regionName}{indentation}[CrmPluginRegistration({indentation}{tab}" + code + $"{indentation})]{indentation}#endregion"; return(code); }
public static string GetAttributeCode(this CrmPluginRegistrationAttribute attribute, string indentation) { var code = string.Empty; var targetType = (attribute.Stage != null) ? TargetType.Plugin : TargetType.WorkflowAcitivty; string additionalParmeters = ""; // Image 1 if (attribute.Image1Name != null) { additionalParmeters += indentation + ", Image1Type = ImageTypeEnum." + attribute.Image1Type; } if (attribute.Image1Name != null) { additionalParmeters += indentation + ", Image1Name = \"" + attribute.Image1Name + "\""; } if (attribute.Image1Name != null) { additionalParmeters += indentation + ", Image1Attributes = \"" + attribute.Image1Attributes + "\""; } // Image 2 if (attribute.Image2Name != null) { additionalParmeters += indentation + ", Image2Type = ImageTypeEnum." + attribute.Image2Type; } if (attribute.Image2Name != null) { additionalParmeters += indentation + ", Image2Name = \"" + attribute.Image2Name + "\""; } if (attribute.Image2Attributes != null) { additionalParmeters += indentation + ", Image2Attributes = \"" + attribute.Image2Attributes + "\""; } if (targetType == TargetType.Plugin) { // Description is only option for plugins if (attribute.Description != null) { additionalParmeters += indentation + ", Description = \"" + attribute.Description + "\""; } if (attribute.Offline) { additionalParmeters += indentation + ", Offline = " + attribute.Offline; } if (!attribute.Server) { additionalParmeters += indentation + ", Server = " + attribute.Server; } } if (attribute.Id != null) { additionalParmeters += indentation + ", Id = \"" + attribute.Id + "\""; } if (attribute.DeleteAsyncOperaton != null) { additionalParmeters += indentation + ", DeleteAsyncOperaton = " + attribute.DeleteAsyncOperaton; } if (attribute.UnSecureConfiguration != null) { additionalParmeters += indentation + ", UnSecureConfiguration = \"" + attribute.UnSecureConfiguration + "\""; } if (attribute.SecureConfiguration != null) { additionalParmeters += indentation + ", SecureConfiguration = \"" + attribute.SecureConfiguration + "\""; } if (attribute.Action != null) { additionalParmeters += indentation + ", Action = PluginStepOperationEnum." + attribute.Action; } // determine which template to use if (targetType == TargetType.Plugin) { // Plugin Step string template = "{9}[CrmPluginRegistration(\"{0}\", {9}\"{1}\", StageEnum.{2}, ExecutionModeEnum.{3}, {9}\"{4}\", \"{5}\", {6}, {9}IsolationModeEnum.{7}{8}{9})]"; code = String.Format(template, attribute.Message, attribute.EntityLogicalName, attribute.Stage, attribute.ExecutionMode, attribute.FilteringAttributes, attribute.Name, attribute.ExecutionOrder, attribute.IsolationMode, additionalParmeters, indentation); } else { // Workflow Step string template = "{6}[CrmPluginRegistration({6}\"{0}\", \"{1}\", \"{2}\", \"{3}\", IsolationModeEnum.{4}{6}{5})]"; code = String.Format(template, attribute.Name, attribute.FriendlyName, attribute.Description, attribute.GroupName, attribute.IsolationMode, additionalParmeters, indentation); } return(code); }