From 4746ad4e63eee965d84885b5ebee8d3e98c75253 Mon Sep 17 00:00:00 2001 From: FastReports-bot Date: Wed, 31 Jan 2024 15:46:42 +0300 Subject: [PATCH] * sync 1/31/2024 version: 2024.1.5 --- FastReport.Base/Report.cs | 1 + .../Designer/ConnectionsController.cs | 6 ++-- .../Controllers/Designer/UtilsController.cs | 4 +-- .../Services/Abstract/IConnectionsService.cs | 2 +- .../Abstract/IDesignerUtilsService.cs | 7 +++++ .../Implementation/ConnectionService.cs | 30 +++++++++++++++---- .../Implementation/DesignerUtilsService.cs | 22 +++++++++++++- 7 files changed, 60 insertions(+), 12 deletions(-) diff --git a/FastReport.Base/Report.cs b/FastReport.Base/Report.cs index 5ed6591f..7d37caeb 100644 --- a/FastReport.Base/Report.cs +++ b/FastReport.Base/Report.cs @@ -2451,6 +2451,7 @@ private async Task PrepareAsync(bool append, CancellationToken token = def try { await CompileAsync(token).ConfigureAwait(false); + isParameterChanged = false; return Engine.Run(true, append, true); } finally diff --git a/FastReport.Core.Web/Controllers/Designer/ConnectionsController.cs b/FastReport.Core.Web/Controllers/Designer/ConnectionsController.cs index b95a100a..738bf244 100644 --- a/FastReport.Core.Web/Controllers/Designer/ConnectionsController.cs +++ b/FastReport.Core.Web/Controllers/Designer/ConnectionsController.cs @@ -32,9 +32,11 @@ public sealed class ConnectionTablesRequestModel } [HttpGet("/designer.getConnectionTypes")] - public static IResult GetConnectionTypes(IConnectionsService connectionsService) + public static IResult GetConnectionTypes([FromQuery] string needSqlSupportInfo, IConnectionsService connectionsService) { - var response = connectionsService.GetConnectionTypes(); + var isNeedSqlSupport = bool.TryParse(needSqlSupportInfo, out var parsedBool) && parsedBool; + + var response = connectionsService.GetConnectionTypes(isNeedSqlSupport); var content = "{" + string.Join(",", response.ToArray()) + "}"; return Results.Content(content, "application/json"); diff --git a/FastReport.Core.Web/Controllers/Designer/UtilsController.cs b/FastReport.Core.Web/Controllers/Designer/UtilsController.cs index 9be31986..17d39ad9 100644 --- a/FastReport.Core.Web/Controllers/Designer/UtilsController.cs +++ b/FastReport.Core.Web/Controllers/Designer/UtilsController.cs @@ -41,12 +41,12 @@ public static IResult GetComponentProperties(string name, IDesignerUtilsService } [HttpGet("/designer.getConfig")] - public static IResult GetConfig(string reportId, IReportService reportService) + public static IResult GetConfig(string reportId, IReportService reportService, IDesignerUtilsService designerUtilsService) { if (!reportService.TryFindWebReport(reportId, out var webReport)) return Results.NotFound(); - var content = webReport.Designer.Config.IsNullOrWhiteSpace() ? "{}" : webReport.Designer.Config; + var content = designerUtilsService.GetConfig(webReport); return Results.Content(content, "application/json"); } diff --git a/FastReport.Core.Web/Services/Abstract/IConnectionsService.cs b/FastReport.Core.Web/Services/Abstract/IConnectionsService.cs index 9edb17bb..bcefe128 100644 --- a/FastReport.Core.Web/Services/Abstract/IConnectionsService.cs +++ b/FastReport.Core.Web/Services/Abstract/IConnectionsService.cs @@ -37,6 +37,6 @@ public interface IConnectionsService /// /// Returns the list of connection types /// - List GetConnectionTypes(); + List GetConnectionTypes(bool needSqlSupportInfo = false); } } diff --git a/FastReport.Core.Web/Services/Abstract/IDesignerUtilsService.cs b/FastReport.Core.Web/Services/Abstract/IDesignerUtilsService.cs index 862a7c15..87ef27f8 100644 --- a/FastReport.Core.Web/Services/Abstract/IDesignerUtilsService.cs +++ b/FastReport.Core.Web/Services/Abstract/IDesignerUtilsService.cs @@ -34,6 +34,13 @@ public interface IDesignerUtilsService /// Returns a string with the report functions string GetFunctions(Report report); + /// + /// Returns the Online Designer configuration + /// + /// WebReport configuration of which is to be returned + /// String in JSON format with configuration for Online Designer + string GetConfig(WebReport webReport); + string DesignerObjectPreview(WebReport webReport, string reportObj); } } diff --git a/FastReport.Core.Web/Services/Implementation/ConnectionService.cs b/FastReport.Core.Web/Services/Implementation/ConnectionService.cs index c9006240..56277ef6 100644 --- a/FastReport.Core.Web/Services/Implementation/ConnectionService.cs +++ b/FastReport.Core.Web/Services/Implementation/ConnectionService.cs @@ -7,6 +7,7 @@ using System.ComponentModel; using System.Data; using System.IO; +using System.Linq; using System.Net; using System.Text; using System.Text.Encodings.Web; @@ -198,6 +199,7 @@ public string GetConnectionTables(string connectionType, string connectionString { Table = new DataTable(), TableName = view.TableName, + Name = view.TableName, SelectCommand = view.SqlQuery }; @@ -245,17 +247,33 @@ private static bool IsConnectionStringValid(string connectionString, out string return true; } - public List GetConnectionTypes() + public List GetConnectionTypes(bool needSqlSupportInfo = false) { - var names = new List(); + var result = new List(); var objects = new List(); RegisteredObjects.DataConnections.EnumItems(objects); - foreach (var info in objects) - if (info.Object != null) - names.Add($@"""{info.Object.FullName}"":""{Res.TryGetBuiltin(info.Text)}"""); + foreach (var info in objects.Where(info => info.Object != null)) + { + string connection; + + if (needSqlSupportInfo) + { + using var conn = (DataConnectionBase)Activator.CreateInstance(info.Object); + connection = $"\"{info.Object.FullName}\": {GetConnectionJson(info.Text, conn.IsSqlBased)}"; + } + else connection = $"\"{info.Object.FullName}\": \"{Res.TryGetBuiltin(info.Text)}\""; - return names; + result.Add(connection); + } + + return result; } + + private static string GetConnectionJson(string text, bool isSqlBased) + { + return $"{{\"connectionType\": \"{Res.TryGetBuiltin(text)}\", \"sqlSupport\": {isSqlBased.ToString().ToLowerInvariant()}}}"; + } + } } diff --git a/FastReport.Core.Web/Services/Implementation/DesignerUtilsService.cs b/FastReport.Core.Web/Services/Implementation/DesignerUtilsService.cs index e01d4ad7..db8c8c51 100644 --- a/FastReport.Core.Web/Services/Implementation/DesignerUtilsService.cs +++ b/FastReport.Core.Web/Services/Implementation/DesignerUtilsService.cs @@ -1,6 +1,6 @@ using FastReport.Utils; using FastReport.Utils.Json; - +using FastReport.Web.Infrastructure; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; @@ -17,6 +17,7 @@ namespace FastReport.Web.Services { internal sealed class DesignerUtilsService : IDesignerUtilsService { + private const string IsCustomSqlAllowedKey = "custom-sql-allowed"; public string GetMSChartTemplateXML(string templateName) { @@ -149,6 +150,25 @@ public string DesignerObjectPreview(WebReport webReport, string reportObj) return sb.ToString(); } + + public string GetConfig(WebReport webReport) + { + JsonBase config; + + try + { + config = JsonBase.FromString(webReport.Designer.Config); + } + catch + { + config = new JsonObject(); + } + + config[IsCustomSqlAllowedKey] = FastReportGlobal.AllowCustomSqlQueries; + + return config.ToString(); + } + } static class ComponentInformationCache