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()); }
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; }
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()); }
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; }