tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DatabaseCollectionExtensions.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Linq.Expressions;
4using System.Threading;
5using System.Threading.Tasks;
6
7using Microsoft.EntityFrameworkCore;
8
11
13{
18 {
27 public static Task<TResult> GetTgsUser<TResult>(
28 this IDatabaseCollection<User> databaseCollection,
29 Expression<Func<User, TResult>> selector,
30 CancellationToken cancellationToken)
31 {
32 ArgumentNullException.ThrowIfNull(databaseCollection);
33 ArgumentNullException.ThrowIfNull(selector);
34
35 return databaseCollection
36 .AsQueryable()
37 .Where(x => x.CanonicalName == User.CanonicalizeName(User.TgsSystemUserName))
38 .Select(selector)
39 .FirstAsync(cancellationToken);
40 }
41 }
42}
Extension methods for the IDatabaseCollection<TModel> interface.
static Task< TResult > GetTgsUser< TResult >(this IDatabaseCollection< User > databaseCollection, Expression< Func< User, TResult > > selector, CancellationToken cancellationToken)
Gets User with the name User.TgsSystemUserName.
const string TgsSystemUserName
Username used when creating jobs automatically.
Definition User.cs:21
static string CanonicalizeName(string name)
Change a UserName.Name into a CanonicalName.