SAPTeam.CommonTK 2.0.4-alpha

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of SAPTeam.CommonTK.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SAPTeam.CommonTK --version 2.0.4-alpha
NuGet\Install-Package SAPTeam.CommonTK -Version 2.0.4-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SAPTeam.CommonTK" Version="2.0.4-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SAPTeam.CommonTK --version 2.0.4-alpha
#r "nuget: SAPTeam.CommonTK, 2.0.4-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SAPTeam.CommonTK as a Cake Addin
#addin nuget:?package=SAPTeam.CommonTK&version=2.0.4-alpha&prerelease

// Install SAPTeam.CommonTK as a Cake Tool
#tool nuget:?package=SAPTeam.CommonTK&version=2.0.4-alpha&prerelease

CommonTK - All in One and Multi Purpose .NET Library

Build status Nuget Nuget

This library has many Features and also provides Interfaces can be used in CommonTK.Console library and other .NET Application.

Installation

You can install this library with Package manager console.

SAPTeam.CommonTK

PM> Install-Package SAPTeam.CommonTK

Features

Contexts

Contexts is a key feature in this library. With contexts you can set a global situation and this change is visible across the program using Context.Current.HasContext<IContext>().

For using this feature you can implement a new class from IContext interface and Context base class, or use Contexts available in CommonTK.Console library.

JsonWorker and Config

JsonWorker is a base class for doing Json-related actions. A best place to use Json file, is Application onfig. Config class do it simply Just by getting a file name and a Serializer class.

This class gives you config data in Config.Prefs property that you can make changes on it and save changes using Config.Write() method. This is the Simplest way to save your Application settings or other type of data!

public class Entries
{
    public string UserName { get; set; }
    public string Password { get; set; }
}

// Loads config.json, if it is not existing create it.
Config<Entries> config = new("config.json");

// Set new values.
config.Prefs.UserName = "admin";
config.Prefs.Password = "12345";

// Save config.json.
config.Write();

Status Providers

There is a set of Interfaces and methods to work with IStatusProvider classes. This feature intended for Interacting with users and must be implemented by Application for work in a specified way.

You can deal with statuses using static methods of Interact class or directly with StatusProvider.Current. First you must Create and Assign a new instance of a class that implements IStatusProvider using Interact.AssignStatus(IStatusProvider) or:

StatusProvider.Current = new StatusProvider();

There is a variety types of Status Providers. All of that implements IStatusProvider as root Interface.

IStatusProvider

This interface has a basic functionality. Just a Write(string) and Clear() method for writing and clearing text. It is suitable for simple uses such as using a single label as Status Provider.

public class UIStatusProvider : IStatusProvider
{
    private readonly Label status;

    public UIStatusProvider(Label label)
    {
        status = label;
    }

    public void Clear()
    {
        status.Text = "";
    }

    public void Write(string message)
    {
        status.Text = message;
    }
}
IProgressStatusProvider

This interface is intended to use when you need to show a message with progress bar. It has two method Write(string, ProgressType) and Increment(int) for writing a message with progress bar and incrementing value of progress bar respectively. also Classes that implement this interface can throw exception Write(string) is called.

IMultiStatusBar

This interface intended for complicated usages. It is useful when you deal with a Control that support item collections, such as StatusStrip. you must declare a method to manage and control multi item collections.

This is a code from my AndroCtrl project:

public class AppStatusProvider : IProgressStatusProvider, IMultiStatusProvider
{
	readonly StatusStrip statusbar;
	ToolStripProgressBar progressbar;

	bool gc;

	readonly Dictionary<string, (ToolStripLabel label, ToolStripProgressBar progressBar)> packets = new();

	public AppStatusProvider(StatusStrip statusbar, bool garbageCollection = true)
	{
		this.statusbar = statusbar;
		gc = garbageCollection;
	}

	public void Clear()
	{
		if (statusbar.Items.Count > 0)
		{
			foreach (var packet in packets)
			{
				if (packet.Value.progressBar != progressbar)
				{
					Clear(packet.Key);
				}
			}

			if (progressbar != null)
			{
				throw new InvalidOperationException("Can't remove an unfinished progress bar.");
			}
		}
	}

	public void Clear(string message)
	{
		if (packets[message].progressBar == progressbar)
		{
			progressbar = null;
		}

		statusbar.Items.Remove(packets[message].label);
		statusbar.Items.Remove(packets[message].progressBar);
		packets.Remove(message);
	}

	public void Write(string message)
	{
		throw new NotImplementedException();
	}

