Esempio n. 1
0
        public static Specification <TFact, TProjection> Match <TProjection>(Expression <Func <TFact, FactRepository, IQueryable <TProjection> > > specExpression)
        {
            var    spec      = specExpression.Compile();
            object proxy     = SpecificationParser.InstanceOfFact(typeof(TFact));
            var    label     = new Label(specExpression.Parameters[0].Name, specExpression.Parameters[0].Type.FactTypeName());
            var    context   = SpecificationContext.Empty.With(label, proxy, specExpression.Parameters[0].Type);
            var    queryable = (JinagaQueryable <TProjection>)spec((TFact)proxy, new FactRepository());

            var result        = SpecificationParser.ParseSpecification(SymbolTable.Empty, context, queryable.Expression);
            var specification = SpecificationGenerator.CreateSpecification(context, result);

            return(new Specification <TFact, TProjection>(specification.Pipeline, specification.Projection));
        }
Esempio n. 2
0
        public static Specification <TFact, TProjection> Match <TProjection>(Expression <Func <TFact, TProjection> > spec)
        {
            var    parameter       = spec.Parameters[0];
            var    initialFactName = parameter.Name;
            var    initialFactType = parameter.Type.FactTypeName();
            object proxy           = SpecificationParser.InstanceOfFact(typeof(TFact));
            var    label           = new Label(initialFactName, initialFactType);
            var    context         = SpecificationContext.Empty.With(label, proxy, parameter.Type);
            var    startingSet     = new SetDefinitionInitial(label, parameter.Type);
            var    symbolTable     = SymbolTable.Empty.With(initialFactName, new SymbolValueSetDefinition(startingSet));

            var symbolValue   = ValueParser.ParseValue(symbolTable, context, spec.Body).symbolValue;
            var result        = SpecificationParser.ParseValue(symbolValue);
            var specification = SpecificationGenerator.CreateSpecification(context, result);

            return(new Specification <TFact, TProjection>(specification.Pipeline, specification.Projection));
        }
Esempio n. 3
0
 private static Pipeline AppendToPipeline(Pipeline pipeline, SpecificationContext context, SetDefinition setDefinition, SpecificationResult result)
 {
     if (setDefinition is SetDefinitionPredecessorChain predecessorChainSet)
     {
         var chain = predecessorChainSet.ToChain();
         var targetSetDefinition = chain.TargetSetDefinition;
         var start  = targetSetDefinition.Label;
         var target = new Label(predecessorChainSet.Role, chain.TargetFactType);
         var path   = new Path(start, target);
         return(pipeline.AddPath(AddPredecessorSteps(path, chain)));
     }
     else if (setDefinition is SetDefinitionJoin joinSet)
     {
         var head = joinSet.Head;
         var tail = joinSet.Tail;
         var sourceSetDefinition = head.TargetSetDefinition;
         var source = sourceSetDefinition.Label;
         var target = joinSet.Label;
         var path   = new Path(source, target);
         return(pipeline.AddPath(PrependSuccessorSteps(AddPredecessorSteps(path, head), tail)));
     }
     else if (setDefinition is SetDefinitionConditional conditionalSet)
     {
         var targetSetDefinition = conditionalSet.Source;
         var start         = targetSetDefinition.Label;
         var childPipeline = CreatePipeline(
             SpecificationContext.Empty
             .With(start, SpecificationParser.InstanceOfFact(targetSetDefinition.Type), targetSetDefinition.Type),
             conditionalSet.Condition.SpecificationResult);
         var conditional = new Conditional(start, conditionalSet.Condition.Exists, childPipeline);
         return(pipeline.AddConditional(conditional));
     }
     else
     {
         throw new NotImplementedException();
     }
 }