/// <summary> /// Creates and initializes a IEntityScriptingService from a list of expressions. /// </summary> /// <param name="expressions">Expressions to evaluated.</param> /// <param name="initialAttributes">The initial values to be use for dynamic properties /// if not already present on the entity.</param> /// <typeparam name="TEntity">The entity type associated with the list of expressions.</typeparam> /// <returns>The created service.</returns> public static IEntityScriptingService CreateService <TEntity>(this IList <EntityExpression> expressions, IDictionary <string, object> initialAttributes = null) where TEntity : IAttributedEntity { if (expressions == null) { throw new ArgumentNullException(nameof(expressions)); } var es = new EntityScript( Guid.NewGuid().ToString(), "default", typeof(TEntity).AssemblyQualifiedName, new ReadOnlyCollection <EntityExpression>(expressions)); es.ImportedAssemblies = new[] { typeof(Common.Extensions.ObjectExtensions).GetTypeInfo().Assembly.FullName }; es.ImportedNamespaces = new[] { typeof(Common.Extensions.ObjectExtensions).Namespace }; if (initialAttributes != null) { es.InitialAttributes = initialAttributes; } var loggerFactory = new LoggerFactory(); var evalSrv = new EntityScriptingService(loggerFactory); evalSrv.Load(new[] { es }); return(evalSrv); }
// Creates a configured evaluation service with a single expression. private static IEntityScriptingService CreateEvalService() { var expressions = new List <EntityExpression>(); expressions.AddExpression("IsImportant", "Entity.RuleTestValue > 5000"); var es = new EntityScript( Guid.NewGuid().ToString(), "test-script", typeof(MockDomainEvent).AssemblyQualifiedName, new ReadOnlyCollection <EntityExpression>(expressions)); var loggerFactory = new LoggerFactory(); var evalSrv = new EntityScriptingService(loggerFactory); evalSrv.Load(new EntityScript[] { es }); return(evalSrv); }
public static IEntityScriptingService CreateService <T>(this IList <EntityExpression> expressions) where T : IAttributedEntity { var es = new EntityScript( Guid.NewGuid().ToString(), "default", typeof(T).AssemblyQualifiedName, new ReadOnlyCollection <EntityExpression>(expressions)); es.ImportedAssemblies = new[] { typeof(NetFusion.Common.Extensions.ObjectExtensions).Assembly.FullName }; es.ImportedNamespaces = new[] { typeof(NetFusion.Common.Extensions.ObjectExtensions).Namespace }; var loggerFactory = new LoggerFactory(); var evalSrv = new EntityScriptingService(loggerFactory); evalSrv.Load(new [] { es }); return(evalSrv); }