	public void Write(string message, ProgressBarType type)
	{
		if (progressbar != null && type == ProgressBarType.Block)
		{
			throw new InvalidOperationException("Can't register more than one block progress bar.");
		}
		if (packets.ContainsKey(message))
		{
			throw new ArgumentException("Can't use a duplicated status message: ", message);
		}

		ToolStripLabel label = new(message);
		statusbar.Items.Add(label);

		switch (type)
		{
			case ProgressBarType.None:
				throw new ArgumentException("type can't be None.");
			case ProgressBarType.Wait:
				ToolStripProgressBar loadingbar = new();
				loadingbar.Style = ProgressBarStyle.Marquee;
				statusbar.Items.Add(loadingbar);
				packets[message] = (label, loadingbar);
				break;
			case ProgressBarType.Block:
				progressbar = new();
				statusbar.Items.Add(progressbar);
				packets[message] = (label, progressbar);
				break;
		}
	}

	public void Increment(int value)
	{
		if (value == -1)
		{
			progressbar.PerformStep();
		}
		else
		{
			progressbar.Increment(value);
		}

		if (gc && progressbar.Value >= 100)
		{
			Clear(packets.Where((x) => x.Value.progressBar == progressbar).First().Key);
		}
	}
}

Timer

Starts a simple timer in separate thread and calls the callback once or several times.

var timer = CommonTK.Timer.Set(5000. () => Environment.Exit(0), repeat: false);

Contribution

Feel free to grab the source, open issues or pull requests.

Credits

Almost all the Classes of this library were extracted from The public API of my private repository Windows Pro and published in two libraries, CommonTK and CommonTK.Console

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SAPTeam.CommonTK:

Package Downloads
SAPTeam.CommonTK.Console The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

All in One and Multi Purpose .NET Library for Professional Console actions. This library contains toolset of classes and methods that can be used by .NET Applications to perform Deep level Controls on Console. Key features of this library are: - Console Form: A way different way to Interact with your users. A Console User Interface! - Creating and Using console windows in Desktop Applications in The easiest way! - Colorize Your console text output! - Global Color Set. and more... For Getting started with this library and See more features you can visit the github page.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 134 3/18/2024
2.4.5 509 6/10/2023
2.4.1 257 5/1/2023
2.3.11 337 4/23/2023
2.3.9 190 4/23/2023
2.3.8 205 4/23/2023
2.3.7 200 4/23/2023
2.3.6 135 4/23/2023
2.3.5 139 4/23/2023
2.3.4 156 4/23/2023
2.3.3 497 4/14/2023
2.3.2 229 4/13/2023
2.2.20 140 4/13/2023
2.2.19 139 4/13/2023
2.2.18 144 4/13/2023
2.2.17 155 4/12/2023
2.2.16 145 4/12/2023
2.2.15 134 4/12/2023
2.2.14 146 4/11/2023
2.2.13 160 4/11/2023
2.2.12 149 4/11/2023
2.2.11 150 4/11/2023
2.2.9 162 4/11/2023
2.2.8 134 4/10/2023
2.2.7 145 4/10/2023
2.2.6 161 4/10/2023
2.2.4 167 4/10/2023
2.2.3 151 4/9/2023
2.2.2 174 4/9/2023
2.1.2 160 4/9/2023
2.1.1 175 4/6/2023
2.0.8 308 4/5/2023
2.0.7-alpha 106 4/5/2023
2.0.6-alpha 118 4/5/2023
2.0.5-alpha 114 4/4/2023
2.0.4-alpha 109 4/4/2023
2.0.3-alpha 91 4/4/2023
2.0.2-alpha 108 4/4/2023
2.0.1-alpha 89 4/4/2023
1.3.6 193 4/3/2023
1.3.5 170 4/3/2023
1.3.3 167 4/3/2023
1.3.2 169 4/3/2023
1.2.6 254 4/3/2023
1.2.5 361 4/1/2023
1.2.4 322 4/1/2023
1.2.3 497 3/31/2023
1.2.2 173 3/31/2023
1.2.1 169 3/31/2023
1.2.0 650 3/30/2023
1.1.16 177 3/30/2023
1.1.14 180 3/29/2023
1.1.13 182 3/29/2023
1.1.12 160 3/29/2023
1.1.11 173 3/29/2023
1.1.10 184 3/29/2023
1.1.9 192 3/29/2023
1.1.8 436 3/28/2023
1.1.1 280 3/28/2023
1.0.3 243 3/26/2023