private static void MapPluginAssemblyStepObject(SdkMessageProcessingStep pluginStep
                                                        , SdkMessage sdkMessage
                                                        , SdkMessageFilter filter
                                                        , List <SdkMessageProcessingStepImage> images
                                                        , Assembly pluginAssembly
                                                        , Type pluginType)
        {
            var step = new Step()
            {
                Id = pluginStep.SdkMessageProcessingStepId,
                CustomConfiguration = pluginStep.Configuration,
                Name                      = pluginStep.Name,
                Description               = pluginStep.Description,
                FilteringAttributes       = pluginStep.FilteringAttributes,
                ImpersonatingUserFullname = pluginStep.ImpersonatingUserId?.Name ?? string.Empty,
                MessageName               = sdkMessage?.Name,
                Mode                      = pluginStep.ModeEnum,
                PrimaryEntityName         = filter.PrimaryObjectTypeCode,
                Rank                      = pluginStep.Rank,
                Stage                     = pluginStep.StageEnum,
                SupportedDeployment       = pluginStep.SupportedDeploymentEnum,
                Images                    = new List <Image>()
            };

            MapImagesObject(images, pluginStep, step);
            pluginType.Steps.Add(step);
        }
Exemplo n.º 2
0
        private static void MapPluginAssemblyStepObject(PluginType pluginType
                                                        , SdkMessageProcessingStep pluginStep
                                                        , SdkMessage sdkMessage
                                                        , SdkMessageFilter filter
                                                        , List <SdkMessageProcessingStepImage> images
                                                        , Assembly pluginAssemblyTemp
                                                        , Type pluginAssemblyTypeTemp)
        {
            var pluginAssemblyStepTemp = pluginAssemblyTemp.PluginTypes.FirstOrDefault(item1 => item1.Name == pluginType.Name)
                                         .Steps.FirstOrDefault <Step>(item => item.Name == pluginStep.Name);

            if (pluginAssemblyStepTemp == null)
            {
                pluginAssemblyStepTemp = new Step()
                {
                    Id = pluginStep.SdkMessageProcessingStepId.ToString(),
                    CustomConfiguration = pluginStep.Configuration,
                    Name                      = pluginStep.Name,
                    Description               = pluginStep.Description,
                    FilteringAttributes       = pluginStep.FilteringAttributes,
                    ImpersonatingUserFullname = pluginStep.ImpersonatingUserId == null ? string.Empty : pluginStep.ImpersonatingUserId.Name,
                    MessageName               = sdkMessage != null ? sdkMessage.CategoryName : null,
                    Mode                      = ((SdkMessageProcessingStep_Mode)pluginStep.Mode.Value).ToString(),
                    PrimaryEntityName         = filter.PrimaryObjectTypeCode,
                    Rank                      = pluginStep.Rank,
                    Stage                     = ((SdkMessageProcessingStep_Stage)pluginStep.Stage.Value).ToString(),
                    SupportedDeployment       = ((SdkMessageProcessingStep_SupportedDeployment)pluginStep.SupportedDeployment.Value).ToString(),
                    Images                    = new List <Image>()
                };
                MapImagesObject(images, pluginStep, pluginAssemblyStepTemp);
                pluginAssemblyTypeTemp.Steps.Add(pluginAssemblyStepTemp);
            }
        }
 public MetadataFilter(SdkMessageFilter filter)
 {
     Id = filter.Id;
     PrimaryObjectTypeCode   = filter.PrimaryObjectTypeCode;
     SecondaryObjectTypeCode = filter.SecondaryObjectTypeCode;
     IsVisible = filter.IsVisible;
 }
        private static void MapPluginAssemblyStepObject(SdkMessageProcessingStep pluginStep
                                                        , SdkMessage sdkMessage
                                                        , SdkMessageFilter filter
                                                        , List <SdkMessageProcessingStepImage> images
                                                        , Assembly pluginAssembly
                                                        , Type pluginType)
        {
            var step = MapStep(pluginStep, sdkMessage, filter);

            MapImagesObject(images, pluginStep, step);
            pluginType.Steps.Add(step);
        }
        public Dictionary <string, object> GenerateCrmEntities()
        {
            Dictionary <string, object> entityList = new Dictionary <string, object>();

            SdkMessageFilter entity = new SdkMessageFilter();

            entity["sdkmessagefilterid"]      = MessageEntityId;
            entity.SdkMessageId               = new EntityReference(SdkMessage.EntityLogicalName, MessageId);
            entity["primaryobjecttypecode"]   = PrimaryEntity;
            entity["secondaryobjecttypecode"] = SecondaryEntity;

            entityList.Add(SdkMessageFilter.EntityLogicalName, entity);

            return(entityList);
        }
        private static bool MapPluginObject(SdkMessageProcessingStep pluginStep
                                            , SdkMessage sdkMessage
                                            , SdkMessageFilter filter
                                            , List <SdkMessageProcessingStepImage> images
                                            , Assembly pluginAssemblyObject
                                            , PluginType pluginType
                                            )
        {
            var typeObject = MapPluginAssemblyTypeObject(pluginType, pluginAssemblyObject);

            if (pluginStep != null)
            {
                MapPluginAssemblyStepObject(pluginStep, sdkMessage, filter, images, pluginAssemblyObject, typeObject);
            }

            return(true);
        }
        public void RefreshFromSdkMessageFilter(SdkMessageFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }

            if (filter.SdkMessageFilterId != null)
            {
                MessageEntityId = filter.SdkMessageFilterId.Value;
            }

            if (filter.SdkMessageId != null)
            {
                MessageId = filter.SdkMessageId.Id;
            }

            if (!string.IsNullOrEmpty(filter.PrimaryObjectTypeCode))
            {
                PrimaryEntity = filter.PrimaryObjectTypeCode;
            }

            if (!string.IsNullOrEmpty(filter.SecondaryObjectTypeCode))
            {
                SecondaryEntity = filter.SecondaryObjectTypeCode;
            }

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

            if ((string.IsNullOrWhiteSpace(PrimaryEntity) || PrimaryEntity.Equals("none")) &&
                (string.IsNullOrWhiteSpace(SecondaryEntity) || SecondaryEntity.Equals("none")))
            {
                Availability = CrmPluginStepDeployment.Both;
            }
            else
            {
                Availability = (CrmPluginStepDeployment)Enum.ToObject(typeof(CrmPluginStepDeployment),
                                                                      filter.Availability.GetValueOrDefault());
            }

            CreatedOn  = filter.CreatedOn;
            ModifiedOn = filter.ModifiedOn;
        }
