public PageDescriptor(Type pageType, Type domainType, Type originType = null, IProcLocator locator = null) { this.PageType = pageType ?? throw new ArgumentNullException(nameof(pageType)); this.DomainType = domainType ?? throw new ArgumentNullException(nameof(domainType)); this.OriginType = originType ?? pageType; this.Locator = locator; }
private IProcResult ExecuteAndGetResult(string procName, object model, ProcArgs args) { IProcLocator locator = this.Context?.Locator ?? new ProcLocator(); IProcEngine engine = this.Context?.Engine ?? new ProcEngine(null); PageDescriptor descriptor = locator.FindPage(procName, this.GetType()); ProcFactory factory = engine.Proc(descriptor, args); return(factory(model)); }
public string Sql <TModel, TResult>(Runnable <TModel, TResult> model) { IProcLocator locator = this.Context?.Locator ?? new ProcLocator(); IProcEngine engine = this.Context?.Engine ?? new ProcEngine(null); PageDescriptor descriptor = locator.FindPage("Query", this.GetType()); ProcArgs args = new ProcArgs(typeof(Runnable <TModel, TResult>), typeof(List <TResult>)); ProcFactory factory = engine.Proc(descriptor, args); return(factory(model).Buffer.ReadToEnd().Text.Trim()); }
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 AccessorContext(IProcLocator locator, IProcEngine engine) { this.Locator = locator ?? throw new ArgumentNullException(nameof(locator)); this.Engine = engine ?? throw new ArgumentNullException(nameof(engine)); }