/// <summary> /// Initializes a new instance of the PSEventRuleCondition class /// </summary> /// <param name="ruleCondition">The rule condition</param> public PSLocationThresholdRuleCondition(LocationThresholdRuleCondition ruleCondition) { var dataSource = ruleCondition.DataSource as RuleMetricDataSource; if (dataSource != null) { this.DataSource = dataSource; } else { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, ResourcesForAlertCmdlets.RuleDataSourceTypeNotSupported, ruleCondition.DataSource.GetType().Name)); } this.FailedLocationCount = ruleCondition.FailedLocationCount; this.WindowSize = ruleCondition.WindowSize; }
private RuleCondition CreateRuleCondition() { // Since WindowSize is not mandatory, but it cannot be null (TimeSpan) checking for default value if (this.WindowSize == default(TimeSpan)) { this.WindowSize = DefaultWindowSize; } RuleCondition condition; switch (this.RuleType) { case AlertRuleTypes.Event: condition = this.CreateEventRuleCondition(); break; case AlertRuleTypes.Metric: condition = this.CreateThresholdRuleCondition(); break; case AlertRuleTypes.Webtest: condition = new LocationThresholdRuleCondition() { DataSource = new RuleMetricDataSource(), FailedLocationCount = this.FailedLocationCount, WindowSize = this.WindowSize, }; break; default: throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, ResourcesForAlertCmdlets.RuleTypeNotSupported, this.RuleType)); } return condition; }