private void AddRuleSignatureExtension(RulePoint rulePoint, IRuleSignatureExtension signatureExtension) { RuleSignature signature = rulePoint.Signature; if (null != signature) { signature.AddExtension(signatureExtension); } foreach (RuleBase rule in rulePoint.Children) { if (rule is RulePoint) { AddRuleSignatureExtension((rule as RulePoint), signatureExtension); } } }
/// <summary> /// Initializes a new instance of Autodesk.IM.Rule.RulePoint with specified owner, /// name, signature, display name. /// </summary> /// <param name="owner">An object of RuleManager which owns this rule point.</param> /// <param name="name">The specified rule point's name.</param> /// <param name="signature">The specified rule point's signature.</param> /// <param name="displayName">The rule point's display name.</param> public RulePoint(RuleManager owner, string name = "", RuleSignature signature = null, string displayName = null) { // Fix defect 20970 <https://fogbugzaec.autodesk.com/default.asp?20970> - When a Catalog // Category contains slash "/", adding a material rule causes crash. // Because the name will be used for Autodesk.UtilityDesign.UI.Rule.RuleBaseContext.Path, // so if it contains the character "/", that will result in an invalid path. // Solution: Replace character "/" with its url encoding "%2F". // Note that we don't need to decode this change. The Name property is only used for identifying // the RulePoint, and the DisplayName property is what actually gets displayed in the UI. if (name.Contains("/")) { name = name.Replace("/", "%2F"); } _owner = owner; _name = name; _displayName = displayName; _signature = signature; }
/// <summary> /// Initializes arguments including system input arguments and extended arguments. /// /// Initialization of extended arguments are based on original input arguments and rule's activity. /// This method checks rule's activity first to find out the extended arguments which are really used. /// /// When the extended argument exists in the input argument list, use it immediately. /// If not, retrieve the argument from rule extensions. /// </summary> /// <param name="rule">The specified rule for initialization of arguments.</param> /// <param name="originalArguments">The original input arguments.</param> private void InitializeArguments(IRule rule, IDictionary <string, object> originalArguments) { DynamicActivity da = rule.Activity; RuleSignature signature = rule.Signature; var properties = da.Properties; Dictionary <RuleArgument, object> arguments = new Dictionary <RuleArgument, object>(); // Add system input arguments foreach (RuleArgument arg in signature.SystemInArguments) { string argumentName = arg.Name; if (properties.Contains(argumentName)) { if (originalArguments.ContainsKey(argumentName)) { arguments.Add(arg, originalArguments[argumentName]); } else { // Comment this because there are so many assert triggered // Ideally, the assert should be triggered when the system input arguments // are absent, however existing code cannot make sure it, and fixing it // requires a lot of effort. Considering limitation of time and the stage // we are in, we comment it out and give default value or null when input // arguments are not given. //Debug.Assert(false, "Some system input arguments are missing."); //NOXLATE Type type = arg.ArgumentType; if (type.IsValueType) { arguments.Add(arg, Activator.CreateInstance(type)); } else { arguments.Add(arg, null); } } } } // Initialize extended arguments. foreach (IRuleSignatureExtension extension in signature.Extensions) { foreach (RuleArgument arg in extension.GetSystemInArguments()) { string argumentName = arg.Name; if (properties.Contains(argumentName)) // Require this argument. { if (originalArguments.ContainsKey(argumentName)) { // Use caller-provided argument arguments.Add(arg, originalArguments[argumentName]); } else { // Use default argument provided by rule extension. extension.AddDefaultArgument(arg, arguments); } } } } Arguments = arguments; }
/// <summary> /// Registers a new rule point with specified position. /// </summary> /// <param name="parentPath">A string representing the position where the rule point goes.</param> /// <param name="name">The name of rule point.</param> /// <param name="displayName">The display name of rule point.</param> /// <param name="signature">The signature of rule point.</param> public void RegisterRulePoint(string parentPath, string name, string displayName, RuleSignature signature) { RulePoint rulePoint = new RulePoint(this, name, signature, displayName); // Create rule points recursively. RulePoint iter = RootRulePoint; string[] pathItems = RulePathHelper.GetRulePathComponents(parentPath); foreach (string item in pathItems) { if (!iter.HasChild(item)) { iter.AddRulePoint(new RulePoint(this, item)); } iter = iter.GetSubRulePoint(item); if (iter == null) { throw new InvalidOperationException(Properties.Resources.CannotRegisterRulePoint); } } iter.AddRulePoint(rulePoint); }