コード例 #1
0
        private PageFactory CreatePageFactory(Type pageType)
        {
            Type resultType = this.GetResultTypeFromPage(pageType);
            Type modelType  = this.GetModelTypeFromPage(pageType);

            if (resultType == null || modelType == null)
            {
                throw new InvalidOperationException("Type must inherit ProcPage<TModel, TResult>.");
            }

            PageConstructor constructor = this.CreatePageConstructor(pageType);

            void pageFactory(IProjection model, IProjection result)
            {
                IProjection newModel  = this.GetProjectionForPartialModel(model, modelType);
                IProjection newResult = this.GetProjectionForPartialResult(result, resultType);

                ISqlPage page = constructor(newModel, newResult);

                page.Execute();
            }

            return(pageFactory);
        }
コード例 #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);
        }