/// <summary> /// Gets the rules categorized with specified <paramref name="contentType" /> between <paramref name="dateBegin" /> and <paramref name="dateEnd" />. /// </summary> /// <param name="contentType">the content type categorization.</param> /// <param name="dateBegin">the filtering begin date.</param> /// <param name="dateEnd">the filtering end date.</param> /// <returns></returns> public async Task <IEnumerable <Rule <TContentType, TConditionType> > > GetRulesAsync(TContentType contentType, DateTime dateBegin, DateTime dateEnd) { FilterDefinition <RuleDataModel> getRulesByContentTypeAndDatesInterval = MongoDbProviderRulesDataSource <TContentType, TConditionType> .BuildFilterByContentTypeAndDatesInterval(contentType, dateBegin, dateEnd); return(await this.GetRulesAsync(getRulesByContentTypeAndDatesInterval).ConfigureAwait(false)); }
/// <summary> /// Sets the rules engine data source from a Mongo DB database. /// </summary> /// <typeparam name="TContentType">The type of the content type.</typeparam> /// <typeparam name="TConditionType">The type of the condition type.</typeparam> /// <param name="rulesDataSourceSelector">The rules data source selector.</param> /// <param name="mongoClient">The mongo client.</param> /// <param name="mongoDbProviderSettings">The mongo database provider settings.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"> /// rulesDataSourceSelector /// or /// mongoClient /// or /// mongoDbProviderSettings /// </exception> public static IConfiguredRulesEngineBuilder <TContentType, TConditionType> SetMongoDbDataSource <TContentType, TConditionType>( this IRulesDataSourceSelector <TContentType, TConditionType> rulesDataSourceSelector, IMongoClient mongoClient, MongoDbProviderSettings mongoDbProviderSettings) { if (rulesDataSourceSelector is null) { throw new ArgumentNullException(nameof(rulesDataSourceSelector)); } if (mongoClient is null) { throw new ArgumentNullException(nameof(mongoClient)); } if (mongoDbProviderSettings is null) { throw new ArgumentNullException(nameof(mongoDbProviderSettings)); } IContentSerializationProvider <TContentType> contentSerializationProvider = new DynamicToStrongTypeContentSerializationProvider <TContentType>(); IRuleFactory <TContentType, TConditionType> ruleFactory = new RuleFactory <TContentType, TConditionType>(contentSerializationProvider); MongoDbProviderRulesDataSource <TContentType, TConditionType> mongoDbProviderRulesDataSource = new MongoDbProviderRulesDataSource <TContentType, TConditionType>( mongoClient, mongoDbProviderSettings, ruleFactory); return(rulesDataSourceSelector.SetDataSource(mongoDbProviderRulesDataSource)); }
/// <summary> /// Gets the rules filtered by specified arguments. /// </summary> /// <param name="rulesFilterArgs">The rules filter arguments.</param> /// <returns></returns> public Task <IEnumerable <Rule <TContentType, TConditionType> > > GetRulesByAsync(RulesFilterArgs <TContentType> rulesFilterArgs) { if (rulesFilterArgs is null) { throw new ArgumentNullException(nameof(rulesFilterArgs)); } FilterDefinition <RuleDataModel> filterDefinition = MongoDbProviderRulesDataSource <TContentType, TConditionType> .BuildFilterFromRulesFilterArgs(rulesFilterArgs); return(this.GetRulesAsync(filterDefinition)); }