Exemplo n.º 8
0
        private static bool MapPluginObject(List <Assembly> pluginAssemblyList
                                            , PluginAssembly pluginAssembly
                                            , PluginType pluginType
                                            , SdkMessageProcessingStep pluginStep
                                            , SdkMessage sdkMessage
                                            , SdkMessageFilter filter
                                            , List <SdkMessageProcessingStepImage> images)
        {
            var pluginAssemblyTemp = MapPluginAssemblyObject(pluginAssemblyList, pluginAssembly);

            if (pluginAssemblyTemp == null)
            {
                return(false);
            }
            var pluginAssemblyTypeTemp = MapPluginAssemblyTypeObject(pluginType, pluginAssemblyTemp);

            if (pluginStep != null)
            {
                MapPluginAssemblyStepObject(pluginType, pluginStep, sdkMessage, filter, images, pluginAssemblyTemp, pluginAssemblyTypeTemp);
            }

            return(true);
        }
Exemplo n.º 9
0
        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 static Step MapStep(SdkMessageProcessingStep pluginStep, SdkMessage sdkMessage, SdkMessageFilter filter) => new Step()
 {
     Id = pluginStep.SdkMessageProcessingStepId,
     CustomConfiguration = pluginStep.Configuration,
     Name                      = pluginStep.Name,
     Description               = pluginStep.Description,
     FilteringAttributes       = pluginStep.FilteringAttributes,
     ImpersonatingUserFullname = pluginStep.ImpersonatingUserId?.Name ?? string.Empty,
     MessageName               = sdkMessage?.Name,
     Mode                      = pluginStep.ModeEnum,
     PrimaryEntityName         = filter.PrimaryObjectTypeCode,
     Rank                      = pluginStep.Rank,
     Stage                     = pluginStep.StageEnum,
     SupportedDeployment       = pluginStep.SupportedDeploymentEnum,
     Images                    = new List <Image>()
 };
        private static bool MapWebHookObject(List <ServiceEndpt> webHookList, ServiceEndpoint serviceEndpoint, SdkMessageProcessingStep steps, SdkMessage message, SdkMessageFilter filters)
        {
            var webHook = MapWebHook(serviceEndpoint);

            webHook.Steps.Add(MapStep(steps, message, filters));
            webHookList.Add(webHook);

            return(true);
        }
