Exemple #1
0
        public WindowSdkMessageProcessingStepImage(
            IWriteToOutput iWriteToOutput
            , IOrganizationServiceExtented service
            , SdkMessageProcessingStepImage image
            , string entityName
            , string messageName
            )
        {
            this.IncreaseInit();

            InputLanguageManager.SetInputLanguage(this, CultureInfo.CreateSpecificCulture("en-US"));

            this._iWriteToOutput = iWriteToOutput;
            this._entityName     = entityName;
            this._messageName    = messageName;
            this._service        = service;
            this.Image           = image;

            InitializeComponent();

            tSSLblConnectionName.Content = _service.ConnectionData.Name;

            LoadEntityImageProperties();

            this.DecreaseInit();

            txtBName.Focus();
        }
Exemple #2
0
        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);
        }
        private void CreateImage(SdkMessageProcessingStep crmStep, int pre1post2, int stage, bool async, string message, Models.Image imgDef)
        {
            var name  = Kipon.Tools.Xrm.Reflection.PluginMethod.ImageSuffixFor(pre1post2, stage, async);
            var image = new SdkMessageProcessingStepImage
            {
                SdkMessageProcessingStepImageId = Guid.NewGuid(),
                SdkMessageProcessingStepId      = new Microsoft.Xrm.Sdk.EntityReference(Entities.SdkMessageProcessingStep.EntityLogicalName, crmStep.SdkMessageProcessingStepId.Value),
                Name                = name,
                EntityAlias         = name,
                Description         = name,
                ImageType           = new Microsoft.Xrm.Sdk.OptionSetValue((pre1post2 - 1)),
                MessagePropertyName = this.MessagePropertyName(message),
            };

            string filterAttr = null;

            if (!imgDef.AllAttributes && imgDef.FilteredAttributes != null && imgDef.FilteredAttributes.Length > 0)
            {
                filterAttr = string.Join(",", imgDef.FilteredAttributes);
            }

            if (!string.IsNullOrEmpty(filterAttr))
            {
                image.Attributes1 = filterAttr;
            }

            uow.Create(image);
            messageService.Inform($"Created image {name} on step {crmStep.Name}");
        }
        public static void UpdateImage(CrmOrganization org, CrmPluginImage image, CrmPluginStep step)
        {
            if (null == org)
            {
                throw new ArgumentNullException("org");
            }
            else if (null == image)
            {
                throw new ArgumentNullException("image");
            }
            else if (null == step)
            {
                throw new ArgumentNullException("step");
            }

            //Retrieve the SDK entity equivalent of the given image
            Dictionary <string, object>   entityList = image.GenerateCrmEntities(step.MessageId, step.MessageEntityId);
            SdkMessageProcessingStepImage sdkImage   = (SdkMessageProcessingStepImage)entityList[SdkMessageProcessingStepImage.EntityLogicalName];

            //If the step that owns this image is a profiled step, the step will be the original step (the step that is being profiled),
            //not the profiler step. The Profiler step is what should be set on the server, since that is the step that is actually enabled.
            if (step.IsProfiled && null != sdkImage.SdkMessageProcessingStepId)
            {
                sdkImage.SdkMessageProcessingStepId.Id = step.ProfilerStepId.GetValueOrDefault();
            }

            org.OrganizationService.Update(sdkImage);
            OrganizationHelper.RefreshImage(org, image, step);
        }
Exemple #5
0
        public TEntity ToEntity <TEntity>() where TEntity : Entity
        {
            var image =
                new SdkMessageProcessingStepImage
            {
                SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, StepId),
                ImageType           = new OptionSetValue((int)ImageType),
                MessagePropertyName = MessagePropertyName,
                Name        = Name,
                EntityAlias = EntityAlias,
                Attributes  = string.IsNullOrEmpty(Attributes) ? string.Empty : Attributes
            };

            if (Id != Guid.Empty)
            {
                image.Id = Id;
            }

            if (!string.IsNullOrEmpty(RelatedAttribute))
            {
                image.RelatedAttributeName = RelatedAttribute;
            }

            return(image.ToEntity <TEntity>());
        }
