示例#1
0
        public async Task <HttpResponseMessage> ToPlainExcel(QueryRequestTS request, CancellationToken token)
        {
            var queryRequest = request.ToQueryRequest();

            ResultTable queryResult = await DynamicQueryManager.Current.ExecuteQueryAsync(queryRequest, token);

            byte[] binaryFile = PlainExcelGenerator.WritePlainExcel(queryResult, QueryUtils.GetNiceName(queryRequest.QueryName));

            var fileName = request.queryKey + TimeZoneManager.Now.ToString("yyyyMMdd-HHmmss") + ".xlsx";

            return(FilesController.GetHttpReponseMessage(new MemoryStream(binaryFile), fileName));
        }
示例#2
0
        public async Task <FileStreamResult> ToPlainExcel([Required, FromBody] QueryRequestTS request, CancellationToken token)
        {
            var queryRequest = request.ToQueryRequest();

            ResultTable queryResult = await QueryLogic.Queries.ExecuteQueryAsync(queryRequest, token);

            byte[] binaryFile = PlainExcelGenerator.WritePlainExcel(queryResult, QueryUtils.GetNiceName(queryRequest.QueryName));

            var fileName = request.queryKey + TimeZoneManager.Now.ToString("yyyyMMdd-HHmmss") + ".xlsx";

            return(FilesController.GetFileStreamResult(new MemoryStream(binaryFile), fileName));
        }
示例#3
0
    public async Task <FileStreamResult> ToPlainExcel([Required, FromBody] QueryRequestTS request, CancellationToken token)
    {
        ExcelPermission.PlainExcel.AssertAuthorized();

        var queryRequest = request.ToQueryRequest(SignumServer.JsonSerializerOptions);

        ResultTable queryResult = await QueryLogic.Queries.ExecuteQueryAsync(queryRequest, token);

        byte[] binaryFile = PlainExcelGenerator.WritePlainExcel(queryResult, QueryUtils.GetNiceName(queryRequest.QueryName));

        var fileName = request.queryKey + Clock.Now.ToString("yyyyMMdd-HHmmss") + ".xlsx";

        return(FilesController.GetFileStreamResult(new MemoryStream(binaryFile), fileName));
    }
示例#4
0
    public async Task <ResultTable> ExecuteQuery([Required, FromBody] QueryRequestTS request, CancellationToken token)
    {
        var result = await QueryLogic.Queries.ExecuteQueryAsync(request.ToQueryRequest(SignumServer.JsonSerializerOptions), token);

        return(result);
    }
示例#5
0
        public static void Register()
        {
            new Execute(DashboardOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (cp, _) => { }
            }.Register();

            new Delete(DashboardOperation.Delete)
            {
                Delete = (cp, _) =>
                {
                    var parts = cp.Parts.Select(a => a.Content).ToList();
                    cp.Delete();
                    Database.DeleteList(parts);
                }
            }.Register();

            new ConstructFrom <DashboardEntity>(DashboardOperation.Clone)
            {
                Construct = (cp, _) => cp.Clone()
            }.Register();

            new Execute(DashboardOperation.RegenerateCachedQueries)
            {
                CanExecute = c => c.CacheQueryConfiguration == null?ValidationMessage._0IsNotSet.NiceToString(ReflectionTools.GetPropertyInfo(() => c.CacheQueryConfiguration)) : null,
                                 AvoidImplicitSave = true,
                                 Execute           = (db, _) =>
                {
                    var cq = db.CacheQueryConfiguration !;

                    var oldCachedQueries = db.CachedQueries().ToList();
                    oldCachedQueries.ForEach(a => a.File.DeleteFileOnCommit());
                    db.CachedQueries().UnsafeDelete();

                    var definitions = DashboardLogic.GetCachedQueryDefinitions(db).ToList();

                    var combined = DashboardLogic.CombineCachedQueryDefinitions(definitions);

                    foreach (var c in combined)
                    {
                        var qr = c.QueryRequest;

                        if (qr.Pagination is Pagination.All)
                        {
                            qr            = qr.Clone();
                            qr.Pagination = new Pagination.Firsts(cq.MaxRows + 1);
                        }

                        var now = Clock.Now;

                        Stopwatch sw = Stopwatch.StartNew();

                        var rt = Connector.CommandTimeoutScope(cq.TimeoutForQueries).Using(_ => QueryLogic.Queries.ExecuteQuery(qr));

                        var queryDuration = sw.ElapsedMilliseconds;

                        if (c.QueryRequest.Pagination is Pagination.All)
                        {
                            if (rt.Rows.Length == cq.MaxRows)
                            {
                                throw new ApplicationException($"The query for {c.UserAssets.CommaAnd(a => a.KeyLong())} has returned more than {cq.MaxRows} rows: " +
                                                               JsonSerializer.Serialize(QueryRequestTS.FromQueryRequest(c.QueryRequest), EntityJsonContext.FullJsonSerializerOptions));
                            }
                            else
                            {
                                rt = new ResultTable(rt.AllColumns(), null, new Pagination.All());
                            }
                        }


                        sw.Restart();

                        var json = new CachedQueryJS
                        {
                            CreationDate = now,
                            QueryRequest = QueryRequestTS.FromQueryRequest(c.QueryRequest),
                            ResultTable  = rt,
                        };

                        var bytes = JsonSerializer.SerializeToUtf8Bytes(json, EntityJsonContext.FullJsonSerializerOptions);

                        var file = new Entities.Files.FilePathEmbedded(CachedQueryFileType.CachedQuery, "CachedQuery.json", bytes).SaveFile();

                        var uploadDuration = sw.ElapsedMilliseconds;

                        new CachedQueryEntity
                        {
                            CreationDate   = now,
                            UserAssets     = c.UserAssets.ToMList(),
                            NumColumns     = qr.Columns.Count + (qr.GroupResults ? 0 : 1),
                            NumRows        = rt.Rows.Length,
                            QueryDuration  = queryDuration,
                            UploadDuration = uploadDuration,
                            File           = file,
                            Dashboard      = db.ToLite(),
                        }.Save();
                    }
                }
            }.SetMinimumTypeAllowed(TypeAllowedBasic.Read).Register();