24 Commits

Author SHA1 Message Date
f1c2ad5e7e Create C# bindings from C headers 2025-06-04 17:05:46 -03:00
e4986367e7 Disable ImplicitUsings 2025-06-04 16:55:16 -03:00
58f300e39b Update Program.cs 2025-06-04 07:45:04 -03:00
479f719816 Update Logger.cs 2025-06-03 20:03:23 -03:00
eb9e939fc8 Update log levels 2025-06-03 20:01:16 -03:00
c8bb2d95b5 Update TribufuApi.cs 2025-06-03 19:37:55 -03:00
e63812204d Rename Tribufu.Runtime to Tribufu.Platform 2025-06-02 10:06:03 -03:00
4b694a4031 Update Tribufu.Runtime.csproj 2025-06-02 09:24:13 -03:00
5fdd52265b Revert "Remove net standard support"
This reverts commit f45e827ba4.
2025-06-02 09:23:54 -03:00
f45e827ba4 Remove net standard support 2025-06-02 09:19:21 -03:00
ffc4079881 Update Tribufu.Runtime.csproj 2025-06-02 09:15:38 -03:00
374a634949 Add IsPublishable to all projects 2025-06-02 09:15:00 -03:00
13c5d6a71c Rename ConfigurationLoader 2025-06-02 09:06:21 -03:00
f6c296d9b6 Update READMEs 2025-06-02 09:00:15 -03:00
5b2588b47f Add shared packages 2025-06-02 08:58:34 -03:00
6ebfde013a Update TribufuApi.cs 2025-06-01 21:45:51 -03:00
9ff743097b Update TribufuApi.cs 2025-05-27 18:55:32 -03:00
42e14fc07b Update README.md 2025-05-27 08:39:35 -03:00
ed2dfa2b8f Update README.md 2025-05-27 08:39:00 -03:00
1815ca6bcd Update README.md 2025-05-27 08:35:17 -03:00
8994fc13d6 Update Directory.Build.props 2025-05-27 08:35:16 -03:00
549e7bcbe3 Update projects deps 2025-05-26 21:43:58 -03:00
aede8c7ac2 Update README.md 2025-05-26 21:41:40 -03:00
d791408793 Generate client with open-api-generator (#1)
* Generate project with open-api-generator

* Add example project

* Create wrapper class
2025-05-26 21:40:46 -03:00
41 changed files with 1082 additions and 317 deletions

View File

@@ -5,7 +5,7 @@
<Copyright>Copyright (c) Tribufu. All Rights Reserved.</Copyright> <Copyright>Copyright (c) Tribufu. All Rights Reserved.</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/tribufu/sdk-dotnet</RepositoryUrl> <RepositoryUrl>https://github.com/tribufu/tribufu-dotnet</RepositoryUrl>
<Version>1.1.0</Version> <Version>1.1.0</Version>
<AssemblyVersion>$(Version).0</AssemblyVersion> <AssemblyVersion>$(Version).0</AssemblyVersion>
<NoWarn>$(NoWarn);0618;1591;1998;2002;8767</NoWarn> <NoWarn>$(NoWarn);0618;1591;1998;2002;8767</NoWarn>

View File

@@ -3,11 +3,21 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageVersion Include="CppAst.CodeGen" Version="0.4.1" />
<PackageVersion Include="dotenv.net" Version="3.2.0" /> <PackageVersion Include="dotenv.net" Version="3.2.0" />
<PackageVersion Include="JsonSubTypes" Version="2.0.1" /> <PackageVersion Include="JsonSubTypes" Version="2.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.16" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" /> <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Polly" Version="8.1.0" /> <PackageVersion Include="Polly" Version="8.1.0" />
<PackageVersion Include="RestSharp" Version="112.1.0" /> <PackageVersion Include="RestSharp" Version="112.1.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" /> <PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="Tomlyn.Extensions.Configuration" Version="1.0.6" />
<PackageVersion Include="Tomlyn" Version="0.17.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

288
README.md
View File

@@ -1,279 +1,23 @@
# Tribufu - the C# library for the Tribufu API # Tribufu .NET
REST API to access Tribufu services. .NET SDK to access Tribufu APIs and services.
This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: [![nuget][nuget-badge]][nuget-url]
[![MIT License][mit-badge]][mit-url]
[![Discord Chat][discord-badge]][discord-url]
- API version: 1.1.0 [nuget-badge]: https://img.shields.io/nuget/v/tribufu.svg
- SDK version: 1.0.0 [nuget-url]: https://www.nuget.org/packages/Tribufu
- Generator version: 7.8.0 [mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
- Build package: org.openapitools.codegen.languages.CSharpClientCodegen [mit-url]: https://github.com/tribufu/tribufu-dotnet/blob/main/LICENSE.txt
For more information, please visit [https://www.tribufu.com/contact](https://www.tribufu.com/contact) [discord-badge]: https://img.shields.io/discord/276504514616623104.svg?logo=discord&style=flat-square
[discord-url]: https://www.tribufu.com/discord
<a id="frameworks-supported"></a> [Website](https://www.tribufu.com) |
## Frameworks supported [Discord](https://www.tribufu.com/discord)
<a id="dependencies"></a> ## License
## Dependencies
- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later This project is licensed under the [MIT License].
- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later
- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later
The DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:
```
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
Install-Package System.ComponentModel.Annotations
```
<a id="installation"></a>
## Installation
Run the following command to generate the DLL
- [Mac/Linux] `/bin/sh build.sh`
- [Windows] `build.bat`
Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces:
```csharp
using Tribufu.Api;
using Tribufu.Client;
using Tribufu.Model;
```
<a id="packaging"></a>
## Packaging
A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages.
This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly:
```
nuget pack -Build -OutputDirectory out Tribufu.csproj
```
Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual.
<a id="usage"></a>
## Usage
To use the API client with a HTTP proxy, setup a `System.Net.WebProxy`
```csharp
Configuration c = new Configuration();
System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/");
webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
c.Proxy = webProxy;
```
### Connections
Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.
To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor.
```csharp
HttpClientHandler yourHandler = new HttpClientHandler();
HttpClient yourHttpClient = new HttpClient(yourHandler);
var api = new YourApiClass(yourHttpClient, yourHandler);
```
If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.
```csharp
HttpClient yourHttpClient = new HttpClient();
var api = new YourApiClass(yourHttpClient);
```
You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.
Here an example of DI setup in a sample web project:
```csharp
services.AddHttpClient<YourApiClass>(httpClient =>
new PetApi(httpClient));
```
<a id="getting-started"></a>
## Getting Started
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using Tribufu.Api;
using Tribufu.Client;
using Tribufu.Model;
namespace Example
{
public class Example
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://localhost";
// Configure API key authorization: ApiKey
config.ApiKey.Add("Authorization", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// config.ApiKeyPrefix.Add("Authorization", "Bearer");
// create instances of HttpClient, HttpClientHandler to be reused later with different Api classes
HttpClient httpClient = new HttpClient();
HttpClientHandler httpClientHandler = new HttpClientHandler();
var apiInstance = new TribufuApi(httpClient, config, httpClientHandler);
var authorizeRequest = new AuthorizeRequest?(); // AuthorizeRequest? | (optional)
try
{
// Authorize the client to access the user information.
apiInstance.Authorize(authorizeRequest);
}
catch (ApiException e)
{
Debug.Print("Exception when calling TribufuApi.Authorize: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```
<a id="documentation-for-api-endpoints"></a>
## Documentation for API Endpoints
All URIs are relative to *http://localhost*
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*TribufuApi* | [**Authorize**](docs/TribufuApi.md#authorize) | **POST** /v1/oauth2/authorize | Authorize the client to access the user information.
*TribufuApi* | [**ChangeEmail**](docs/TribufuApi.md#changeemail) | **PUT** /v1/users/{id}/email | Change the email of a user.
*TribufuApi* | [**ChangePassword**](docs/TribufuApi.md#changepassword) | **PUT** /v1/users/{id}/password | Change the password of a user.
*TribufuApi* | [**ClaimGameServer**](docs/TribufuApi.md#claimgameserver) | **PUT** /v1/servers/{id}/claim | Claim a game server.
*TribufuApi* | [**ConvertBase64**](docs/TribufuApi.md#convertbase64) | **POST** /v1/utils/base64 | Convert a string to base64 or vice versa.
*TribufuApi* | [**CreateGameServer**](docs/TribufuApi.md#creategameserver) | **POST** /v1/servers | Create a new game server.
*TribufuApi* | [**CreateGameServerCluster**](docs/TribufuApi.md#creategameservercluster) | **POST** /v1/clusters | Create a new game server cluster.
*TribufuApi* | [**CreateGroup**](docs/TribufuApi.md#creategroup) | **POST** /v1/groups | Create a new group.
*TribufuApi* | [**CreateToken**](docs/TribufuApi.md#createtoken) | **POST** /v1/oauth2/token | Create a new token with grant type.
*TribufuApi* | [**DeleteGameServer**](docs/TribufuApi.md#deletegameserver) | **DELETE** /v1/servers/{id} | Delete a game server.
*TribufuApi* | [**DeleteGameServerCluster**](docs/TribufuApi.md#deletegameservercluster) | **DELETE** /v1/clusters/{id} | Delete a game server cluster.
*TribufuApi* | [**DeleteGroup**](docs/TribufuApi.md#deletegroup) | **DELETE** /v1/groups/{id} | Delete a group.
*TribufuApi* | [**GenerateFlakeId**](docs/TribufuApi.md#generateflakeid) | **GET** /v1/utils/flake | Generate one or more flake ids.
*TribufuApi* | [**GenerateFlakeIdFromTimestamp**](docs/TribufuApi.md#generateflakeidfromtimestamp) | **GET** /v1/utils/flake/{timestamp} | Generate one or more flake ids from a timestamp.
*TribufuApi* | [**GeneratePassword**](docs/TribufuApi.md#generatepassword) | **GET** /v1/utils/password | Generate a random password.
*TribufuApi* | [**GenerateUuid**](docs/TribufuApi.md#generateuuid) | **GET** /v1/utils/uuid | Generate one or more uuids with a specific version.
*TribufuApi* | [**GetClientInfo**](docs/TribufuApi.md#getclientinfo) | **GET** /v1/oauth2/clientinfo | Get current client information.
*TribufuApi* | [**GetCurrentIpAddress**](docs/TribufuApi.md#getcurrentipaddress) | **GET** /v1/geoip | Get current ip address location.
*TribufuApi* | [**GetGameById**](docs/TribufuApi.md#getgamebyid) | **GET** /v1/games/{id} | Get a game by id.
*TribufuApi* | [**GetGameClustersByGameId**](docs/TribufuApi.md#getgameclustersbygameid) | **GET** /v1/games/{id}/clusters | Get a list of game server clusters of a game.
*TribufuApi* | [**GetGameItems**](docs/TribufuApi.md#getgameitems) | **GET** /v1/games/{id}/items | Get a list of game items.
*TribufuApi* | [**GetGameServerByAddressAndQueryPort**](docs/TribufuApi.md#getgameserverbyaddressandqueryport) | **GET** /v1/servers/address/{address}:{port} | Get a game server by address and query port.
*TribufuApi* | [**GetGameServerById**](docs/TribufuApi.md#getgameserverbyid) | **GET** /v1/servers/{id} | Get a game server by id.
*TribufuApi* | [**GetGameServerClusterById**](docs/TribufuApi.md#getgameserverclusterbyid) | **GET** /v1/clusters/{id} | Get a game server cluster by id.
*TribufuApi* | [**GetGameServerClusters**](docs/TribufuApi.md#getgameserverclusters) | **GET** /v1/clusters | Get a list of game server clusters.
*TribufuApi* | [**GetGameServers**](docs/TribufuApi.md#getgameservers) | **GET** /v1/servers | Get a list of game servers.
*TribufuApi* | [**GetGameServersByCountry**](docs/TribufuApi.md#getgameserversbycountry) | **GET** /v1/servers/country/{country} | Get a list of game servers from a country.
*TribufuApi* | [**GetGameServersByGameId**](docs/TribufuApi.md#getgameserversbygameid) | **GET** /v1/games/{id}/servers | Get a list of game servers of a game.
*TribufuApi* | [**GetGameServersCountries**](docs/TribufuApi.md#getgameserverscountries) | **GET** /v1/servers/countries | Get a list of countries with the number of game servers.
*TribufuApi* | [**GetGameServersMetrics**](docs/TribufuApi.md#getgameserversmetrics) | **GET** /v1/servers/metrics | Get metrics about the tracked game servers.
*TribufuApi* | [**GetGames**](docs/TribufuApi.md#getgames) | **GET** /v1/games | Get a list of games.
*TribufuApi* | [**GetGroupById**](docs/TribufuApi.md#getgroupbyid) | **GET** /v1/groups/{id} | Get a group by id.
*TribufuApi* | [**GetGroupByTag**](docs/TribufuApi.md#getgroupbytag) | **GET** /v1/groups/tag/{tag} | Get a group by tag.
*TribufuApi* | [**GetGroupByUuid**](docs/TribufuApi.md#getgroupbyuuid) | **GET** /v1/groups/uuid/{uuid} | Get a group by uuid.
*TribufuApi* | [**GetGroupGames**](docs/TribufuApi.md#getgroupgames) | **GET** /v1/groups/{id}/games | Get a list of games of a group.
*TribufuApi* | [**GetGroupMembers**](docs/TribufuApi.md#getgroupmembers) | **GET** /v1/groups/{id}/members | Get a list of members in a group.
*TribufuApi* | [**GetGroups**](docs/TribufuApi.md#getgroups) | **GET** /v1/groups | Get a list of groups.
*TribufuApi* | [**GetIpAddress**](docs/TribufuApi.md#getipaddress) | **GET** /v1/geoip/addresses/{address} | Get a ip address location.
*TribufuApi* | [**GetIpAddresses**](docs/TribufuApi.md#getipaddresses) | **GET** /v1/geoip/addresses | Get a list of ip addresses.
*TribufuApi* | [**GetLeaderboard**](docs/TribufuApi.md#getleaderboard) | **GET** /v1/leaderboard | Get the top 20 leaderboard users.
*TribufuApi* | [**GetMe**](docs/TribufuApi.md#getme) | **GET** /v1/me | Get current user information.
*TribufuApi* | [**GetPackageById**](docs/TribufuApi.md#getpackagebyid) | **GET** /v1/packages/{id} | Get a package by id.
*TribufuApi* | [**GetPackages**](docs/TribufuApi.md#getpackages) | **GET** /v1/packages | Get a list of packages.
*TribufuApi* | [**GetPublicKeys**](docs/TribufuApi.md#getpublickeys) | **GET** /v1/oauth2/jwks | Get the public keys for the client.
*TribufuApi* | [**GetSubscriptionById**](docs/TribufuApi.md#getsubscriptionbyid) | **GET** /v1/subscriptions/{id} | Get a subscription by id.
*TribufuApi* | [**GetSubscriptions**](docs/TribufuApi.md#getsubscriptions) | **GET** /v1/subscriptions | Get a list of subscriptions.
*TribufuApi* | [**GetUserAccounts**](docs/TribufuApi.md#getuseraccounts) | **GET** /v1/users/{id}/accounts | Get a list of connected accounts of the user.
*TribufuApi* | [**GetUserById**](docs/TribufuApi.md#getuserbyid) | **GET** /v1/users/{id} | Get a user profile by id.
*TribufuApi* | [**GetUserByName**](docs/TribufuApi.md#getuserbyname) | **GET** /v1/users/name/{name} | Get a user profile by name.
*TribufuApi* | [**GetUserByUuid**](docs/TribufuApi.md#getuserbyuuid) | **GET** /v1/users/uuid/{uuid} | Get a user profile by uuid.
*TribufuApi* | [**GetUserFriends**](docs/TribufuApi.md#getuserfriends) | **GET** /v1/users/{id}/friends | Get a list of friends of the user.
*TribufuApi* | [**GetUserGames**](docs/TribufuApi.md#getusergames) | **GET** /v1/users/{id}/games | Get a list of games the user has played.
*TribufuApi* | [**GetUserGroups**](docs/TribufuApi.md#getusergroups) | **GET** /v1/users/{id}/groups | Get a list of groups the user is a member of.
*TribufuApi* | [**GetUserInfo**](docs/TribufuApi.md#getuserinfo) | **GET** /v1/oauth2/userinfo | Get current user information.
*TribufuApi* | [**GetUserPunishments**](docs/TribufuApi.md#getuserpunishments) | **GET** /v1/users/{id}/punishments | Get a list of punishments the user has received.
*TribufuApi* | [**GetUserServers**](docs/TribufuApi.md#getuserservers) | **GET** /v1/users/{id}/servers | Get a list of servers the user is owner of.
*TribufuApi* | [**GetUsers**](docs/TribufuApi.md#getusers) | **GET** /v1/users | Get a list of user profiles.
*TribufuApi* | [**HashArgon2**](docs/TribufuApi.md#hashargon2) | **POST** /v1/utils/argon2 | Hash a string using argon2.
*TribufuApi* | [**HashBcrypt**](docs/TribufuApi.md#hashbcrypt) | **POST** /v1/utils/bcrypt | Hash a string using bcrypt.
*TribufuApi* | [**HashMd5**](docs/TribufuApi.md#hashmd5) | **POST** /v1/utils/md5 | Hash a string using md5.
*TribufuApi* | [**HashSha256**](docs/TribufuApi.md#hashsha256) | **POST** /v1/utils/sha256 | Hash a string using sha256.
*TribufuApi* | [**IntrospectToken**](docs/TribufuApi.md#introspecttoken) | **POST** /v1/oauth2/introspect | Introspect a token.
*TribufuApi* | [**Login**](docs/TribufuApi.md#login) | **POST** /v1/login | Login with name or email and password.
*TribufuApi* | [**Logout**](docs/TribufuApi.md#logout) | **POST** /v1/logout | Invalidate credentials.
*TribufuApi* | [**Refresh**](docs/TribufuApi.md#refresh) | **POST** /v1/refresh | Refresh credentials.
*TribufuApi* | [**Register**](docs/TribufuApi.md#register) | **POST** /v1/register | Create a new user.
*TribufuApi* | [**RevokeToken**](docs/TribufuApi.md#revoketoken) | **POST** /v1/oauth2/revoke | Revoke a token.
*TribufuApi* | [**Search**](docs/TribufuApi.md#search) | **POST** /v1/search | Advanced search for servers or players.
*TribufuApi* | [**UpdateGameServer**](docs/TribufuApi.md#updategameserver) | **PUT** /v1/servers/{id} | Update a game server.
*TribufuApi* | [**UpdateGameServerCluster**](docs/TribufuApi.md#updategameservercluster) | **PUT** /v1/clusters/{id} | Update a game server cluster.
*TribufuApi* | [**UpdateGroup**](docs/TribufuApi.md#updategroup) | **PUT** /v1/groups/{id} | Update a group.
*TribufuApi* | [**UpdateUserProfile**](docs/TribufuApi.md#updateuserprofile) | **PUT** /v1/users/{id}/profile | Update a user profile.
<a id="documentation-for-models"></a>
## Documentation for Models
- [Model.Account](docs/Account.md)
- [Model.Application](docs/Application.md)
- [Model.ApplicationType](docs/ApplicationType.md)
- [Model.AuthorizeRequest](docs/AuthorizeRequest.md)
- [Model.CodeChallengeMethod](docs/CodeChallengeMethod.md)
- [Model.CryptoViewModel](docs/CryptoViewModel.md)
- [Model.Game](docs/Game.md)
- [Model.GameServer](docs/GameServer.md)
- [Model.GameServerCluster](docs/GameServerCluster.md)
- [Model.GrantType](docs/GrantType.md)
- [Model.Group](docs/Group.md)
- [Model.GroupGame](docs/GroupGame.md)
- [Model.GroupMember](docs/GroupMember.md)
- [Model.GroupRank](docs/GroupRank.md)
- [Model.HashViewModel](docs/HashViewModel.md)
- [Model.IntrospectRequest](docs/IntrospectRequest.md)
- [Model.IpAddress](docs/IpAddress.md)
- [Model.LeaderboardItem](docs/LeaderboardItem.md)
- [Model.LeaderboardOrder](docs/LeaderboardOrder.md)
- [Model.LoginProvider](docs/LoginProvider.md)
- [Model.LoginRequest](docs/LoginRequest.md)
- [Model.LoginResponse](docs/LoginResponse.md)
- [Model.Package](docs/Package.md)
- [Model.Profile](docs/Profile.md)
- [Model.ProfileGame](docs/ProfileGame.md)
- [Model.ProfileGroup](docs/ProfileGroup.md)
- [Model.RefreshRequest](docs/RefreshRequest.md)
- [Model.RegisterRequest](docs/RegisterRequest.md)
- [Model.ResponseType](docs/ResponseType.md)
- [Model.RevokeRequest](docs/RevokeRequest.md)
- [Model.SearchRequest](docs/SearchRequest.md)
- [Model.SearchType](docs/SearchType.md)
- [Model.ServerMetrics](docs/ServerMetrics.md)
- [Model.ServerStatus](docs/ServerStatus.md)
- [Model.Subscription](docs/Subscription.md)
- [Model.TokenHintType](docs/TokenHintType.md)
- [Model.TokenRequest](docs/TokenRequest.md)
- [Model.TokenResponse](docs/TokenResponse.md)
- [Model.TokenType](docs/TokenType.md)
- [Model.UpdateProfile](docs/UpdateProfile.md)
- [Model.UserInfo](docs/UserInfo.md)
- [Model.UserType](docs/UserType.md)
<a id="documentation-for-authorization"></a>
## Documentation for Authorization
Authentication schemes defined for the API:
<a id="ApiKey"></a>
### ApiKey
- **Type**: API key
- **API key parameter name**: Authorization
- **Location**: HTTP header
[MIT License]: https://github.com/tribufu/tribufu-dotnet/blob/main/LICENSE.txt

View File

@@ -7,6 +7,22 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Generated", "src\Tr
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Example", "src\Tribufu.Example\Tribufu.Example.csproj", "{D6392A29-E2DC-4050-B4C1-B279DD2D226D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Example", "src\Tribufu.Example\Tribufu.Example.csproj", "{D6392A29-E2DC-4050-B4C1-B279DD2D226D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Logging", "src\Tribufu.Logging\Tribufu.Logging.csproj", "{CFD80847-9B98-4991-BADF-8714E7D8D81C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Configuration", "src\Tribufu.Configuration\Tribufu.Configuration.csproj", "{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Platform", "src\Tribufu.Platform\Tribufu.Platform.csproj", "{26EEB407-733C-4383-9211-B083CD5F593B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Database", "src\Tribufu.Database\Tribufu.Database.csproj", "{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Serialization", "src\Tribufu.Serialization\Tribufu.Serialization.csproj", "{D6DAE078-2F80-49DD-97A3-B1223FE04F91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.ComponentModel", "src\Tribufu.ComponentModel\Tribufu.ComponentModel.csproj", "{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Native", "src\Tribufu.Native\Tribufu.Native.csproj", "{A7388573-2EEA-449D-8605-9115BE8C0050}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tribufu.Native.Generator", "src\Tribufu.Native.Generator\Tribufu.Native.Generator.csproj", "{F71217EC-9ED2-40B9-B0B8-7696FA280889}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -53,6 +69,102 @@ Global
{D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x64.Build.0 = Release|Any CPU {D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x64.Build.0 = Release|Any CPU
{D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x86.ActiveCfg = Release|Any CPU {D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x86.ActiveCfg = Release|Any CPU
{D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x86.Build.0 = Release|Any CPU {D6392A29-E2DC-4050-B4C1-B279DD2D226D}.Release|x86.Build.0 = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|x64.ActiveCfg = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|x64.Build.0 = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|x86.ActiveCfg = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Debug|x86.Build.0 = Debug|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|Any CPU.Build.0 = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|x64.ActiveCfg = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|x64.Build.0 = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|x86.ActiveCfg = Release|Any CPU
{CFD80847-9B98-4991-BADF-8714E7D8D81C}.Release|x86.Build.0 = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|x64.ActiveCfg = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|x64.Build.0 = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|x86.ActiveCfg = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Debug|x86.Build.0 = Debug|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|Any CPU.Build.0 = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|x64.ActiveCfg = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|x64.Build.0 = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|x86.ActiveCfg = Release|Any CPU
{C0A841C8-9FC5-4AC0-B9AD-6BBFCEDCBE5F}.Release|x86.Build.0 = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|x64.ActiveCfg = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|x64.Build.0 = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|x86.ActiveCfg = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Debug|x86.Build.0 = Debug|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|Any CPU.Build.0 = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|x64.ActiveCfg = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|x64.Build.0 = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|x86.ActiveCfg = Release|Any CPU
{26EEB407-733C-4383-9211-B083CD5F593B}.Release|x86.Build.0 = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|x64.ActiveCfg = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|x64.Build.0 = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|x86.ActiveCfg = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Debug|x86.Build.0 = Debug|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|Any CPU.Build.0 = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|x64.ActiveCfg = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|x64.Build.0 = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|x86.ActiveCfg = Release|Any CPU
{E7F9A76F-C087-410B-B4B5-A928A6CDC2BA}.Release|x86.Build.0 = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|x64.ActiveCfg = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|x64.Build.0 = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|x86.ActiveCfg = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Debug|x86.Build.0 = Debug|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|Any CPU.Build.0 = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|x64.ActiveCfg = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|x64.Build.0 = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|x86.ActiveCfg = Release|Any CPU
{D6DAE078-2F80-49DD-97A3-B1223FE04F91}.Release|x86.Build.0 = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|x64.ActiveCfg = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|x64.Build.0 = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|x86.ActiveCfg = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Debug|x86.Build.0 = Debug|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|Any CPU.Build.0 = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|x64.ActiveCfg = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|x64.Build.0 = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|x86.ActiveCfg = Release|Any CPU
{7CB04FFD-8F4B-4B40-BB4B-2BAA19D783E1}.Release|x86.Build.0 = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|x64.ActiveCfg = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|x64.Build.0 = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|x86.ActiveCfg = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Debug|x86.Build.0 = Debug|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|Any CPU.Build.0 = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|x64.ActiveCfg = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|x64.Build.0 = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|x86.ActiveCfg = Release|Any CPU
{A7388573-2EEA-449D-8605-9115BE8C0050}.Release|x86.Build.0 = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|x64.ActiveCfg = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|x64.Build.0 = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|x86.ActiveCfg = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Debug|x86.Build.0 = Debug|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|Any CPU.Build.0 = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|x64.ActiveCfg = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|x64.Build.0 = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|x86.ActiveCfg = Release|Any CPU
{F71217EC-9ED2-40B9-B0B8-7696FA280889}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

5
scripts/package.ps1 Normal file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env sh
dotnet clean
dotnet build -c Release
dotnet pack

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env sh
dotnet pack

View File

@@ -0,0 +1,30 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace Tribufu.ComponentModel
{
public class EnumMemberConverter<T> : EnumConverter
{
public EnumMemberConverter(Type type) : base(type) { }
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var type = typeof(T);
foreach (var field in type.GetFields())
{
if (Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) is EnumMemberAttribute attribute && value is string enumValue && attribute.Value == enumValue)
{
return field.GetValue(null);
}
}
return base.ConvertFrom(context, culture, value);
}
}
}

View File

@@ -0,0 +1 @@
# Tribufu ComponentModel

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.ComponentModel</PackageId>
<Description>Tribufu ComponentModel Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;net45;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,53 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Microsoft.Extensions.Configuration;
using System.IO;
using Tomlyn.Extensions.Configuration;
using Tribufu.Logging;
using Tribufu.Platform;
namespace Tribufu.Configuration
{
public static class ConfigurationLoader
{
public static IConfiguration Configuration { get; private set; }
public static IConfiguration Load(string[] fileNames)
{
var configDirectory = Paths.GetApplicationConfigDirectory();
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddEnvironmentVariables();
foreach (var fileName in fileNames)
{
var fullPath = Path.Combine(configDirectory, fileName);
if (!File.Exists(fullPath))
{
Logger.Debug($"Config file '{fullPath}' not found, skipping.");
continue;
}
var ext = Path.GetExtension(fullPath).ToLowerInvariant();
switch (ext)
{
case ".ini":
configurationBuilder.AddIniFile(fullPath, true, false);
break;
case ".json":
configurationBuilder.AddJsonFile(fullPath, true, false);
break;
case ".toml":
configurationBuilder.AddTomlFile(fullPath, true, false);
break;
default:
Logger.Warn($"Unsupported config file extension: {ext}");
break;
}
}
Configuration = configurationBuilder.Build();
return Configuration;
}
}
}

View File

@@ -0,0 +1 @@
# Tribufu Configuration

View File

@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.Configuration</PackageId>
<Description>Tribufu Configuration Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Tomlyn.Extensions.Configuration" />
<PackageReference Include="Tomlyn" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,55 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Microsoft.Extensions.Configuration;
using System;
namespace Tribufu.Database
{
public class DatabaseConfiguration
{
public DatabaseDriver Driver { get; set; }
public string? Version { get; set; }
public string? Host { get; set; }
public string? Port { get; set; }
public string? User { get; set; }
public string? Password { get; set; }
public string? Schema { get; set; }
/// <summary>
/// Loads the <see cref="DatabaseConfiguration"/> from the "database" section or from root-level keys prefixed with "database_".
/// </summary>
/// <param name="configuration">The configuration source.</param>
/// <returns>The populated <see cref="DatabaseConfiguration"/> instance.</returns>
public static DatabaseConfiguration Load(IConfiguration configuration)
{
var section = configuration.GetSection("database");
var useRootFallback = !section.Exists();
string? GetConfig(string key) => useRootFallback ? configuration[$"database_{key}"] : section[key];
var driverString = GetConfig("driver") ?? throw new Exception("Missing database driver");
if (!Enum.TryParse<DatabaseDriver>(driverString, true, out var driver))
{
throw new Exception($"Unsupported database driver: {driverString}");
}
return new DatabaseConfiguration
{
Driver = driver,
Version = GetConfig("version"),
Host = GetConfig("host"),
Port = GetConfig("port"),
User = GetConfig("user"),
Password = GetConfig("password"),
Schema = GetConfig("schema")
};
}
}
}

View File

@@ -0,0 +1,12 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
namespace Tribufu.Database
{
public static class DatabaseConstants
{
public const uint DEFAULT_PAGINATION = 20;
public const uint MAX_PAGINATION = 100;
}
}

View File

@@ -0,0 +1,22 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
namespace Tribufu.Database
{
public enum DatabaseDriver : byte
{
MySql = 0,
Postgres = 1,
SqlServer = 2,
Oracle = 3,
Firebird = 4,
Sqlite = 5,
MongoDb = 6,
}
}

View File

@@ -0,0 +1 @@
# Tribufu Database

View File

@@ -0,0 +1,39 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Tribufu.Database.Repositories
{
public interface IRepository<T, K> where T : class
{
IList<T> GetAll();
Task<IList<T>> GetAllAsync();
IList<T> GetPage(uint page, uint limit);
Task<IList<T>> GetPageAsync(uint page, uint limit);
T? GetOne(K key);
Task<T?> GetOneAsync(K key);
T? Create(T entity);
Task<T?> CreateAsync(T entity);
T? Update(T entity);
Task<T?> UpdateAsync(T entity);
void Delete(K key);
Task DeleteAsync(K key);
void Delete(T entity);
Task DeleteAsync(T entity);
}
}

View File

@@ -0,0 +1,113 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Tribufu.Database.Repositories
{
public class Repository<C, T, K> : IRepository<T, K> where C : DbContext where T : class
{
protected readonly C _context;
protected readonly DbSet<T> _dbSet;
public Repository(C context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_dbSet = context.Set<T>();
}
public virtual IList<T> GetAll()
{
return [.. _dbSet];
}
public virtual async Task<IList<T>> GetAllAsync()
{
return await _dbSet.ToListAsync();
}
public virtual IList<T> GetPage(uint page, uint limit)
{
return _dbSet.Skip((int)((page < 1 ? 0 : page - 1) * limit)).Take((int)limit).ToList();
}
public virtual async Task<IList<T>> GetPageAsync(uint page, uint limit)
{
return await _dbSet.Skip((int)((page < 1 ? 0 : page - 1) * limit)).Take((int)limit).ToListAsync();
}
public virtual T? GetOne(K key)
{
return _dbSet.Find(key);
}
public virtual async Task<T?> GetOneAsync(K key)
{
return await _dbSet.FindAsync(key);
}
public virtual T? Create(T entity)
{
_dbSet.Add(entity);
var result = _context.SaveChanges();
return result > 0 ? entity : null;
}
public virtual async Task<T?> CreateAsync(T entity)
{
await _dbSet.AddAsync(entity);
var result = await _context.SaveChangesAsync();
return result > 0 ? entity : null;
}
public virtual T? Update(T entity)
{
_dbSet.Update(entity);
var result = _context.SaveChanges();
return result > 0 ? entity : null;
}
public virtual async Task<T?> UpdateAsync(T entity)
{
_dbSet.Update(entity);
var result = await _context.SaveChangesAsync();
return result > 0 ? entity : null;
}
public virtual void Delete(K key)
{
var entity = _dbSet.Find(key);
if (entity != null)
{
Delete(entity);
}
}
public virtual async Task DeleteAsync(K key)
{
var entity = await _dbSet.FindAsync(key);
if (entity != null)
{
await DeleteAsync(entity);
}
}
public virtual void Delete(T entity)
{
_dbSet.Remove(entity);
_context.SaveChanges();
}
public virtual async Task DeleteAsync(T entity)
{
_dbSet.Remove(entity);
await _context.SaveChangesAsync();
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.Database</PackageId>
<Description>Tribufu Database Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.Configuration\Tribufu.Configuration.csproj" />
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,8 +1,9 @@
// Copyright (c) Tribufu. All Rights Reserved. // Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: MIT
using dotenv.net; using dotenv.net;
using Tribufu.Generated.Client; using Tribufu.Generated.Client;
using Tribufu.Logging;
namespace Tribufu.Test namespace Tribufu.Test
{ {
@@ -10,21 +11,23 @@ namespace Tribufu.Test
{ {
public static async Task Main(string[] args) public static async Task Main(string[] args)
{ {
Logger.Initialize(LogLevel.Trace);
DotEnv.Load(new DotEnvOptions(ignoreExceptions: true, envFilePaths: [".env", "../../.env"])); DotEnv.Load(new DotEnvOptions(ignoreExceptions: true, envFilePaths: [".env", "../../.env"]));
var apiKey = Environment.GetEnvironmentVariable("TRIBUFU_API_KEY"); var apiKey = Environment.GetEnvironmentVariable("TRIBUFU_API_KEY");
var tribufu = new TribufuApi(apiKey ?? ""); var tribufu = new TribufuApi(apiKey ?? "");
Console.WriteLine(TribufuApi.GetVersion()); Logger.Debug(TribufuApi.GetUserAgent());
try try
{ {
var result = await tribufu.GetUserInfoAsync(); var result = await tribufu.GetUserInfoAsync();
Console.WriteLine(result); Logger.Debug(result.ToString());
} }
catch (ApiException e) catch (ApiException e)
{ {
Console.WriteLine(e.Message); Logger.Debug(e.Message);
} }
} }
} }

View File

@@ -1,11 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings> <IsPublishable>false</IsPublishable>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="dotenv.net" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
<ProjectReference Include="..\Tribufu\Tribufu.csproj" /> <ProjectReference Include="..\Tribufu\Tribufu.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1 +1 @@
# Tribufu # Tribufu Generated

View File

@@ -8,7 +8,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ImplicitUsings>enable</ImplicitUsings> <IsPublishable>false</IsPublishable>
<Nullable>annotations</Nullable> <Nullable>annotations</Nullable>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks> <TargetFrameworks>net6.0</TargetFrameworks>
@@ -17,7 +17,6 @@
<None Include="README.md" Pack="true" PackagePath="\" /> <None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="dotenv.net" />
<PackageReference Include="JsonSubTypes" /> <PackageReference Include="JsonSubTypes" />
<PackageReference Include="Newtonsoft.Json" /> <PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Polly" /> <PackageReference Include="Polly" />

View File

@@ -0,0 +1,20 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
namespace Tribufu.Logging
{
public enum LogLevel : byte
{
Off = 0,
Error = 1,
Warn = 2,
Info = 3,
Debug = 4,
Trace = 5,
}
}

View File

@@ -0,0 +1,54 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System;
namespace Tribufu.Logging
{
public static class Logger
{
private static LogLevel _level = LogLevel.Off;
public static void Initialize(LogLevel level = LogLevel.Off)
{
_level = level;
}
public static void Info(string message)
{
Log(LogLevel.Info, message, ConsoleColor.Green);
}
public static void Warn(string message)
{
Log(LogLevel.Warn, message, ConsoleColor.Yellow);
}
public static void Error(string message)
{
Log(LogLevel.Error, message, ConsoleColor.Red);
}
public static void Debug(string message)
{
Log(LogLevel.Debug, message, ConsoleColor.White);
}
public static void Trace(string message)
{
Log(LogLevel.Trace, message, ConsoleColor.DarkGray);
}
private static void Log(LogLevel level, string message, ConsoleColor color)
{
if (level <= _level)
{
var defaultColor = Console.ForegroundColor;
Console.ForegroundColor = color;
var timestamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
Console.WriteLine($"[{timestamp}] [{level.ToString().ToUpper()}]: {message}");
Console.ForegroundColor = defaultColor;
}
}
}
}

View File

@@ -0,0 +1 @@
# Tribufu Logging

View File

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.Logging</PackageId>
<Description>Tribufu Logging Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;net45;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,62 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: UNLICENSED
using CppAst;
using CppAst.CodeGen.Common;
using CppAst.CodeGen.CSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Tribufu.Platform;
using Zio.FileSystems;
namespace Tribufu.Native.Generator
{
public class Program
{
public static void Main(string[] args)
{
var applicationDirectory = Paths.GetApplicationDirectory();
var includeDirectory = Path.Combine(applicationDirectory, "..", "sdk-rust", "include");
var tribufuIncludeDirectory = Path.Combine(includeDirectory, "tribufu");
List<string> headerDirectories = [includeDirectory, tribufuIncludeDirectory];
Console.WriteLine(includeDirectory);
var options = new CSharpConverterOptions()
{
DefaultNamespace = "Tribufu.Native",
DefaultClassLib = "NativeLibrary",
DefaultOutputFilePath = "./src/Tribufu.Native/NativeLibrary.cs",
GenerateEnumItemAsFields = false,
TypedefCodeGenKind = CppTypedefCodeGenKind.NoWrap,
DefaultDllImportNameAndArguments = "\"tribufu_sdk\"",
};
options.IncludeFolders.AddRange(headerDirectories);
var headerFiles = headerDirectories.SelectMany(dir => Directory.EnumerateFiles(dir, "*.h")).ToList();
var compilation = CSharpConverter.Convert(headerFiles, options);
if (compilation.HasErrors)
{
foreach (CppDiagnosticMessage message in compilation.Diagnostics.Messages)
{
if (message.Type == CppLogMessageType.Error)
{
Console.WriteLine(message);
}
}
return;
}
using var fileSystem = new PhysicalFileSystem();
using var subFileSystem = new SubFileSystem(fileSystem, fileSystem.ConvertPathFromInternal("."));
var writer = new CodeWriter(new CodeWriterOptions(subFileSystem));
compilation.DumpTo(writer);
}
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPublishable>false</IsPublishable>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<UseAppHost>false</UseAppHost>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CppAst.CodeGen" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.Platform\Tribufu.Platform.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPublishable>false</IsPublishable>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,122 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using System;
using System.IO;
using System.Runtime.InteropServices;
using Tribufu.Logging;
namespace Tribufu.Platform
{
/// <summary>
/// Provides standardized access to important directories, such as config, saved data, logs, and platform-specific binaries.
/// This is especially useful for abstracting file path logic across environments (development, production, etc).
/// </summary>
public static class Paths
{
/// <summary>
/// Gets the root base directory of the application.
/// </summary>
/// <remarks>
/// - In development, this resolves to the root of the repository (five levels above bin/Debug or bin/Release).
/// - In production, it resolves to two levels above the binary location.
/// - It uses case-insensitive checks and runtime heuristics to improve accuracy.
/// </remarks>
/// <returns>The absolute path to the base directory.</returns>
public static string GetApplicationDirectory()
{
try
{
string baseDirectory;
string defaultBaseDirectory = AppContext.BaseDirectory;
bool isDevelopment = defaultBaseDirectory.ToLowerInvariant().Contains("debug");
if (isDevelopment)
{
// Go 5 levels up to simulate project root
baseDirectory = Path.Combine(defaultBaseDirectory, "..", "..", "..", "..", "..");
}
else
{
baseDirectory = Path.Combine(defaultBaseDirectory, "..", "..");
}
return Path.GetFullPath(baseDirectory);
}
catch (Exception ex)
{
Logger.Warn($"(Paths) Failed to resolve base directory: {ex.Message}");
return AppContext.BaseDirectory;
}
}
/// <summary>
/// Gets the path to the platform-specific binary directory.
/// </summary>
/// <returns>
/// The absolute path to <c>bin/&lt;runtime-identifier&gt;</c> if available,
/// otherwise falls back to <c>bin/dotnet</c>.
/// </returns>
public static string GetApplicationBinDirectory()
{
var binDirectory = Path.Combine(GetApplicationDirectory(), "bin");
if (!string.IsNullOrEmpty(RuntimeInformation.RuntimeIdentifier))
{
binDirectory = Path.Combine(binDirectory, RuntimeInformation.RuntimeIdentifier);
}
else
{
binDirectory = Path.Combine(binDirectory, "dotnet");
}
return binDirectory;
}
/// <summary>
/// Gets the path to the configuration directory.
/// </summary>
/// <returns>The absolute path to the <c>config</c> directory.</returns>
public static string GetApplicationConfigDirectory()
{
return Path.Combine(GetApplicationDirectory(), "config");
}
/// <summary>
/// Gets the path to the assets directory.
/// </summary>
/// <returns>The absolute path to the <c>assets</c> directory.</returns>
public static string GetApplicationAssetsDirectory()
{
return Path.Combine(GetApplicationDirectory(), "assets");
}
/// <summary>
/// Gets the path to the saved data directory.
/// </summary>
/// <returns>The absolute path to the <c>saved</c> directory.</returns>
public static string GetApplicationSavedDirectory()
{
return Path.Combine(GetApplicationDirectory(), "saved");
}
/// <summary>
/// Gets the path to the cache directory inside <c>saved</c>.
/// </summary>
/// <returns>The absolute path to the <c>saved/cache</c> directory.</returns>
public static string GetApplicationCacheDirectory()
{
return Path.Combine(GetApplicationSavedDirectory(), "cache");
}
/// <summary>
/// Gets the path to the logs directory inside <c>saved</c>.
/// </summary>
/// <returns>The absolute path to the <c>saved/logs</c> directory.</returns>
public static string GetApplicationLogsDirectory()
{
return Path.Combine(GetApplicationSavedDirectory(), "logs");
}
}
}

View File

@@ -0,0 +1 @@
# Tribufu Runtime

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.Platform</PackageId>
<Description>Tribufu Runtime Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<OutputType>Library</OutputType>
<TargetFrameworks>net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tribufu.ComponentModel\Tribufu.ComponentModel.csproj" />
<ProjectReference Include="..\Tribufu.Logging\Tribufu.Logging.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,46 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Newtonsoft.Json;
using System;
using System.Globalization;
namespace Tribufu.Serialization
{
public class DecimalNullableStringConverter : JsonConverter<decimal?>
{
public override decimal? ReadJson(JsonReader reader, Type objectType, decimal? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer)
{
string value = reader.Value?.ToString();
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
return decimal.Parse(value);
}
throw new JsonSerializationException($"Unexpected token {reader.TokenType} when parsing decimal?.");
}
public override void WriteJson(JsonWriter writer, decimal? value, JsonSerializer serializer)
{
if (value.HasValue)
{
writer.WriteValue(value.Value.ToString(CultureInfo.InvariantCulture));
}
else
{
writer.WriteNull();
}
}
}
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Newtonsoft.Json;
using System;
using System.Globalization;
namespace Tribufu.Serialization
{
public class DecimalStringConverter : JsonConverter<decimal>
{
public override decimal ReadJson(JsonReader reader, Type objectType, decimal existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String && decimal.TryParse(reader.Value?.ToString(), out var result))
{
return result;
}
if (reader.TokenType == JsonToken.Integer)
{
return Convert.ToUInt64(reader.Value);
}
throw new JsonSerializationException($"Unexpected token {reader.TokenType} when parsing decimal.");
}
public override void WriteJson(JsonWriter writer, decimal value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString(CultureInfo.InvariantCulture));
}
}
}

View File

@@ -0,0 +1 @@
# Tribufu Serialization

View File

@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>Tribufu.Serialization</PackageId>
<Description>Tribufu Serialization Extensions</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<AppDesignerFolder>Properties</AppDesignerFolder>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPublishable>false</IsPublishable>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;net45;net5.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,45 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Newtonsoft.Json;
using System;
namespace Tribufu.Serialization
{
public class ULongNullableStringConverter : JsonConverter<ulong?>
{
public override ulong? ReadJson(JsonReader reader, Type objectType, ulong? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
if (reader.TokenType == JsonToken.String || reader.TokenType == JsonToken.Integer)
{
string value = reader.Value?.ToString();
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
return ulong.Parse(value);
}
throw new JsonSerializationException($"Unexpected token {reader.TokenType} when parsing ulong?.");
}
public override void WriteJson(JsonWriter writer, ulong? value, JsonSerializer serializer)
{
if (value.HasValue)
{
writer.WriteValue(value.Value.ToString());
}
else
{
writer.WriteNull();
}
}
}
}

View File

@@ -0,0 +1,31 @@
// Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT
using Newtonsoft.Json;
using System;
namespace Tribufu.Serialization
{
public class ULongStringConverter : JsonConverter<ulong>
{
public override ulong ReadJson(JsonReader reader, Type objectType, ulong existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.String && ulong.TryParse(reader.Value?.ToString(), out var result))
{
return result;
}
if (reader.TokenType == JsonToken.Integer)
{
return Convert.ToUInt64(reader.Value);
}
throw new JsonSerializationException($"Unexpected token {reader.TokenType} when parsing ulong.");
}
public override void WriteJson(JsonWriter writer, ulong value, JsonSerializer serializer)
{
writer.WriteValue(value.ToString());
}
}
}

View File

@@ -8,7 +8,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ImplicitUsings>enable</ImplicitUsings> <IsPublishable>false</IsPublishable>
<Nullable>annotations</Nullable> <Nullable>annotations</Nullable>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks> <TargetFrameworks>net6.0</TargetFrameworks>

View File

@@ -1,6 +1,7 @@
// Copyright (c) Tribufu. All Rights Reserved. // Copyright (c) Tribufu. All Rights Reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
using System;
using System.Net; using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Tribufu.Generated.Api; using Tribufu.Generated.Api;
@@ -14,7 +15,7 @@ namespace Tribufu
/// <remarks> /// <remarks>
/// Use this class to interact with the Tribufu API. /// Use this class to interact with the Tribufu API.
/// </remarks> /// </remarks>
public class TribufuApi : TribufuGeneratedApi public sealed class TribufuApi : TribufuGeneratedApi
{ {
/// <summary> /// <summary>
/// The default base URL for the Tribufu API. /// The default base URL for the Tribufu API.
@@ -22,22 +23,9 @@ namespace Tribufu
public const string DefaultBaseUrl = "https://api.tribufu.com"; public const string DefaultBaseUrl = "https://api.tribufu.com";
/// <summary> /// <summary>
/// Create a <see cref="TribufuApi"/> with the default options. /// Create a <see cref="TribufuApi"/> instance.
/// </summary> /// </summary>
/// <returns><see cref="TribufuApi"/> instance with default configuration</returns> public TribufuApi(string? apiKey = null) : base(CreateConfiguration(apiKey))
public TribufuApi() : this(string.Empty)
{
}
/// <summary>
/// Create a <see cref="TribufuApi"/> with the given API key.
/// </summary>
/// <remarks>
/// A API key gives you public read only access to the Tribufu API.
/// </remarks>
/// <param name="apiKey">The API key for authentication</param>
/// <returns><see cref="TribufuApi"/> instance configured with the API key</returns>
public TribufuApi(string apiKey) : base(CreateConfiguration(apiKey))
{ {
} }
@@ -54,7 +42,7 @@ namespace Tribufu
/// Create a <see cref="TribufuApi"/> with the given API key. /// Create a <see cref="TribufuApi"/> with the given API key.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A API key gives you public read only access to the Tribufu API. /// An API key gives you public read only access to the Tribufu API.
/// </remarks> /// </remarks>
/// <param name="apiKey">The API key for authentication</param> /// <param name="apiKey">The API key for authentication</param>
/// <returns><see cref="TribufuApi"/> instance configured with the API key</returns> /// <returns><see cref="TribufuApi"/> instance configured with the API key</returns>
@@ -118,7 +106,7 @@ namespace Tribufu
/// <summary> /// <summary>
/// Gets the user agent string for the Tribufu API client. /// Gets the user agent string for the Tribufu API client.
/// </summary> /// </summary>
private static string GetUserAgent() public static string GetUserAgent()
{ {
var version = GetVersion(); var version = GetVersion();
var frameworkDescription = RuntimeInformation.FrameworkDescription.Trim(); var frameworkDescription = RuntimeInformation.FrameworkDescription.Trim();
@@ -126,6 +114,19 @@ namespace Tribufu
return $"Tribufu/{version} ({frameworkDescription}; {runtimeIdentifier})"; return $"Tribufu/{version} ({frameworkDescription}; {runtimeIdentifier})";
} }
/// <summary>
/// Checks if debug mode is enabled.
/// </summary>
/// <returns>True if debug mode is enabled, otherwise false</returns>
public static bool DebugEnabled()
{
#if DEBUG
return true;
#else
return false;
#endif
}
/// <summary> /// <summary>
/// Get the base URL for the Tribufu API. /// Get the base URL for the Tribufu API.
/// </summary> /// </summary>
@@ -147,23 +148,10 @@ namespace Tribufu
return DefaultBaseUrl; return DefaultBaseUrl;
} }
/// <summary>
/// Checks if debug mode is enabled.
/// </summary>
/// <returns>True if debug mode is enabled, otherwise false</returns>
private static bool DebugEnabled()
{
#if DEBUG
return true;
#else
return false;
#endif
}
/// <summary> /// <summary>
/// Creates a configuration for the Tribufu API client. /// Creates a configuration for the Tribufu API client.
/// </summary> /// </summary>
private static Configuration CreateConfiguration(string apiKey) private static Configuration CreateConfiguration(string? apiKey)
{ {
var config = new Configuration var config = new Configuration
{ {