Пример #1
0
        public void Push(IPageExecutionContext context)
        {
            IPageExecutionContext currentContext = this.stack.FirstOrDefault();

            PageExecutionContext newContext = new PageExecutionContext()
            {
                Page   = context.Page ?? currentContext?.Page,
                Buffer = context.Buffer ?? currentContext?.Buffer,
                Body   = context.Body ?? currentContext?.Body,
            };

            this.stack.Push(newContext);
        }
Пример #2
0
        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);
        }