Exemple #6
0
        public WindowSdkMessageProcessingStepImage(
            IWriteToOutput iWriteToOutput
            , IOrganizationServiceExtented service
            , SdkMessageProcessingStepImage image
            , string entityName
            , string messageName
            ) : base(iWriteToOutput, service)
        {
            this.IncreaseInit();

            InitializeComponent();

            SetInputLanguageEnglish();

            this._entityName  = entityName;
            this._messageName = messageName;
            this.Image        = image;

            tSSLblConnectionName.Content = _service.ConnectionData.Name;

            LoadEntityImageProperties();

            this.DecreaseInit();

            txtBName.Focus();
        }
Exemple #7
0
        public Guid UpsertSdkMessageProcessingStepImage(Guid parentId, Image image, string solutionName, string registrationType)
        {
            var  name      = image.EntityAlias;
            var  imageType = (int)GetEnumValue <SdkMessageProcessingStepImage_ImageType>(image.ImageType);
            Guid Id        = Guid.Empty;

            if (image == null || string.IsNullOrEmpty(image.Id) || !Guid.TryParse(image.Id, out Id))
            {
                Id = GetSdkMessageProcessingStepImageId(parentId, name, imageType);
                xrmCommandBase.WriteWarning(string.Format("Extracted id using plugin step image name {0}", name));
            }

            var sdkMessageProcessingStepImage = new SdkMessageProcessingStepImage()
            {
                Attributes1                = image.Attributes,
                EntityAlias                = image.EntityAlias,
                MessagePropertyName        = image.MessagePropertyName,
                ImageType                  = new OptionSetValue(imageType),
                SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, parentId)
            };

            Id = ExecuteRequest(registrationType, Id, sdkMessageProcessingStepImage);

            return(Id);
        }
        private void _UpdateImage(CrmStepImage image)
        {
            UpdateStatus($"Updating image '{image.Name}' in step ... ", 1);

            //var updatedImage = Context.SdkMessageProcessingStepImageSet.FirstOrDefault(entity => entity.SdkMessageProcessingStepImageId == image.Id)
            //					  ?? new SdkMessageProcessingStepImage();

            //if (updatedImage.Id == Guid.Empty)
            //{
            //	updatedImage.Id = image.Id;
            //}
            var updatedImage = new SdkMessageProcessingStepImage
            {
                Id          = image.Id,
                Name        = image.Name,
                EntityAlias = image.EntityAlias,
                Attributes1 = image.AttributesSelectedString,
                ImageType   = image.ImageType.ToOptionSetValue()
            };

            //Context.ConfirmAttached(updatedImage);
            //Context.UpdateObject(updatedImage);
            UpdateStatus("Updating image ... ");
            Service.Update(updatedImage);
            //UpdateStatus("Saving updated image to CRM ... ");
            //Context.SaveChanges();

            UpdateStatus($"Finished updating image '{image.Name}'.", -1);
        }
Exemple #9
0
        public Dictionary <string, object> GenerateCrmEntities(Guid sdkMessageId, Guid sdkMessageFilterId)
        {
            if (Organization != null)
            {
                if (string.IsNullOrEmpty(MessagePropertyName))
                {
                    List <ImageMessagePropertyName> validImages = Organization.Messages[sdkMessageId].ImageMessagePropertyNames;
                    if (0 != validImages.Count)
                    {
                        //Select the first one from the list
                        MessagePropertyName = validImages[0].Name;
                    }
                }
            }

            Dictionary <string, object>   entityList = new Dictionary <string, object>();
            SdkMessageProcessingStepImage image      = new SdkMessageProcessingStepImage();

            if (ImageId != Guid.Empty)
            {
                image.SdkMessageProcessingStepImageId    = new Guid?();
                image["sdkmessageprocessingstepimageid"] = ImageId;
            }

            if (StepId != Guid.Empty)
            {
                image.SdkMessageProcessingStepId             = new EntityReference();
                image.SdkMessageProcessingStepId.LogicalName = SdkMessageProcessingStep.EntityLogicalName;
                image.SdkMessageProcessingStepId.Id          = StepId;
            }

            image.ImageType       = new OptionSetValue();
            image.ImageType.Value = (int)ImageType;

            image.MessagePropertyName = MessagePropertyName;

            image.Name = Name;

            image.EntityAlias = EntityAlias;

            if (!string.IsNullOrEmpty(Attributes)) // null is all attributes
            {
                image.Attributes1 = Attributes;
            }
            else
            {
                image.Attributes1 = string.Empty;
            }
            if (!string.IsNullOrEmpty(RelatedAttribute))
            {
                image.RelatedAttributeName = RelatedAttribute; //For Related Entity Information
            }

            entityList.Add(SdkMessageProcessingStepImage.EntityLogicalName, image);

            return(entityList);
        }
