https://github.com/sapteamdev/commontk
All in One and Multi Purpose .NET Library
https://github.com/sapteamdev/commontk
config context setting statusbar timer toolkit tools utility
Last synced: 6 months ago
JSON representation
All in One and Multi Purpose .NET Library
- Host: GitHub
- URL: https://github.com/sapteamdev/commontk
- Owner: SAPTeamDEV
- License: mit
- Created: 2022-08-23T08:23:59.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-06-10T12:38:58.000Z (7 months ago)
- Last Synced: 2025-07-22T09:36:52.217Z (6 months ago)
- Topics: config, context, setting, statusbar, timer, toolkit, tools, utility
- Language: C#
- Homepage: https://www.nuget.org/packages/SAPTeam.CommonTK
- Size: 342 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# CommonTK - All-in-One and Multi-Purpose .NET Library
[](https://github.com/SAPTeamDEV/CommonTK/actions/workflows/main.yml)
[](https://codecov.io/gh/SAPTeamDEV/CommonTK)
[](https://www.nuget.org/packages/SAPTeam.CommonTK)
[](https://www.nuget.org/packages/SAPTeam.CommonTK)
CommonTK is a feature-rich toolkit for .NET applications, providing advanced context management, status providers, hierarchical settings, action groups, and more. It is designed for flexibility, extensibility, and performance.
## Installation
Install with dotnet CLI:
```bash
dotnet add package SAPTeam.CommonTK
```
## Features
### Contexts
Contexts allow you to define and manage global or private application states, with support for locking execution via action groups.
**Example: Custom Context**
```
public class ExampleContext : Context
{
public override string[] Groups => new[] { Context.ActionGroup(ActionScope.Application, "sample_action") };
public ExampleContext()
{
Initialize(true); // Register as global context. must be called after ctor logic, if not called, the context won't be registered and not working.
}
protected override void CreateContext()
{
// Initialization logic here
}
protected override void DisposeContext()
{
// Cleanup logic here
}
}
```
**Usage:**
```
using (var context = new ExampleContext())
{
// Code here runs with the context changes.
// In this state, the action group application.sample_action is locked and all methods that use it will be blocked.
}
// Action group is unlocked here.
```
### Action Groups
Action groups let you prevent unintended changes that may conflict eith the running context.
```
public void ModifyUnintendedValues()
{
Context.QueryGroup(Context.ActionGroup(ActionScope.Application, "sample_action"));
// Code here will only run if the action group is not locked
}
```
### Hierarchical Settings
Define and manage settings in a hierarchical structure, with type convention and import/export capabilities.
```
var root = new SettingsStore();
var setting = root.CreateSetting("app.theme", "dark", "UI theme");
setting.Value = "light";
string theme = setting.Value;
```
### Status Providers
Unified interfaces for reporting status, progress, and multi-status bars.
**Basic Status Provider:**
```
public class UIStatusProvider : IStatusProvider
{
private readonly Label status;
public UIStatusProvider(Label label) => status = label;
public void Clear() => status.Text = "";
public StatusIdentifier Write(string message)
{
status.Text = message;
return StatusIdentifier.Empty;
}
}
```
### Registry
A simple registry for managing resources with resource locations.
```
var registry = new Registry();
// Register a resource
var location = new ResourceLocation("private", "myimage");
var stream = File.OpenRead("path/to/image.png");
registry.TryAdd(location, stream);
// Retrieve a resource
var file = registry[location];
```
### Timer
Call a method after a specified time interval, with optional repeat functionality and exception handling.
```
var timer = new Timer(5000, () => SendMessage("test"), repeat: false);
// Stop or pause before the timer ends
timer.Pause(); // Only for repeating timers
timer.Stop();
// Get thrown exceptions
var exception = timer.Exceptions.FirstOrDefault();
```
## Security Reporting
If you discover any security vulnerabilities, please report them by following our [Security Guidelines](https://github.com/SAPTeamDEV/CommonTK/blob/master/SECURITY.md).
## Contributing
We welcome contributions! Please see our [Contributing guide](https://github.com/SAPTeamDEV/CommonTK/blob/master/CONTRIBUTING.md) for more information on how to get started.
## License
This project is licensed under the [MIT License](https://github.com/SAPTeamDEV/CommonTK/blob/master/LICENSE.md).