예제 #1
0
        public async Task RenderElementKind(RequestUrlKind kind, String pathInfo, ExpandoObject loadPrms, TextWriter writer)
        {
            RequestModel rm = await RequestModel.CreateFromUrl(_host, kind, pathInfo);

            RequestView rw = rm.GetCurrentAction(kind);

            rw.CheckPermissions(_userStateManager?.GetUserPermissions(), Host.IsDebugConfiguration);
            await Render(rw, writer, loadPrms);
        }
예제 #2
0
        public async Task <ReportInfo> GetReportInfo(ReportContext context, String url, String id, ExpandoObject prms)
        {
            var          appReader = _host.ApplicationReader;
            var          ri        = new ReportInfo();
            RequestModel rm        = await RequestModel.CreateFromBaseUrl(_host, url);

            var rep = rm.GetReport();

            rep.CheckPermissions(_userStateManager?.GetUserPermissions(), _host.IsDebugConfiguration);

            ri.Type = rep.type;

            if (rep.type == RequestReportType.xml)
            {
                if (rep.xmlSchemas != null)
                {
                    ri.XmlSchemaPathes = new List <String>();
                    foreach (var schema in rep.xmlSchemas)
                    {
                        ri.XmlSchemaPathes.Add(appReader.MakeFullPath(rep.Path, schema + ".xsd"));
                    }
                }

                ri.Encoding = rep.encoding;
                ri.Validate = rep.validate;
            }

            prms.Set("UserId", context.UserId);
            if (_host.IsMultiTenant || context.TenantId != 0 /*hack for desktop*/)
            {
                prms.Set("TenantId", context.TenantId);
            }
            if (_host.IsMultiCompany)
            {
                prms.Set("CompanyId", context.CompanyId);
            }
            prms.Set("Id", id);
            prms.AppendIfNotExists(rep.parameters);

            ri.DataModel = await _dbContext.LoadModelAsync(rep.CurrentSource, rep.ReportProcedure, prms);

            CheckTypes(rep.Path, rep.checkTypes, ri.DataModel);

            // after query
            ExpandoObject vars = rep.variables;

            if (vars == null)
            {
                vars = new ExpandoObject();
            }
            vars.Set("UserId", context.UserId);
            if (_host.IsMultiTenant)
            {
                vars.Set("TenantId", context.TenantId);
            }
            if (_host.IsMultiCompany)
            {
                vars.Set("CompanyId", context.CompanyId);
            }
            vars.Set("Id", id);
            ri.Variables = vars;
            var repName = _localizer.Localize(null, String.IsNullOrEmpty(rep.name) ? rep.ReportName : rep.name);

            if (ri.DataModel != null && ri.DataModel.Root != null)
            {
                repName = ri.DataModel.Root.Resolve(repName);
            }
            ri.Name = repName;

            if (rep.ReportFromDataModel)
            {
                ri.ReportStream = ri.DataModel.Eval <Byte[]>(rep.ReportExpression);
                if (ri.ReportStream == null)
                {
                    throw new InvalidDataException($"Expression '{rep.ReportName}'  is null");
                }
            }
            else if (rep.HasPath)
            {
                ri.ReportPath = appReader.MakeFullPath(rep.Path, rep.ReportName + rep.GetExtension());
            }

            return(ri);
        }