Exemple #10
0
        /// <summary>
        /// Update the existing image if the attributes are changed.
        /// </summary>
        /// <param name="image"> old image from dynamics </param>
        /// <param name="imageAttribute"> new image attributes </param>
        /// <param name="imageName">The name of the image </param>
        /// <param name="uow"> Iunitofwork object that is connected to dynamics </param>
        private static void UpdateImage(SdkMessageProcessingStepImage image, string imageAttribute, string imageName, IUnitOfWork uow)
        {
            var clean = uow.SdkMessageProcessingStepImages.Clean(image);

            if (imageAttribute != image.Attributes1)
            {
                clean.Attributes1 = imageAttribute;
                uow.Update(clean);
                Console.WriteLine(imageName + " updated " + imageName + " :" + imageAttribute);
            }
            image.Relevant = true;
        }
Exemple #11
0
        private async Task <SdkMessageProcessingStepImage> GetStepImageById(Guid id)
        {
            SdkMessageProcessingStepImage entity1 = GetLinked1(id);
            SdkMessageProcessingStepImage entity2 = await GetLinked2(id);

            SdkMessageProcessingStepImage entity3 = GetLinked3(id);

            entity1.Merge(entity2, entity3);

            SdkMessageProcessingStepRepository.FullfillEntitiesSteps(entity1);

            return(entity1);
        }
Exemple #12
0
        private static Entity ComposeEntity(ImageType imageType, string imageName, EntityReference sdkMessageProcessingStepRef, string attributes)
        {
            var image = new SdkMessageProcessingStepImage
            {
                ImageType   = MapImageType(imageType),
                Name        = imageName,
                EntityAlias = imageName,
                SdkMessageProcessingStepId = sdkMessageProcessingStepRef,
                MessagePropertyName        = "Target",
                Attributes1 = attributes
            };

            return(image);
        }