Exemplo n.º 12
0
 private static Step MapStep(SdkMessageProcessingStep pluginStep, SdkMessage sdkMessage, SdkMessageFilter filter) => new Step()
 {
     Id = pluginStep.SdkMessageProcessingStepId,
     CustomConfiguration = pluginStep.Configuration,
     Name                = pluginStep.Name,
     Description         = pluginStep.Description,
     FilteringAttributes = pluginStep.FilteringAttributes != null?string.Join(",", pluginStep.FilteringAttributes.Split(',').OrderBy(a => a)) : null,
                               ImpersonatingUserFullname = pluginStep.ImpersonatingUserId?.Name ?? string.Empty,
                               MessageName         = sdkMessage?.Name,
                               Mode                = pluginStep.ModeEnum,
                               PrimaryEntityName   = filter?.PrimaryObjectTypeCode,
                               Rank                = pluginStep.Rank,
                               Stage               = pluginStep.StageEnum,
                               AsyncAutoDelete     = pluginStep.AsyncAutoDelete,
                               SupportedDeployment = pluginStep.SupportedDeploymentEnum,
                               StateCode           = pluginStep.StateCode,
                               Images              = new List <Image>()
 };
        protected override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (Mode == CrmPluginStepMode.Asynchronous && Stage != CrmPluginStepStage.PostOperation)
            {
                throw new Exception("Asynchronous Execution Mode requires registration in one of the Post Stages. Please change the Mode or the Stage.");
            }
            if (!string.IsNullOrWhiteSpace(SecureConfig) && (Deployment == CrmPluginStepDeployment.OfflineOnly || Deployment == CrmPluginStepDeployment.Both))
            {
                throw new Exception("Secure Configuration is not supported for Steps deployed Offline.");
            }

            Entity crmEventSource = RetrieveEventSource(EventSource);

            if (crmEventSource == null)
            {
                throw new Exception(string.Format("No Plugin or ServiceEndpoint found with Id '{0}'.", EventSource));
            }

            SdkMessageFilter = RetrieveMessageFilter(Message, PrimaryEntity, SecondaryEntity);
            if (SdkMessageFilter == null)
            {
                throw new Exception(string.Format("No supported Steps found for '{0}' on entities {1} and {2}.", Message, PrimaryEntity, SecondaryEntity));
            }
            else
            {
                SdkMessage      = SdkMessageFilter.GetAttributeValue <EntityReference>("sdkmessageid");
                Message         = SdkMessage.Name;
                PrimaryEntity   = SdkMessageFilter.GetAttributeValue <string>("primaryobjecttypecode");
                SecondaryEntity = SdkMessageFilter.GetAttributeValue <string>("secondaryobjecttypecode");
            }

            int filterAvailability = SdkMessageFilter.GetAttributeValue <int>("availability");

            if (!IsDeploymentSupported(filterAvailability, Deployment))
            {
                throw new Exception(string.Format("The Step must be deployed '{0}'.", Enum.GetName(typeof(CrmPluginStepDeployment), filterAvailability)));
            }

            if (IsServiceEndpoint && Mode == CrmPluginStepMode.Synchronous)
            {
                throw new Exception("Only asynchronous Steps are supported for Service Endpoint plug-ins.");
            }

            string generatedDescription = string.Empty;

            if (IsServiceEndpoint)
            {
                generatedDescription = PluginManagementHelper.GenerateStepDescription(crmEventSource.GetAttributeValue <string>("name"), Message, PrimaryEntity, SecondaryEntity);
            }
            else
            {
                generatedDescription = PluginManagementHelper.GenerateStepDescription(crmEventSource.GetAttributeValue <string>("typename"), Message, PrimaryEntity, SecondaryEntity);
            }
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = generatedDescription;
            }
            if (string.IsNullOrWhiteSpace(Description))
            {
                Description = generatedDescription;
            }

            Guid secureConfigId = Guid.Empty;

            if (!string.IsNullOrWhiteSpace(SecureConfig))
            {
                secureConfigId = _repository.Add("sdkmessageprocessingstepsecureconfig", Guid.Empty, new System.Collections.Hashtable()
                {
                    { "secureconfig", SecureConfig }
                });
            }

            Guid newId = _repository.Add(GenerateCrmEntity(secureConfigId));

            if (PassThru)
            {
                WriteObject(_repository.Get("sdkmessageprocessingstep", newId));
            }
        }
 public CrmMessageEntity(CrmOrganization org, SdkMessageFilter filter)
     : this(org)
 {
     RefreshFromSdkMessageFilter(filter);
 }
Exemplo n.º 15
0
 public EntityViewItem(SdkMessageFilter entity)
 {
     this.SdkMessageFilter = entity;
 }