skipcheck

TM1 client · Docs · Sessions and logins

Tm1Session

using Skipcheck.Tm1.Client.Session;

Used in the walkthroughs Connect and list your cubes, Test your code against a real TM1, Add TM1 to a Spring Boot application.

One TM1 session, shared by every service. Thread-safe, and safe to share between any number of concurrent callers: TM1 runs requests on one session in parallel.

  • Login is lazy and happens once. The first request logs in, and concurrent first requests share that login. Only the login carries the credentials; every other request carries just the session cookie, since a request with credentials and no cookie makes TM1 open another session.
  • Close it. CloseAsync ends the TM1 session. Otherwise it stays open on the server, counting against its sessions, until it times out.
  • Any request. ExecuteAsync and StreamAsync send any Tm1Request, so anything the services don't cover yet is still reachable.

Build a session with CAM security and a label:

// CAM security, with a label that shows in Sessions and Threads
return Tm1Session
    .Builder()
    .Address("https://tm1.example.com:8010")
    .Authenticator(Tm1Authenticator.CamNamespace("alice", password, "LDAP"))
    .SessionContext("Sales planning")
    .Build();

Or log in with a CAM passport, such as one from exchanging an OIDC token with Cognos:

// CAM passports expire, so the session asks for a current one on every login
return Tm1Session.Builder().Address("https://tm1.example.com:8010").Authenticator(Tm1Authenticator.CamPassport(cognos)).Build();

Send a request no service covers yet, here streaming a collection:

// GET MessageLogEntries, straight through the session: the latest 20 entries
return session.StreamAsync(
    Tm1Request.List<MessageLogEntry>(ODataPath.Of("MessageLogEntries"), ODataQuery.None().OrderByDescending(MessageLogEntry.Fields.TimeStamp).Top(20))
);

Run a service's requests in a sandbox by giving it a sandbox view of the session:

// The cell: every dimension, in the cube's order
var cell = new Dictionary<string, string> { ["Region"] = "North", ["Month"] = "Jan" };
await new SandboxService(session).CreateAsync(SandboxPatch.Builder().Name("What-if").Build());
await new CellService(session.WithSandbox("What-if")).UpdateAsync("Sales", cell, 1200);

Members

Builder staticThe settings one by one, as the Java client's Tm1Session.builder().
Utf8Headers staticThe encoding of the request headers TM1 reads as UTF-8.
ServiceRootThe REST API's root, such as http://tm1:8010/api/v1/.
SandboxThe sandbox this view's requests run in, or null for base data.
ChangeSetThe ID of the change set this view's writes are recorded in, or null.
AsyncHow often this view polls an async request's monitor, or null.
IsClosedWhether CloseAsync has been called.
WithSandboxA view of this session whose requests run in sandbox name.
WithoutSandboxA view of this session whose requests run outside any sandbox, in base data; this session if it has no sandbox.
WithChangeSetA view of this session whose writes are recorded in change set id (from BeginChangeSet).
WithoutChangeSetA view of this session whose writes go into no change set; this session if it has none.
WithAsyncA view of this session whose requests TM1 runs asynchronously (OData's Prefer.
WithoutAsyncA view of this session whose requests run synchronously, as usual; this session if it isn't async.
BatchStarts a JSON $batch.
ConnectAsyncLogs in now, rather than on the first request.
SessionIdAsyncThe session's ID on TM1 (ActiveSession), logging in if needed.
CloseAsyncEnds the session on the server, for every view.
DisposeAsyncCloses the session.
VersionAsyncThe server's product version, such as 11.8.03500.6, read from Server.ProductVersion once per login.
CapabilitiesAsyncWhat the server supports, from its own $metadata.
ExecuteAsyncSends a request and reads its answer.
StreamAsyncThe items of a collection, fetching pages as they're needed (Java's stream).
ToString

Builder

static
Tm1SessionBuilder Builder()

The settings one by one, as the Java client's Tm1Session.builder().

Utf8Headers

static
Encoding? Utf8Headers(string headerName, HttpRequestMessage request)

The encoding of the request headers TM1 reads as UTF-8: a user name in TM1-Impersonate and a label in TM1-SessionContext. TM1 (11.8) decodes them as UTF-8 and nothing else: a name sent as ISO 8859-1 bytes, percent-encoded or as an RFC 2047 encoded word isn't found. .NET refuses a header value outside ASCII unless the handler is told how to write it, so this is the SocketsHttpHandler.RequestHeaderEncodingSelector of the client's own handler, and what a handler of yours needs (Tm1SessionBuilder.HttpHandler).

