Пример #1
0
        private bool SkipPluginValidation(ICrmContext crmContext, ILogging logging)
        {
            logging.Write("ThinkCrmPlugin: SkipPluginValidation Executed");

            var attrs = System.Attribute.GetCustomAttributes(this.GetType());

            if (!attrs.OfType<SkipValidationAttribute>().Any()) return logging.WriteAndReturn(false, "ThinkCrmPlugin: No SkipValidationAttribute Attribute Found");

            var skipBool = attrs.OfType<SkipValidationAttribute>().First().SkipValidation;

            return logging.WriteAndReturn(skipBool, "ThinkCrmPlugin: SkipPluginValidation Attribute Found, Skip={0}", skipBool.ToString());
        }
Пример #2
0
        private bool ExceedsMaxDepth(int pluginDepth, ILogging logging)
        {
            logging.Write("ThinkCrmPlugin: ExceedsMaxDepth Executed");

            var attrs = System.Attribute.GetCustomAttributes(this.GetType());

            if (!attrs.OfType<MaxDepthAttribute>().Any()) return logging.WriteAndReturn(false, "ThinkCrmPlugin: No MaxDepth Attribute Found");

            var maxAllowedDepth = attrs.OfType<MaxDepthAttribute>().First().MaxDepth;

            logging.Write("ThinkCrmPlugin: MaxDepth Attribute Found, MaxDepth Allowed={0} Actual Depth={1}",maxAllowedDepth, pluginDepth);

            return pluginDepth > maxAllowedDepth;
        }
Пример #3
0
        private ReturnOnErrorAttribute GetErrorRules(ILogging logging)
        {
            logging.Write("ThinkCrmPlugin: GetErrorRules Executed");

            var attrs = System.Attribute.GetCustomAttributes(this.GetType());

            if (!attrs.OfType<ReturnOnErrorAttribute>().Any()) return logging.WriteAndReturn(new ReturnOnErrorAttribute(), "ThinkCrmPlugin: No MaxDepth Attribute Found, Using Defaults");

            var errorRules = (ReturnOnErrorAttribute) attrs.First();

            return logging.WriteAndReturn(errorRules,
                "ThinkCrmPlugin: Found ReturnOnError Attribute ReturnOnPluginError={0} / ReturnOnPluginValiationError={1} / ReturnOnUnhandledError={2} ",
                errorRules.ReturnOnPluginError.ToString(), errorRules.ReturnOnPluginValidationError.ToString(),
                errorRules.ReturnOnUnhandledError.ToString());
        }
Пример #4
0
        protected virtual bool ValidatePluginExecution(ICrmContext crmContext, ILogging logging, out string keyName)
        {
            logging.Write("ThinkCrmPlugin: Default ValidatePluginExecution Executed");

            var attrs = System.Attribute.GetCustomAttributes(this.GetType());

            var preImageName = crmContext.PluginExecutionContext.PreEntityImages.Count > 0
                ? crmContext.PluginExecutionContext.PreEntityImages.First().Key : string.Empty;
            var preImage = crmContext.PluginExecutionContext.PreEntityImages.Count > 0
                ? crmContext.PluginExecutionContext.PreEntityImages.First().Value
                : null;

            var postImageName = crmContext.PluginExecutionContext.PostEntityImages.Count > 0
                ? crmContext.PluginExecutionContext.PostEntityImages.First().Key
                : string.Empty;
            var postImage = crmContext.PluginExecutionContext.PostEntityImages.Count > 0
                ? crmContext.PluginExecutionContext.PostEntityImages.First().Value
                : null;

            foreach (var pAtt in attrs.OfType<PluginRegistrationAttribute>().Select(att => att as PluginRegistrationAttribute))
            {
                logging.Write("ThinkCrmPlugin: Validating Key Name: {0}", pAtt.KeyName);
                if (pAtt.MatchesExecutingPlugin(crmContext.Message, crmContext.PluginExecutionContext.PrimaryEntityName,
                    crmContext.PluginExecutionContext.SecondaryEntityName, crmContext.PipelineStage,
                    crmContext.ExecutionMode, crmContext.PluginExecutionContext.IsExecutingOffline, preImageName,
                    preImage, postImageName, postImage))
                {
                    keyName = pAtt.KeyName;
                    logging.WriteAndReturn(true, "ThinkCrmPlugin: Validated Key Name: {0}", keyName);
                }
                else
                {
                    logging.Write("ThinkCrmPlugin: Validation Failed for Key Name: {0}", pAtt.KeyName);
                }

            }

            logging.Write("ThinkCrmPlugin: No PluginRegistrationAttribute was Validated");
            keyName = string.Empty;
            return false;
        }