/// <summary> /// Initializes a new instance of the <see cref="BuiltInRuleDialogViewModel"/> class. /// </summary> /// <param name="builtInRule"> /// The <see cref="IBuiltInRule"/> that is represented by the current <see cref="BuiltInRuleDialogViewModel"/> /// </param> public BuiltInRuleDialogViewModel(IBuiltInRule builtInRule) { this.SetProperties(builtInRule); this.CloseCommand = ReactiveCommand.Create(); this.CloseCommand.Subscribe(_ => this.ExecuteClose()); }
/// <summary> /// Initializes a new instance of the <see cref="BuiltInRuleRowViewModel"/> class. /// </summary> /// <param name="rule"> /// The <see cref="BuiltInRule"/> that is represented by the current row view-model. /// </param> /// <param name="metaData"> /// The <see cref="IBuiltInRuleMetaData"/> that provides the meta-data for the <see cref="BuiltInRule"/> /// that is represented by the current row view-model. /// </param> public BuiltInRuleRowViewModel(IBuiltInRule rule, IBuiltInRuleMetaData metaData) { if (rule == null) { throw new ArgumentNullException(nameof(rule), "The rule shall not be null"); } if (metaData == null) { throw new ArgumentNullException(nameof(metaData), "The metaData shall not be null"); } this.Rule = rule; this.metaData = metaData; }
/// <summary> /// Registers a <see cref="builtInRule"/> with the service /// </summary> /// <param name="builtInRule"> /// The <see cref="BuiltInRule"/> to register /// </param> /// <param name="metaData"> /// The <see cref="IBuiltInRuleMetaData"/> that describes the <see cref="BuiltInRule"/> /// </param> public void Register(IBuiltInRule builtInRule, IBuiltInRuleMetaData metaData) { var ruleName = metaData.Name; var registration = new Lazy <IBuiltInRule, IBuiltInRuleMetaData>(() => builtInRule, metaData); if (this.builtInRules.ContainsKey(ruleName)) { var ruleAuthor = metaData.Author; var ruleDescription = metaData.Description; logger.Warn("A BuiltInRule with name:{0}, by author:{1} with description:{2}, has already been registered.", ruleName, ruleAuthor, ruleDescription); } else { this.builtInRules.Add(ruleName, registration); } }
/// <summary> /// Queries the <see cref="IBuiltInRuleMetaData"/> from the provided <see cref="IBuiltInRule"/> /// </summary> /// <param name="rule"> /// The <see cref="IBuiltInRule"/> that is queried /// </param> /// <remarks> /// The <paramref name="rule"/> must be a class that derives from the abstract <see cref="BuiltInRule"/> class. /// </remarks> private void SetProperties(IBuiltInRule rule) { var builtInRule = rule as BuiltInRule; if (builtInRule == null) { return; } this.SetLibraryProperties(builtInRule); var t = builtInRule.GetType(); var attributes = Attribute.GetCustomAttributes(t).OfType <IBuiltInRuleMetaData>(); var builtInRuleMetaData = attributes.SingleOrDefault(); if (builtInRuleMetaData != null) { this.SetMetaDataProperties(builtInRuleMetaData); } }