Пример #1
0
 /// <summary>
 /// Method to Unregister a Step.
 /// </summary>
 /// <param name="xrmPluginStep">The Step to Unregister.</param>
 /// <returns>Result.</returns>
 internal bool UnregisterStep(string xrmServerDetails, XrmPluginStep xrmPluginStep, Collection <string> errors, SolutionComponentType solutionComponentType)
 {
     try
     {
         Result = RegistrationService.Unregister(xrmServerDetails, SdkMessageProcessingStep.EntityLogicalName, xrmPluginStep.StepId.Value, errors, solutionComponentType);
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #2
0
 /// <summary>
 /// Method to Register a step.
 /// </summary>
 /// <param name="xrmPluginStep">The Step to Register.</param>
 /// <returns>The Identifier of the Registered Step.</returns>
 internal Guid RegisterStep(string xrmServerDetails, XrmPluginStep xrmPluginStep)
 {
     try
     {
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             SdkMessageProcessingStep sdkMessageProcessingStep = GetPluginStep(xrmPluginStep);
             return(xrmService.Create(sdkMessageProcessingStep));
         }
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #3
0
 /// <summary>
 /// Method to verify if the Image is already registered in Dynamics CRM.
 /// </summary>
 /// <param name="xrmPluginStep">The XRM Step Object.</param>
 /// <param name="image">The Image Object.</param>
 /// <param name="service">The XRM Service.</param>
 /// <param name="attributeCSV">A CSV of Attributes.</param>
 /// <returns>An Object containing the details of the verification. If the Image deosn't already exists, a new Image Identifier is returned.</returns>
 private ItemExists GetImageId(XrmPluginStep xrmPluginStep, Image image, XrmService service, string attributeCSV)
 {
     try
     {
         ImageDetails = new ItemExists();
         QuerySdkMessageProcessingStepImage = new QueryExpression(SdkMessageProcessingStepImage.EntityLogicalName)
         {
             ColumnSet = new ColumnSet("sdkmessageprocessingstepimageid"),
             Criteria  = new FilterExpression()
         };
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("entityalias", ConditionOperator.Equal, image.EntityAlias);
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("imagetype", ConditionOperator.Equal, (int)image.ImageType);
         if (!string.IsNullOrEmpty(attributeCSV))
         {
             QuerySdkMessageProcessingStepImage.Criteria.AddCondition("attributes", ConditionOperator.Equal, attributeCSV);
         }
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("name", ConditionOperator.Equal, image.MessageProperty);
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("sdkmessageprocessingstepid", ConditionOperator.Equal, xrmPluginStep.StepId);
         SdkMessageProcessingStepImageEntityCollection = service.RetrieveMultiple(QuerySdkMessageProcessingStepImage);
         if (SdkMessageProcessingStepImageEntityCollection.Entities.Count != 0)
         {
             foreach (Entity entity in SdkMessageProcessingStepImageEntityCollection.Entities)
             {
                 SdkMessageProcessingStepImage = (SdkMessageProcessingStepImage)entity;
                 if (SdkMessageProcessingStepImage.SdkMessageProcessingStepImageId.HasValue)
                 {
                     ImageDetails.ItemId = SdkMessageProcessingStepImage.SdkMessageProcessingStepImageId.Value;
                     ImageDetails.Exists = true;
                 }
                 else
                 {
                     ImageDetails.ItemId = Guid.NewGuid();
                     ImageDetails.Exists = false;
                 }
             }
         }
         else
         {
             ImageDetails.ItemId = Guid.NewGuid();
             ImageDetails.Exists = false;
         }
         return(ImageDetails);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #4
0
 /// <summary>
 /// Method to verify if a Step is already Registered in Dynamics CRM.
 /// </summary>
 /// <param name="step">The Step to verify.</param>
 /// <param name="xrmPluginStep">The Step to populate.</param>
 /// <param name="service">The XRM Service.</param>
 /// <returns>An object containing the details of the verification, including a new Step Identifier if the Step isn't Registered.</returns>
 private ItemExists GetStepId(PluginStep step, XrmPluginStep xrmPluginStep, XrmService service)
 {
     try
     {
         ItemExists stepDetails = new ItemExists();
         stepDetails.SecureConfigId = new Guid?();
         stepDetails.ItemId         = new Guid();
         stepDetails.Exists         = false;
         QueryByAttribute querySdkProcessingStepMessage = new QueryByAttribute(SdkMessageProcessingStep.EntityLogicalName);
         querySdkProcessingStepMessage.ColumnSet = new ColumnSet(true);
         querySdkProcessingStepMessage.AddAttributeValue("name", xrmPluginStep.Name);
         EntityCollection sdkMessageProcessingStepEntityCollection = service.RetrieveMultiple(querySdkProcessingStepMessage);
         if (sdkMessageProcessingStepEntityCollection.Entities.Count != 0)
         {
             foreach (Entity entity in sdkMessageProcessingStepEntityCollection.Entities)
             {
                 SdkMessageProcessingStep sdkMessageProcessingStep = (SdkMessageProcessingStep)entity;
                 if (sdkMessageProcessingStep.SdkMessageProcessingStepId.HasValue)
                 {
                     stepDetails.ItemId = sdkMessageProcessingStep.SdkMessageProcessingStepId.Value;
                     stepDetails.Exists = true;
                 }
                 else
                 {
                     stepDetails.ItemId = Guid.NewGuid();
                     stepDetails.Exists = false;
                 }
                 stepDetails.SecureConfigId = GetSecureConfigId(step, service, stepDetails.SecureConfigId, sdkMessageProcessingStep);
             }
         }
         else
         {
             stepDetails.ItemId = Guid.NewGuid();
             stepDetails.Exists = false;
             if (!string.IsNullOrEmpty(step.SecureConfiguration))
             {
                 stepDetails.SecureConfigId = Guid.NewGuid();
             }
         }
         return(stepDetails);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #5
0
 /// <summary>
 /// Method to add the Secure Configuration on update of the Plugin Step if missing.
 /// </summary>
 /// <param name="xrmPluginStep">The Plugin Step.</param>
 /// <param name="sdkMessageProcessingStep">The SDK Message Processing Step.</param>
 private void AddSecureConfigIfMissing(XrmPluginStep xrmPluginStep, SdkMessageProcessingStep sdkMessageProcessingStep)
 {
     if (xrmPluginStep.SecureConfiguration != null && xrmPluginStep.SecureConfiguration.SecureConfigurationId.HasValue)
     {
         QueryByAttribute queryByAttribute = new QueryByAttribute(SdkMessageProcessingStepSecureConfig.EntityLogicalName)
         {
             ColumnSet = new ColumnSet(true),
         };
         queryByAttribute.Attributes.Add("sdkmessageprocessingstepsecureconfigid");
         queryByAttribute.Values.Add(sdkMessageProcessingStep.SdkMessageProcessingStepSecureConfigId.Id);
         if (xrmService.RetrieveMultiple(queryByAttribute).Entities.Count == 0)
         {
             SdkMessageProcessingStepSecureConfig sdkMessageProcessingStepSecureConfig = new SdkMessageProcessingStepSecureConfig();
             sdkMessageProcessingStepSecureConfig.SdkMessageProcessingStepSecureConfigId = xrmPluginStep.SecureConfiguration.SecureConfigurationId;
             sdkMessageProcessingStepSecureConfig.SecureConfig = xrmPluginStep.SecureConfiguration.SecureConfiguration;
             xrmService.Create(sdkMessageProcessingStepSecureConfig);
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Method to Update a Step.
 /// </summary>
 /// <param name="xrmPluginStep">The Step to Update.</param>
 /// <returns>Result.</returns>
 internal bool UpdateStep(string xrmServerDetails, XrmPluginStep xrmPluginStep)
 {
     try
     {
         Result = false;
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             SdkMessageProcessingStep sdkMessageProcessingStep = GetPluginStep(xrmPluginStep);
             AddSecureConfigIfMissing(xrmPluginStep, sdkMessageProcessingStep);
             xrmService.Update(sdkMessageProcessingStep);
         }
         Result = true;
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #7
0
 /// <summary>
 /// Method to retrieve the list of Images specified in the Registration Object linked to the Step object and populate the XRM Plugin Step accordingly.
 /// </summary>
 /// <param name="registration">The Registration Object.</param>
 /// <param name="step">The Step Object.</param>
 /// <param name="xrmPluginStep">The XRM Plugin Step Object.</param>
 internal XrmPluginStep GetRegistrationImages(string xrmServerDetails, PluginStep step, XrmPluginStep xrmPluginStep)
 {
     try
     {
         foreach (Image image in step.Images)
         {
             ValidateImage(step, image);
             XrmPluginImage xrmPluginImage = new XrmPluginImage();
             using (xrmService = RegistrationService.GetService(xrmServerDetails))
             {
                 string     attributeCSV = GetAttributeCSV(new XrmMetadata(xrmServerDetails), image, step.PrimaryEntity);
                 ItemExists imageDetails = GetImageId(xrmPluginStep, image, xrmService, attributeCSV);
                 xrmPluginImage.ImageId   = imageDetails.ItemId;
                 xrmPluginImage.Exists    = imageDetails.Exists;
                 xrmPluginImage.StepId    = xrmPluginStep.StepId;
                 xrmPluginImage.ImageType = image.ImageType;
                 if (!string.IsNullOrEmpty(attributeCSV))
                 {
                     xrmPluginImage.Attributes = attributeCSV;
                 }
                 xrmPluginImage.EntityAlias     = image.EntityAlias;
                 xrmPluginImage.MessageProperty = image.MessageProperty;
                 if (image.Merge.HasValue)
                 {
                     xrmPluginImage.MessagePropertyName = GetMessagePropertyName(step.PluginMessage, image.Merge.Value);
                 }
                 else
                 {
                     xrmPluginImage.MessagePropertyName = GetMessagePropertyName(step.PluginMessage);
                 }
                 xrmPluginStep.Images.Add(xrmPluginImage);
             }
         }
         return(xrmPluginStep);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #8
0
        /// <summary>
        /// Method to populate the Dynamics CRM Step Object from the XRM Step Object.
        /// </summary>
        /// <param name="xrmPluginStep">The XRM Step Object from whence to retrieve the Dynamics CRM Step Object.</param>
        /// <returns>The Dynamics CRM Step Object.</returns>
        private SdkMessageProcessingStep GetPluginStep(XrmPluginStep xrmPluginStep)
        {
            try
            {
                SdkMessageProcessingStep = new SdkMessageProcessingStep();
                if (xrmPluginStep.SecureConfiguration != null && !string.IsNullOrEmpty(xrmPluginStep.SecureConfiguration.SecureConfiguration))
                {
                    SdkMessageProcessingStepSecureConfig sdkMessageProcessingStepSecureConfig = new SdkMessageProcessingStepSecureConfig();
                    sdkMessageProcessingStepSecureConfig.SdkMessageProcessingStepSecureConfigId = xrmPluginStep.SecureConfiguration.SecureConfigurationId;
                    sdkMessageProcessingStepSecureConfig.SecureConfig = xrmPluginStep.SecureConfiguration.SecureConfiguration;
                    SdkMessageProcessingStep.SdkMessageProcessingStepSecureConfigId             = new EntityReference();
                    SdkMessageProcessingStep.SdkMessageProcessingStepSecureConfigId.LogicalName = SdkMessageProcessingStepSecureConfig.EntityLogicalName;
                    SdkMessageProcessingStep.SdkMessageProcessingStepSecureConfigId.Id          = xrmPluginStep.SecureConfiguration.SecureConfigurationId.Value;
                    Relationship relationship = new Relationship(XrmPluginStep.RelationshipStepToSecureConfig);
                    Entity       entity       = new Entity();
                    entity = (Entity)sdkMessageProcessingStepSecureConfig;
                    EntityCollection entityCollection = new EntityCollection();
                    entityCollection.Entities.Add(entity);
                    SdkMessageProcessingStep.RelatedEntities[relationship] = entityCollection;
                }
                SdkMessageProcessingStep.Configuration = xrmPluginStep.UnsecureConfiguration;
                if (xrmPluginStep.ServiceBusConfigurationId == Guid.Empty)
                {
                    SdkMessageProcessingStep.EventHandler = new EntityReference(PluginType.EntityLogicalName, xrmPluginStep.PluginId);
                }
                else
                {
                    SdkMessageProcessingStep.EventHandler = new EntityReference(ServiceEndpoint.EntityLogicalName, xrmPluginStep.ServiceBusConfigurationId);
                }
                SdkMessageProcessingStep.Name = xrmPluginStep.Name;
                SdkMessageProcessingStep.SdkMessageProcessingStepId = xrmPluginStep.StepId;
                SdkMessageProcessingStep.Mode       = new OptionSetValue();
                SdkMessageProcessingStep.Mode.Value = (int)xrmPluginStep.Mode;
                SdkMessageProcessingStep.Rank       = xrmPluginStep.Rank;
                if (xrmPluginStep.InvocationSource != null)
                {
#pragma warning disable 0612
                    SdkMessageProcessingStep.InvocationSource = new OptionSetValue((int)xrmPluginStep.InvocationSource);
#pragma warning restore 0612
                }
                SdkMessageProcessingStep.SdkMessageId                   = new EntityReference();
                SdkMessageProcessingStep.SdkMessageId.LogicalName       = SdkMessage.EntityLogicalName;
                SdkMessageProcessingStep.SdkMessageFilterId             = new EntityReference();
                SdkMessageProcessingStep.SdkMessageFilterId.LogicalName = SdkMessageFilter.EntityLogicalName;
                if (xrmPluginStep.MessageId == Guid.Empty)
                {
                    SdkMessageProcessingStep.SdkMessageId = null;
                }
                else
                {
                    SdkMessageProcessingStep.SdkMessageId.Id = xrmPluginStep.MessageId;
                }
                if (xrmPluginStep.MessageEntityId == Guid.Empty)
                {
                    SdkMessageProcessingStep.SdkMessageFilterId = null;
                }
                else
                {
                    SdkMessageProcessingStep.SdkMessageFilterId.Id = xrmPluginStep.MessageEntityId;
                }
                SdkMessageProcessingStep.ImpersonatingUserId             = new EntityReference();
                SdkMessageProcessingStep.ImpersonatingUserId.LogicalName = SystemUser.EntityLogicalName;
                if (xrmPluginStep.ImpersonatingUserId != Guid.Empty)
                {
                    SdkMessageProcessingStep.ImpersonatingUserId.Id = xrmPluginStep.ImpersonatingUserId;
                }
                else
                {
                    SdkMessageProcessingStep.ImpersonatingUserId = null;
                }
                SdkMessageProcessingStep.Stage                     = new OptionSetValue();
                SdkMessageProcessingStep.Stage.Value               = (int)xrmPluginStep.Stage;
                SdkMessageProcessingStep.SupportedDeployment       = new OptionSetValue();
                SdkMessageProcessingStep.SupportedDeployment.Value = (int)xrmPluginStep.Deployment;
                if (string.IsNullOrEmpty(xrmPluginStep.FilteringAttributes))
                {
                    SdkMessageProcessingStep.FilteringAttributes = string.Empty;
                }
                else
                {
                    SdkMessageProcessingStep.FilteringAttributes = xrmPluginStep.FilteringAttributes;
                }
                SdkMessageProcessingStep.AsyncAutoDelete = xrmPluginStep.DeleteAsyncOperationIfSuccessful;
                SdkMessageProcessingStep.Description     = xrmPluginStep.Description;
                return(SdkMessageProcessingStep);
            }
            catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
            {
                throw;
            }
        }
Пример #9
0
 /// <summary>
 /// Method to retrieve Steps according to the Registration Object.
 /// </summary>
 /// <param name="plugin">The Registration Object, which indicates which Steps to retrieve.</param>
 /// <param name="xrmPlugin">The Plugin Object to populate with the Steps retrieved.</param>
 /// <param name="pluginName">The Name of the Plugin for which to retrieve Steps.</param>
 /// <param name="pluginExists">An object containing the Identifier of the Plugin and if the Plugin exists.</param>
 internal XrmPlugin GetPluginSteps(string xrmServerDetails, Plugin plugin, XrmPlugin xrmPlugin, string pluginName, ItemExists pluginExists)
 {
     try
     {
         foreach (PluginStep step in plugin.Steps)
         {
             if (plugin.PluginName == pluginName)
             {
                 XrmPluginStep xrmPluginStep = new XrmPluginStep();
                 xrmPluginStep.PluginId = pluginExists.ItemId;
                 if (!string.IsNullOrEmpty(step.Name))
                 {
                     xrmPluginStep.Name = step.Name;
                 }
                 else
                 {
                     xrmPluginStep.Name = pluginName + ": " + step.PluginMessage + " of " + step.PrimaryEntity;
                     if (!string.IsNullOrEmpty(step.SecondaryEntity))
                     {
                         xrmPluginStep.Name += " and " + step.SecondaryEntity;
                     }
                 }
                 if (!string.IsNullOrEmpty(step.Description))
                 {
                     xrmPluginStep.Description = step.Description;
                 }
                 else
                 {
                     xrmPluginStep.Description = xrmPluginStep.Name;
                 }
                 using (xrmService = RegistrationService.GetService(xrmServerDetails))
                 {
                     xrmPluginStep.MessageEntityId     = GetSdkMessageEntityId(xrmServerDetails, step, xrmService);
                     xrmPluginStep.MessageId           = GetSdkMessageId(step, xrmService);
                     xrmPluginStep.ImpersonatingUserId = GetImpersonatingUserId(step, xrmService);
                     ItemExists stepDetails = GetStepId(step, xrmPluginStep, xrmService);
                     xrmPluginStep.StepId = stepDetails.ItemId;
                     xrmPluginStep.Exists = stepDetails.Exists;
                     if (!string.IsNullOrEmpty(step.SecureConfiguration))
                     {
                         xrmPluginStep.SecureConfiguration = new XrmSecureConfiguration();
                         xrmPluginStep.SecureConfiguration.SecureConfiguration   = step.SecureConfiguration;
                         xrmPluginStep.SecureConfiguration.SecureConfigurationId = stepDetails.SecureConfigId;
                     }
                 }
                 xrmPluginStep.UnsecureConfiguration = step.UnsecureConfiguration;
                 xrmPluginStep.FilteringAttributes   = step.FilteringAttributes;
                 xrmPluginStep.Mode             = step.Mode;
                 xrmPluginStep.Rank             = step.Rank;
                 xrmPluginStep.InvocationSource = step.InvocationSource;
                 xrmPluginStep.Stage            = step.Stage;
                 xrmPluginStep.Deployment       = step.Deployment;
                 xrmPluginStep = ImageHelper.GetRegistrationImages(xrmServerDetails, step, xrmPluginStep);
                 xrmPlugin.Steps.Add(xrmPluginStep);
             }
         }
         return(xrmPlugin);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #10
0
 /// <summary>
 /// Add Step to Solution Method.
 /// </summary>
 /// <param name="registrationCollection">Registration Collection.</param>
 /// <param name="registration">Registration.</param>
 /// <param name="step">Step.</param>
 internal void AddStepToSolution(AssemblyRegistration registrationCollection, Registration registration, XrmPluginStep step)
 {
     if (!string.IsNullOrEmpty(registration.SolutionUniqueName) && step.StepId.HasValue)
     {
         XrmSolution = new XrmSolution(registrationCollection.ConnectionString);
         XrmSolution.AddComponentToSolution(SolutionComponentType.SDKMessageProcessingStep, step.StepId.Value, registration.SolutionUniqueName);
     }
 }