diff options
| author | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-09-02 20:36:48 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <roy.mail.net@gmail.com> | 2025-09-02 20:36:48 +0300 |
| commit | dc0d050ad35973e1ae09e3c7e47bc1fb13eedcd2 (patch) | |
| tree | f1921cbdfca16b254a9046ab1e8dd17427d81dcd /Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs | |
| parent | f41758ec7d1e28deae447199fc0024467c84a9d4 (diff) | |
| download | Tango-dc0d050ad35973e1ae09e3c7e47bc1fb13eedcd2.tar.gz Tango-dc0d050ad35973e1ae09e3c7e47bc1fb13eedcd2.zip | |
Portal AI
Diffstat (limited to 'Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs')
| -rw-r--r-- | Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs new file mode 100644 index 000000000..ecb89fcd6 --- /dev/null +++ b/Software/Visual_Studio_22/Tango.Portal.Chat.Web/Services/KustoQueryService.cs @@ -0,0 +1,54 @@ +using Azure.Core; +using Azure.Identity; +using Kusto.Data; +using Kusto.Data.Common; +using Kusto.Data.Net.Client; +using Microsoft.Extensions.Options; +using System.Data; + +namespace ChatADX.Web.Services +{ + public sealed class KustoQueryService + { + private readonly ICslQueryProvider _query; + private readonly string _database; + + public KustoQueryService(IOptions<AdxOptions> opts) + { + var options = opts.Value; + _database = options.Database; + + // Use DefaultAzureCredential: works locally (Azure CLI / Visual Studio), and in Azure (Managed Identity) + var cred = new ClientSecretCredential( + opts.Value.TenantId, + opts.Value.ClientId, + opts.Value.ClientSecret); + + var kcsb = new KustoConnectionStringBuilder(options.ClusterUri) + .WithAadAzureTokenCredentialsAuthentication(cred); + + _query = KustoClientFactory.CreateCslQueryProvider(kcsb); + } + + public async Task<DataTable> QueryAsync(string kql, IDictionary<string, string> parameters, CancellationToken ct = default) + { + var props = new ClientRequestProperties + { + ClientRequestId = $"chat_{Guid.NewGuid()}" + }; + + foreach (var kvp in parameters) + { + // Pass all as strings; let KQL cast via e.g., datetime({from}) if declared + props.SetParameter(kvp.Key, kvp.Value); + } + + props.SetOption("servertimeout", "00:00:12"); + + using var reader = await _query.ExecuteQueryAsync(_database, kql, props); + var table = new DataTable(); + table.Load(reader); + return table; + } + } +} |
