Example #1
0
        public void ParsePluginCode()
        {
            var parser = new CodeParser(TestCode.DecoratedPlugin);

            Assert.AreEqual(parser.PluginCount, 1);

            // find existing attributes and remove
            Assert.AreEqual(2, parser.RemoveExistingAttributes());

            // Remove Attributes again - none should be removed
            Assert.AreEqual(0, parser.RemoveExistingAttributes());

            var attribute = new CrmPluginRegistrationAttribute(
                MessageNameEnum.Update, "account", StageEnum.PostOperation, ExecutionModeEnum.Synchronous,
                "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
            };

            var className = "TestPlugin.Plugins.PreValidateaccountUpdate";

            Assert.AreEqual(true, parser.ClassNames.Contains(className));
            // Add in a new attribute
            parser.AddAttribute(attribute, className);
            parser.AddAttribute(attribute, className);

            // Remove Attributes again - 2 should be removed
            Assert.AreEqual(2, parser.RemoveExistingAttributes());
        }
Example #2
0
        public void RemoveExistingAttributes()
        {
            var parser = new CodeParser(TestCode.CodeSnipToRemoveAdd);

            parser.RemoveExistingAttributes();

            // Check no spaces are left between class and comments
            var correct1 = @"    /// </summary>    
    public class Testplugin : Plugin";
            var contains = parser.Code.Contains(correct1);

            Debug.WriteLine(parser.Code);
            Assert.IsTrue(contains, "Incorrect spaces after remove");

            var attribute = new CrmPluginRegistrationAttribute(
                MessageNameEnum.Update, "account", StageEnum.PostOperation, ExecutionModeEnum.Synchronous,
                "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
            };

            parser.AddAttribute(attribute, "TestPlugins.Testplugin");

            Debug.WriteLine(parser.Code);

            var correct2  = @"    [CrmPluginRegistration(""Update"", 
    ""account"", StageEnum.PostOperation, ExecutionModeEnum.Synchronous,
    ""name,address1_line1"",""Delete of account"", 1, 
    IsolationModeEnum.Sandbox 
    ,Image1Type = ImageTypeEnum.PreImage
    ,Image1Name = ""PreImage""
    ,Image1Attributes = ""name,address1_line1""
    ,Image2Type = ImageTypeEnum.PostImage
    ,Image2Name = ""PostImage""
    ,Image2Attributes = ""name,address1_line1"" 
    )]
    public class Testplugin : Plugin";
            var contains2 = parser.Code.Contains(correct2);

            Assert.IsTrue(contains2, "Incorrect spaces after insert");

            parser.RemoveExistingAttributes();
            var contains3 = parser.Code.Contains(correct1);

            Assert.IsTrue(contains, "Incorrect spaces after remove again");

            parser.AddAttribute(attribute, "TestPlugins.Testplugin");

            var contains4 = parser.Code.Contains(correct2);

            Assert.IsTrue(contains2, "Incorrect spaces after insert again");
        }
Example #3
0
        private void AddWorkflowActivityAttributes(OrganizationServiceContext ctx, CodeParser parser, string pluginType)
        {
            // If so, search CRM for matches
            var steps = ctx.GetWorkflowPluginActivities(pluginType);

            if (steps != null)
            {
                _trace.WriteLine("Found Workflow Activity Type Registration {0}", pluginType);
                // Get the activities
                foreach (var activity in steps)
                {
                    // Create attribute
                    CrmPluginRegistrationAttribute attribute = new CrmPluginRegistrationAttribute(
                        activity.Name,
                        activity.FriendlyName,
                        activity.Description,
                        activity.WorkflowActivityGroupName,
                        activity.pluginassembly_plugintype.IsolationMode.Value == 2 ? IsolationModeEnum.Sandbox : IsolationModeEnum.None
                        )
                    ;
                    // Add attribute
                    parser.AddAttribute(attribute, activity.TypeName);
                }
            }
        }
Example #4
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);
                }
            }
        }