Exemple #13
0
 /// <summary>
 /// Method to Register an Image.
 /// </summary>
 /// <param name="xrmPluginImage">The Image to Register.</param>
 /// <returns>The newly Registered Image Identifier.</returns>
 internal Guid RegisterImage(string xrmServerDetails, XrmPluginImage xrmPluginImage)
 {
     try
     {
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             SdkMessageProcessingStepImage sdkMessageProcessingStepImage = GetPluginImage(xrmPluginImage);
             return(xrmService.Create(sdkMessageProcessingStepImage));
         }
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
        public EntityReference Register(IOrganizationService client, EntityReference parentStep)
        {
            var stepImage = new SdkMessageProcessingStepImage()
            {
                Name                       = this.Name,
                EntityAlias                = this.Name,
                Attributes1                = string.Join(",", this.Attributes),
                ImageType                  = SdkMessageProcessingStepImage_ImageType.PreImage,
                MessagePropertyName        = "Target",
                SdkMessageProcessingStepId = parentStep
            };

            var existingImageQuery = this.GetExistingQuery(parentStep);

            return(stepImage.CreateOrUpdate(client, existingImageQuery));
        }
Exemple #15
0
 /// <summary>
 /// Method to Update an Image Registration.
 /// </summary>
 /// <param name="xrmPluginImage">The Image to Update.</param>
 /// <returns>Result.</returns>
 internal bool UpdateImage(string xrmServerDetails, XrmPluginImage xrmPluginImage)
 {
     try
     {
         Result = false;
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             SdkMessageProcessingStepImage sdkMessageProcessingStepImage = GetPluginImage(xrmPluginImage);
             xrmService.Update(sdkMessageProcessingStepImage);
         }
         Result = true;
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Exemple #16
0
        public Guid UpsertSdkMessageProcessingStepImage(Guid parentId, Image image, string solutionName, string registrationType)
        {
            var  name      = image.EntityAlias;
            var  imageType = (int)GetEnumValue <SdkMessageProcessingStepImage_ImageType>(image.ImageType);
            Guid Id        = GetSdkMessageProcessingStepImageId(parentId, name, imageType);

            var sdkMessageProcessingStepImage = new SdkMessageProcessingStepImage()
            {
                Attributes1                = image.Attributes,
                EntityAlias                = image.EntityAlias,
                MessagePropertyName        = image.MessagePropertyName,
                ImageType                  = new OptionSetValue(imageType),
                SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, parentId)
            };

            Id = ExecuteRequest(registrationType, Id, sdkMessageProcessingStepImage);

            return(Id);
        }
Exemple #17
0
        private void _UpdateImage(CrmStepImage image)
        {
            UpdateStatus($"Updating image '{image.Name}' in step ... ", 1);

            var updatedImage =
                new SdkMessageProcessingStepImage
            {
                Id                         = image.Id,
                Name                       = image.Name,
                EntityAlias                = image.EntityAlias,
                Attributes1                = image.AttributesSelectedString,
                ImageType                  = image.ImageType.ToOptionSetValue(),
                MessagePropertyName        = image.Step.MessagePropertyName,
                SdkMessageProcessingStepId = new EntityReference(
                    SdkMessageProcessingStep.EntityLogicalName, image.Step.Id)
            };

            UpdateStatus("Updating image ... ");
            Service.Update(updatedImage);

            UpdateStatus($"Finished updating image '{image.Name}'.", -1);
        }
        private SortedSet<string> GetSetImageAttributes(SdkMessageProcessingStepImage image)
        {
            SortedSet<string> result = new SortedSet<string>();

            if (!string.IsNullOrEmpty(image.Attributes1))
            {
                if (image.Contains(SdkMessageProcessingStep.Schema.EntityAliasFields.SdkMessageFilterPrimaryObjectTypeCode))
                {
                    string primaryEntity = (string)image.GetAttributeValue<AliasedValue>(SdkMessageProcessingStep.Schema.EntityAliasFields.SdkMessageFilterPrimaryObjectTypeCode).Value;

                    if (primaryEntity.IsValidEntityName())
                    {
                        foreach (var item in image.Attributes1Strings)
                        {
                            result.Add(string.Format("{0}.{1}", primaryEntity, item));
                        }
                    }
                }
            }

            return result;
        }
Exemple #19
0
 /// <summary>
 /// Method to populate a Dynamics CRM Image from a XRM Image and retrieve it.
 /// </summary>
 /// <param name="xrmPluginImage">The ZRM Image providing the details.</param>
 /// <returns>The Dynamics CRM Image.</returns>
 private SdkMessageProcessingStepImage GetPluginImage(XrmPluginImage xrmPluginImage)
 {
     try
     {
         SdkMessageProcessingStepImage = new SdkMessageProcessingStepImage();
         if (!string.IsNullOrEmpty(xrmPluginImage.Attributes))
         {
             SdkMessageProcessingStepImage.Attributes1 = xrmPluginImage.Attributes;
         }
         SdkMessageProcessingStepImage.EntityAlias = xrmPluginImage.EntityAlias;
         SdkMessageProcessingStepImage.SdkMessageProcessingStepImageId = xrmPluginImage.ImageId;
         SdkMessageProcessingStepImage.Name = xrmPluginImage.MessageProperty;
         SdkMessageProcessingStepImage.MessagePropertyName        = xrmPluginImage.MessagePropertyName;
         SdkMessageProcessingStepImage.SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, xrmPluginImage.StepId.Value);
         SdkMessageProcessingStepImage.ImageType = new OptionSetValue((int)xrmPluginImage.ImageType);
         return(SdkMessageProcessingStepImage);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
        private Guid UpsertSdkMessageProcessingStepImage(Guid parentId, Image image, string solutionName, RegistrationTypeEnum registrationType)
        {
            Guid Id = image.Id ?? Guid.Empty;

            if (Id == Guid.Empty)
            {
                Id = pluginRepository.GetSdkMessageProcessingStepImageId(parentId, image.EntityAlias, image.ImageType);
                logWarning?.Invoke($"Extracted id using plugin step image name {image.EntityAlias}");
            }

            var sdkMessageProcessingStepImage = new SdkMessageProcessingStepImage()
            {
                Attributes1                = image.Attributes,
                EntityAlias                = image.EntityAlias,
                MessagePropertyName        = image.MessagePropertyName,
                ImageTypeEnum              = image.ImageType,
                SdkMessageProcessingStepId = new EntityReference(SdkMessageProcessingStep.EntityLogicalName, parentId)
            };

            Id = ExecuteRequest(registrationType, Id, sdkMessageProcessingStepImage);

            return(Id);
        }
        private void _CreateImage(CrmStepImage image)
        {
            UpdateStatus($"Creating image '{image.Name}' in step ... ", 1);

            var newImage = new SdkMessageProcessingStepImage
            {
                Name                       = image.Name,
                EntityAlias                = image.EntityAlias,
                Attributes1                = image.AttributesSelectedString,
                ImageType                  = image.ImageType.ToOptionSetValue(),
                MessagePropertyName        = image.Step.MessagePropertyName,
                SdkMessageProcessingStepId = new EntityReference(
                    SdkMessageProcessingStep.EntityLogicalName, image.Step.Id)
            };

            //Context.AddObject(newImage);

            UpdateStatus("Saving new image to CRM ... ");
            image.Id = Service.Create(newImage);
            //Context.SaveChanges();
            //image.Id = newImage.Id;

            UpdateStatus($"Finished creating image '{image.Name}'.", -1);
        }
Exemple #22
0
        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);
        }
