private ProcFactory CreateProcFactory(PageDescriptor descriptor, ProcArgs args) { IDomainOptions options = this.Options(descriptor.DomainType); PageDescriptor[] template = this.GetTemplateHierarchy(descriptor).Reverse().ToArray(); PageConstructor[] factories = template.Select(t => this.CreatePageConstructor(t.PageType)).Concat(new PageConstructor[1]).ToArray(); IProjectionMetadata resultMetadata = this.GetMetadataForResult(descriptor, args, options); IProjectionMetadata modelMetadata = this.GetMetadataForModel(descriptor, args, options); ISchema resultSchema = resultMetadata.Identity.Schema; ISchema modelSchema = modelMetadata.Identity.Schema; IProcLocator locator = descriptor.Locator; Type originType = descriptor.OriginType; IProcResult procFactory(object model) { ProcContext context = this.CreateContext(descriptor); ProjectionIdentity modelIdentity = new ProjectionIdentity(new Model(modelSchema, model)); ProjectionIdentity resultIdentity = new ProjectionIdentity(resultSchema); IProjection modelProjection = new Projection(modelIdentity, context, modelMetadata); IProjection resultProjection = new Projection(resultIdentity, context, resultMetadata); PageExecutionContext[] execution = template.Select(t => new PageExecutionContext() { Page = t }).ToArray(); execution[0].Buffer = new ProcBuffer(); for (int i = 0; i < execution.Length; i++) { PageConstructor nextFactory = factories[i + 1]; if (nextFactory != null) { PageExecutionContext nextContext = execution[i + 1]; execution[i].Body = () => { ISqlPage bodyPage = nextFactory(modelProjection, resultProjection); context.Stack.Push(nextContext); bodyPage.Execute(); context.Stack.Pop(); }; } } ISqlPage page = factories[0](modelProjection, resultProjection); context.Stack.Push(execution[0]); page.Execute(); return(new ProcResult() { Buffer = context.Execution.Buffer, Domain = options, }); } return(procFactory); }
public ProcRenderer(ProcContext context) { this.Context = context ?? throw new ArgumentNullException(nameof(context)); }