TX Sheet Control

HttpDataSource Constructor

Constructor
Namespace
TXTextControl.TXSheetControl.Data
Package
TXTextControl.TXSheetControl.Server as TXTextControl.TXSheetControl.Data.Http.dll from the private NuGet feed or the supplied NuGet folder

Creates a feed adapter. Optional column names make empty object-array responses well-defined. Factory must return a new owned request and map Offset/Limit to the remote service's query contract.

Syntax

public HttpDataSource(HttpClient client, Func<DataRequest, HttpRequestMessage> requestFactory, string[] columns = null)

Parameters

ParameterTypeOptionalDescription
clientHttpClientNoValue matching client's declared type and the owning object's validation rules.
requestFactoryFunc<DataRequest, HttpRequestMessage>NoValue matching requestFactory's declared type and the owning object's validation rules.
columnsstring[]YesValue matching columns's declared type and the owning object's validation rules.

Return Value

HttpDataSource.

Examples

Create a working report from bounded HTTP sales data. Supply an application-owned HttpClient and service URL; scope cached data to its actual audience.

using System.Net.Http;
using TXTextControl.TXSheetControl.Data;
using TXTextControl.TXSheetControl.Server;

async Task<byte[]> BuildHttpDataSourceConstructorAsync(ServerSheetControl control, HttpClient client, Uri serviceBase)
{
    var book = control.Workbook;
    var sheet = await book.Sheets.AtAsync(0);
    var source = new HttpDataSource(client, request => new HttpRequestMessage(HttpMethod.Get, new Uri(serviceBase, "sales?offset=" + request.Offset + "&limit=" + request.Limit)), ["Region", "Revenue"]);
    var registry = new DataSourceRegistry();
    registry.Register("sales-service", "regional-sales", source);

    var request = new DataRequest { Offset = 0, Limit = 100, Parameters = new Dictionary<string, object?> { ["year"] = 2026 } };
    var options = new DataQueryOptions { Timeout = TimeSpan.FromSeconds(15), CacheDuration = TimeSpan.FromMinutes(1), CacheScope = "public-regional-sales" };
    using var binding = new WorkbookDataBinding(book, registry);
    await binding.RefreshRangeAsync(sheet.Range("A1:B101"), "sales-service", "regional-sales", request, options);
    await sheet.Range("A1:B1").FormatAsync(new { fontFamily = "Liberation Sans", fontSize = 16, bold = true, textColor = "#ffffff", fillColor = "#163b63" });
    return await control.SaveAsync(StreamType.PDF);
}

Remarks

Use the member with an instance or settings object from the documented package. Await task-returning operations. Document-bound handles must be resolved again after loading or deleting their owner.

See Also