Exemple #23
0
        private void RefreshFromSdkMessageProcessingStepImage(Guid assemblyId, Guid pluginId, SdkMessageProcessingStepImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            Contract.EndContractBlock();

            Id                  = image.Id;
            AssemblyId          = assemblyId;
            PluginId            = pluginId;
            Attributes          = image.Attributes;
            EntityAlias         = image.EntityAlias;
            MessagePropertyName = image.MessagePropertyName;
            RelatedAttribute    = image.RelatedAttributeName;
            Name                = image.Name;

            if (image.SdkMessageProcessingStepId != null)
            {
                StepId = image.SdkMessageProcessingStepId.Id;
            }

            if (image.ImageType != null)
            {
                ImageType = (CrmPluginImageType)image.ImageType.Value;
            }
        }
        public static bool UpdateStep(CrmOrganization org, CrmPluginStep step, Guid?origSecureConfigId,
                                      IList <CrmPluginImage> updateImages)
        {
            if (org == null)
            {
                throw new ArgumentNullException("org");
            }
            else if (step == null)
            {
                throw new ArgumentNullException("step");
            }

            Dictionary <string, object> entityList = step.GenerateCrmEntities();
            SdkMessageProcessingStep    sdkStep    = (SdkMessageProcessingStep)entityList[SdkMessageProcessingStep.EntityLogicalName];

            // Loop through each image and set the new message property
            List <SdkMessageProcessingStepImage> sdkImages = null;

            if (null != updateImages)
            {
                // Ensure that the given message supports images
                CrmMessage message = org.Messages[step.MessageId];
                if (0 == message.ImageMessagePropertyNames.Count && step.Images.Count > 0)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                      "The step has images registered, but the \"{0}\" message doesn't support images.{1}In order to change the message to \"{0}\", delete the existing images.",
                                                                      message.Name, Environment.NewLine));
                }

                // Loop through the existing images and update their message property name values
                sdkImages = new List <SdkMessageProcessingStepImage>(updateImages.Count);
                foreach (CrmPluginImage image in updateImages)
                {
                    // Set the message property name for each of the images
                    string propertyName = MessagePropertyNameForm.SelectMessagePropertyName(message);
                    if (string.IsNullOrWhiteSpace(propertyName))
                    {
                        return(false);
                    }
                    else if (string.Equals(image.MessagePropertyName, propertyName, StringComparison.Ordinal))
                    {
                        continue;
                    }

                    // Create the entity to update the value
                    SdkMessageProcessingStepImage sdkImage = new SdkMessageProcessingStepImage();
                    sdkImage.Id = image.ImageId;
                    sdkImage.MessagePropertyName = propertyName;
                    sdkImage.EntityState         = EntityState.Changed;

                    sdkImages.Add(sdkImage);
                }
            }

            //This is a sanity check. The UI won't allow a user to set the secure configuration.
            if (org.SecureConfigurationPermissionDenied)
            {
                sdkStep.Attributes.Remove("sdkmessageprocessingstepsecureconfigid");
                sdkStep.RelatedEntities.Clear();
                origSecureConfigId = null;
            }
            else if (entityList.ContainsKey(Entities.SdkMessageProcessingStepSecureConfig.EntityLogicalName))
            {
                if (null == origSecureConfigId)
                {
                    entityList.Remove(Entities.SdkMessageProcessingStepSecureConfig.EntityLogicalName);
                }
                else
                {
                    SdkMessageProcessingStepSecureConfig sdkSecureConfig =
                        (SdkMessageProcessingStepSecureConfig)entityList[SdkMessageProcessingStepSecureConfig.EntityLogicalName];

                    Guid        secureConfigId;
                    EntityState secureConfigState;
                    if (step.SecureConfigurationId == origSecureConfigId && origSecureConfigId.GetValueOrDefault() != Guid.Empty)
                    {
                        //Set the ID of the secure configuration to be the
                        secureConfigId    = origSecureConfigId.GetValueOrDefault();
                        secureConfigState = EntityState.Changed;

                        //Set the original secure config id so that the current id is not deleted
                        sdkStep.SdkMessageProcessingStepSecureConfigId =
                            new EntityReference(SdkMessageProcessingStepSecureConfig.EntityLogicalName, secureConfigId);
                    }
                    else
                    {
                        secureConfigId    = Guid.NewGuid();
                        secureConfigState = EntityState.Created;
                    }

                    //Set the configuration id for the step
                    step.SecureConfigurationId = secureConfigId;

                    //Populate the secure configuration object and add it to the related entities
                    sdkSecureConfig.SdkMessageProcessingStepSecureConfigId = secureConfigId;
                    sdkSecureConfig.EntityState = secureConfigState;

                    //Update the related entities
                    sdkStep.sdkmessageprocessingstepsecureconfigid_sdkmessageprocessingstep = sdkSecureConfig;

                    //Reset the original secure configuration
                    origSecureConfigId = null;
                }
            }
            else if (null != origSecureConfigId)
            {
                // To null out if it was set before
                sdkStep.SdkMessageProcessingStepSecureConfigId = null;
                step.SecureConfigurationId = Guid.Empty;

                if (Guid.Empty == origSecureConfigId)
                {
                    origSecureConfigId = null;
                }
            }

            // If the images need to be updated, there are two possible scenarios:
            // 1) The step is profiled -- The parent of the image is not the step that is currently being updated
            //    but rather the profiler step itself. In order to avoid changing this, there will have to be two SDK
            //    operations (update the step and update the images). Otherwise, the next time the profiled step executes,
            //    the images won't be present.
            // 2) The step is not profiled -- The image can be added to the related entities because the parent step is the
            //    current step being updated.
            if (null != sdkImages && sdkImages.Count > 0)
            {
                if (!step.IsProfiled || step.ProfilerStepId == step.StepId)
                {
                    sdkStep.sdkmessageprocessingstepid_sdkmessageprocessingstepimage = sdkImages;
                }
            }

            //Update the step
            org.OrganizationService.Update(sdkStep);

            if (step.IsProfiled && null != sdkImages && sdkImages.Count > 0)
            {
                // Update the Profiler step with the new property values as a single transaction to minimize the
                // possibility of data corruption.
                SdkMessageProcessingStep profilerStep = new SdkMessageProcessingStep();
                profilerStep.Id = step.ProfilerStepId.GetValueOrDefault();
                profilerStep.sdkmessageprocessingstepid_sdkmessageprocessingstepimage = sdkImages;
                org.OrganizationService.Update(profilerStep);
            }

            // Refresh the objects so that the caller has up-to-date data
            OrganizationHelper.RefreshStep(org, step);
            if (null != updateImages)
            {
                foreach (CrmPluginImage image in updateImages)
                {
                    OrganizationHelper.RefreshImage(org, image, step);
                }
            }

            // Delete the orphaned Secure config when nulling out the value on the step
            if (null != origSecureConfigId)
            {
                org.OrganizationService.Delete(SdkMessageProcessingStepSecureConfig.EntityLogicalName, origSecureConfigId.GetValueOrDefault());
            }

            return(true);
        }