Returns

UTF-8 for those two headers; null, .NET's default, for any other.

ServiceRoot

string ServiceRoot()

The REST API's root, such as http://tm1:8010/api/v1/.

Sandbox

string? Sandbox()

The sandbox this view's requests run in, or null for base data.

ChangeSet

string? ChangeSet()

The ID of the change set this view's writes are recorded in, or null.

Async

TimeSpan? Async()

How often this view polls an async request's monitor, or null.

IsClosed

bool IsClosed()

Whether CloseAsync has been called.

WithSandbox

Tm1Session WithSandbox(string name)

A view of this session whose requests run in sandbox name: each gets TM1's !sandbox query option, unless the request sets its own. The view shares this session's login, cookie and connections, so it costs nothing; closing either closes both. TM1 evaluates NON EMPTY and filters in the request's sandbox, so every request of an operation needs it, cellset reads and deletes included; a service given this view gets that for free.

Throws

ArgumentException
name is blank.

WithoutSandbox

Tm1Session WithoutSandbox()

A view of this session whose requests run outside any sandbox, in base data; this session if it has no sandbox.

WithChangeSet

Tm1Session WithChangeSet(string id)

A view of this session whose writes are recorded in change set id (from BeginChangeSet): each request gets TM1's !ChangeSet query option, unless it sets its own, so UndoChangeSet can revert them together. Like WithSandbox, the view shares this session's login and connections; it keeps the sandbox, if any.

Throws

ArgumentException
id is blank.

WithoutChangeSet

Tm1Session WithoutChangeSet()

A view of this session whose writes go into no change set; this session if it has none.

WithAsync

Tm1Session WithAsync(TimeSpan every)

A view of this session whose requests TM1 runs asynchronously (OData's Prefer: respond-async): each returns at once with a monitor, which the client polls every every until the result is there, so a long process or chore never holds a request open for its whole run. Methods return what they always do. Cancelling before the result deletes the monitor, which stops the work on TM1: a process run ends as TM1UserException: Cancel. Raw byte requests (document content) aren't sent async. TM1 (11.8) sends no Retry-After, so every is the only pace.

Throws

ArgumentException
every isn't positive.

WithoutAsync

Tm1Session WithoutAsync()

A view of this session whose requests run synchronously, as usual; this session if it isn't async.

Batch

Tm1SessionBatch Batch()

Starts a JSON $batch: its Tm1SessionBatch.Session is a view of this one whose requests are queued, and RunAsync sends them.

ConnectAsync

Task<Tm1Session> ConnectAsync(CancellationToken cancellationToken = default)

Logs in now, rather than on the first request.

SessionIdAsync

Task<long> SessionIdAsync(CancellationToken cancellationToken = default)

The session's ID on TM1 (ActiveSession), logging in if needed.

CloseAsync

Task CloseAsync(CancellationToken cancellationToken = default)

Ends the session on the server, for every view.

DisposeAsync

ValueTask DisposeAsync()

Closes the session: CloseAsync.

VersionAsync

Task<Tm1Version> VersionAsync(CancellationToken cancellationToken = default)

The server's product version, such as 11.8.03500.6, read from Server.ProductVersion once per login. Logs in first if needed.

CapabilitiesAsync

Task<Tm1Capabilities> CapabilitiesAsync(CancellationToken cancellationToken = default)

What the server supports, from its own $metadata. Fetched once per server version and shared by every session built from the same settings, a pool's included. A request that declares Tm1Request{T}.Requires is checked against it before it's sent.

ExecuteAsync

Task<T> ExecuteAsync<T>(Tm1Request<T> request, CancellationToken cancellationToken = default)

Sends a request and reads its answer. Collections are read with StreamAsync. In a batch, the task completes once the batch has run.

StreamAsync

IAsyncEnumerable<T> StreamAsync<T>(Tm1Request<T> request, [EnumeratorCancellation] CancellationToken cancellationToken = default)

The items of a collection, fetching pages as they're needed (Java's stream). In a batch, the items come once the batch has run. If TM1 pages (@odata.nextLink), the pages after the first are fetched with ordinary requests on this session, also through an async view or a batch: they aren't part of the async result or the batch.

ToString

string ToString()