public static ISqlContent Subcommand(this IProjection projection, string commandName)
        {
            ISchema             resultSchema   = projection.Context.Domain.Schemas.GetSchema(typeof(object));
            IProjectionMetadata resultMetadata = resultSchema.Require <IProjectionMetadata>();
            ProjectionIdentity  resultIdentity = new ProjectionIdentity(resultSchema);

            IProjection modelProjection  = projection;
            IProjection resultProjection = new Projection(resultIdentity, projection.Context, resultMetadata);

            return(projection.Context.Renderer.Partial(commandName, modelProjection, resultProjection));
        }
        public ProcLookupKey(string prefix, ProjectionIdentity identity, MetadataIdentity metadata, IField field)
        {
            this.Prefix   = prefix;
            this.Identity = identity;
            this.Metadata = metadata;
            this.Field    = field;
            this.HasValue = (identity != null || metadata != null || field != null);

            if (string.IsNullOrWhiteSpace(this.Prefix))
            {
                throw new ArgumentException("Prefix cannot be empty.");
            }
        }
        public static ISqlContent Subquery(this IProjection projection, string queryName, object model = null)
        {
            ISchema             modelSchema   = projection.Context.Domain.Schemas.GetSchema(model?.GetType() ?? typeof(object));
            IProjectionMetadata modelMetadata = modelSchema.Require <IProjectionMetadata>();
            IField field = new Model(modelSchema, model);

            ProjectionIdentity modelIdentity = new ProjectionIdentity(field);

            IProjection modelProjection  = new Projection(modelIdentity, projection.Context, modelMetadata);
            IProjection resultProjection = projection;

            return(projection.Context.Renderer.Partial(queryName, modelProjection, resultProjection));
        }
        public virtual IProjection <TModel> GetProjection <TModel>(IProcContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ISchema             schema   = context.Domain.Schemas.GetSchema(typeof(IList <TModel>));
            IProjectionMetadata metadata = schema.Require <IProjectionMetadata>();

            ProjectionIdentity identity = new ProjectionIdentity(schema);

            return(new Projection <TModel>(identity, context, metadata.Item ?? metadata));
        }
Example #5
0
        public void Write <T>(T value)
        {
            if (value is ISqlWritable w)
            {
                w.WriteTo(this.Context.Execution.Buffer);
            }
            else
            {
                IField model = this.Context.Domain.Schemas.From(value);

                ProjectionIdentity  identity   = new ProjectionIdentity(model);
                IProjectionMetadata metadata   = model.Identity.Schema.Require <IProjectionMetadata>();
                Projection          projection = new Projection(identity, this.Context, metadata);

                this.Write(projection.Par());
            }
        }
Example #6
0
        public void Write <T>(T value)
        {
            if (value is ISqlWritable w)
            {
                w.WriteTo(this.Context.Execution.Buffer);
            }
            else
            {
                ISchema schema = this.Context.Domain.Schemas.GetSchema(typeof(T));
                IField  field  = new Relation(value, schema);

                ProjectionIdentity identity   = new ProjectionIdentity(schema, field);
                Projection         projection = new Projection(identity, this.Context);

                this.Write(projection.Par());
            }
        }
Example #7
0
        public virtual IProjection <TModel> GetProjection <TModel>(IProcContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ISchema             schema   = context.Domain.Schemas.GetSchema(typeof(IList <TModel>));
            IProjectionMetadata metadata = schema.GetMetadata <IProjectionMetadata>();

            if (metadata == null)
            {
                throw new ProjectionException("Unable to locate projection metadata for model.");
            }

            ProjectionIdentity identity = new ProjectionIdentity(schema);

            return(new Projection <TModel>(identity, context, metadata.Item ?? metadata));
        }
Example #8
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);
        }
Example #9
0
 public string Variable(ProjectionIdentity identity, IField field) => this.Custom("V", identity, field: field);
Example #10
0
 public string Table(ProjectionIdentity identity, MetadataIdentity metadata) => this.Custom("T", identity, metadata);
Example #11
0
 public string Parameter(ProjectionIdentity identity, MetadataIdentity metadata) => this.Custom("P", identity, metadata: metadata);
Example #12
0
 public string Parameter(ProjectionIdentity identity, IField field) => this.Custom("P", identity, field: field);
Example #13
0
 public string Custom(string prefix, ProjectionIdentity identity = null, MetadataIdentity metadata = null, IField field = null) => this.FromKey(new ProcLookupKey(prefix, identity, metadata, field));