Exemple #25
0
 public CrmPluginImage(Guid assemblyId, Guid pluginId, SdkMessageProcessingStepImage image)
 {
     RefreshFromSdkMessageProcessingStepImage(assemblyId, pluginId, image);
 }
Exemple #26
0
        private void CreateImages(UnitOfWork.UnitOfWork uow,
                                  IEnumerable <Step> stepsToCreate,
                                  IReadOnlyCollection <SdkMessageProcessingStepImage> allImages,
                                  IReadOnlyDictionary <string, SdkMessageProcessingStep> stepindex)
        {
            foreach (var step in stepsToCreate)
            {
                var xrmStep = stepindex[step.UniqueName];
                var images  = (
                    from im in allImages
                    where xrmStep.SdkMessageProcessingStepId != null && im.SdkMessageProcessingStepId.Id == xrmStep.SdkMessageProcessingStepId.Value
                    select im);
                var preImageDefined = !string.IsNullOrEmpty(step.PreImageName);


                var sdkMessageProcessingStepImages = images as SdkMessageProcessingStepImage[] ?? images.ToArray();
                if (sdkMessageProcessingStepImages.Any())
                {
                    sdkMessageProcessingStepImages.ForEach(image =>
                    {
                        if (image == null)
                        {
                            var attributes = preImageDefined
                                ? step.PreImageAttributes != null && step.PreImageAttributes.Length > 0
                                    ? string.Join(",", step.PreImageAttributes)
                                    : null
                                : step.PostImageAttributes != null && step.PostImageAttributes.Length > 0
                                    ? string.Join(",", step.PostImageAttributes)
                                    : null;

                            var imageToCreate = new SdkMessageProcessingStepImage
                            {
                                SdkMessageProcessingStepImageId = Guid.NewGuid(),
                                SdkMessageProcessingStepId      = xrmStep.ToEntityReference(),
                                Name                = preImageDefined ? step.PreImageName : step.PostImageName,
                                EntityAlias         = preImageDefined ? step.PreImageName : step.PostImageName,
                                MessagePropertyName = step.MessagePropertyName,
                                ImageType           = preImageDefined ? new OptionSetValue(0) : new OptionSetValue(1),
                                Description         = preImageDefined ? step.PreImageName : step.PostImageName,
                                Relevant            = true,
                                Attributes1         = attributes
                            };
                            uow.Create(imageToCreate);
                            logger.Log(preImageDefined ? $"Pre Image '{step.PreImageName}' created for '{step.Name}'" : $"Post Image '{step.PostImageName}' created for '{step.Name}'");
                        }
                        else
                        {
                            var clean = uow.SdkMessageProcessingStepImages.Clean(image);

                            var atr = preImageDefined ? step.PreImageAttributes == null || step.PreImageAttributes.Length == 0 ? null :
                                      string.Join(",", step.PreImageAttributes) :
                                      step.PostImageAttributes == null || step.PostImageAttributes.Length == 0 ? null :
                                      string.Join(",", step.PostImageAttributes);

                            if (atr != image.Attributes1)
                            {
                                clean.Attributes1 = atr;
                                uow.Update(clean);
                                if (preImageDefined)
                                {
                                    logger.Log("Pre image updated " + step.Name + " :" + atr);
                                }
                                else
                                {
                                    logger.Log("Post image updated " + step.Name + " :" + atr);
                                }
                            }

                            image.Relevant = true;
                        }
                    });
                }
                else
                {
                    var attributes = preImageDefined
                        ? step.PreImageAttributes != null && step.PreImageAttributes.Length > 0
                            ? string.Join(",", step.PreImageAttributes)
                            : null
                        : step.PostImageAttributes != null && step.PostImageAttributes.Length > 0
                            ? string.Join(",", step.PostImageAttributes)
                            : null;

                    var imageToCreate = new SdkMessageProcessingStepImage
                    {
                        SdkMessageProcessingStepImageId = Guid.NewGuid(),
                        SdkMessageProcessingStepId      = xrmStep.ToEntityReference(),
                        Name                = preImageDefined ? step.PreImageName : step.PostImageName,
                        EntityAlias         = preImageDefined ? step.PreImageName : step.PostImageName,
                        MessagePropertyName = step.MessagePropertyName,
                        ImageType           = preImageDefined ? new OptionSetValue(0) : new OptionSetValue(1),
                        Description         = preImageDefined ? step.PreImageName : step.PostImageName,
                        Relevant            = true,
                        Attributes1         = attributes
                    };
                    uow.Create(imageToCreate);
                    if (preImageDefined)
                    {
                        logger.Log($"Pre Image {step.PreImageName} created " + step.Name);
                    }
                    else
                    {
                        logger.Log($"Post Image {step.PostImageName} created " + step.Name);
                    }
                }
            }


            var notNeededs = (from im in allImages where im.Relevant == false select im).ToArray();

            foreach (var notNeeded in notNeededs)
            {
                uow.Delete(notNeeded);
                logger.Log("Image deleted for " + notNeeded.Name);
            }
        }
        public void RefreshFromSdkMessageProcessingStepImage(Guid assemblyId, Guid pluginId, SdkMessageProcessingStepImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            AssemblyId = assemblyId;
            PluginId = pluginId;

            if (image.SdkMessageProcessingStepImageId != null)
            {
                ImageId = image.SdkMessageProcessingStepImageId.Value;
            }

            if (image.Attributes != null)
            {
                Attributes = image.Attributes1;
            }

            if (image.EntityAlias != null)
            {
                EntityAlias = image.EntityAlias;
            }

            if (image.MessagePropertyName != null)
            {
                MessagePropertyName = image.MessagePropertyName;
            }

            if (image.RelatedAttributeName != null)
            {
                RelatedAttribute = image.RelatedAttributeName;
            }

            if (image.SdkMessageProcessingStepId != null)
            {
                StepId = image.SdkMessageProcessingStepId.Id;
            }

            if (image.ImageType != null)
            {
                ImageType = (CrmPluginImageType)Enum.ToObject(typeof(CrmPluginImageType), image.ImageType.Value);
            }

            if (image.CustomizationLevel != null)
            {
                m_customizationLevel = image.CustomizationLevel.Value;
            }

            if (image.CreatedOn != null && (image.CreatedOn.HasValue))
            {
                m_createdOn = image.CreatedOn.Value;
            }

            if (image.ModifiedOn != null && (image.ModifiedOn.HasValue))
            {
                m_modifiedOn = image.ModifiedOn.Value;
            }

            Name = image.Name;
        }
 public CrmPluginImage(CrmOrganization org, Guid assemblyId, Guid pluginId, SdkMessageProcessingStepImage image)
     : this(org)
 {
     RefreshFromSdkMessageProcessingStepImage(assemblyId, pluginId, image);
 }
 private void DeleteSdkMessageProcessingStepImage(SdkMessageProcessingStepImage sdkMessageProcessingStepImage)
 {
     _service.Delete(SdkMessageProcessingStepImage.EntityLogicalName, sdkMessageProcessingStepImage.Id);
 }