Beispiel #1
0
 private async Task <SourceUnit> GenerateHandler(ProcedureDescriptor proc, ProcedureBinding procBinding)
 {
     if (procBinding.Mode == Mode.Command)
     {
         return(await GenerateCommandHandler(proc, procBinding));
     }
     else if (procBinding.Mode == Mode.Query)
     {
         return(await GenerateQueryHandler(proc, procBinding));
     }
     else
     {
         throw new NotSupportedException("This mode is not supported");
     }
 }
Beispiel #2
0
        private async Task BindProcedure(Mode mode, bool isCollection, string key, string handlerName)
        {
            var procName = _context["procName"].ToString();
            var commadId = (long)_context[key];
            var resultId = (long)_context["resultId"];

            await _applicationExecutor.ExecuteAsync <IRepository>(async repo =>
            {
                var procBinding = new ProcedureBinding()
                {
                    IsResultCollection = isCollection,
                    Mode      = mode,
                    Name      = handlerName,
                    Procedure = await repo.Query <ProcedureDescriptor>()
                                .FirstAsync(x => x.Name == procName),
                    RequestId = commadId,
                    ResultId  = resultId
                };
                await repo.Add(procBinding);
                await repo.CommitChanges();
            });
        }
Beispiel #3
0
        private async Task <SourceUnit> GenerateQueryHandler(ProcedureDescriptor proc, ProcedureBinding procBinding)
        {
            var paramBindings = await _repo.Query <ProcedureParameterBinding>()
                                .Where(x => x.Parameter.ProcedureId == proc.Id)
                                .Include(x => x.Parameter)
                                .Include(x => x.Property)
                                .ToArrayAsync();

            var resultBindings = await _repo.Query <ProcedureResultColumnBinding>()
                                 .Where(x => x.ResultColumn.ProcedureId == proc.Id)
                                 .Include(x => x.ResultColumn)
                                 .Include(x => x.Property)
                                 .ToArrayAsync();

            var handlerTypeName = $"{procBinding.Name}{procBinding.Mode.ToString()}Handler";
            var handlerBuilder  = new SqlQueryHandlerBuilder()
                                  .InNamespace(proc.Schema)
                                  .WithName(handlerTypeName)
                                  .WithProcedureName(proc.Name, proc.ConnectionName)
                                  .WithQueryTypeName(procBinding.Request.FullName())
                                  .WithResultTypeName(procBinding.Result.FullName())
                                  .AddDefaultUsings();

            foreach (var p in paramBindings)
            {
                handlerBuilder.BindParameter(p.Property.Name, p.Parameter.Name, p.Property.PropertyType.FullName());
            }

            foreach (var rCol in resultBindings)
            {
                handlerBuilder.BindColumnResult(rCol.Property.Name,
                                                rCol.Property.PropertyType.FullName(),
                                                rCol.ResultColumn.Name);
            }

            return(new SourceUnit(proc.Schema,
                                  handlerTypeName,
                                  handlerBuilder.GenerateCode()));
        }