private void RegisterStep(PluginType sdkPluginType, List <SdkMessageProcessingStep> existingSteps, CustomAttributeData pluginAttribute) { var pluginStep = pluginAttribute.CreateFromData(); 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; step.AsyncAutoDelete = pluginStep.ExecutionMode == ExecutionModeEnum.Asynchronous ? pluginStep.DeleteAsyncOperation : 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 = pluginStep.FilteringAttributes; step.AsyncAutoDelete = pluginStep.DeleteAsyncOperation; 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 RegisterStep(PluginType sdkPluginType, IEnumerable <SdkMessageProcessingStep> existingSteps, CustomAttributeData pluginAttribute) { var pluginStep = (CrmPluginRegistrationAttribute)pluginAttribute.CreateFromData(); 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.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 _service.Update(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); } }