Skip to content

Repository files navigation

dein ToolBox [ Win+Mac+Linux ]

github-actions-buildgithub-actions-packnuget-versionnuget-downloadssonar-reliabilitysonar-securitysonar-maintainabilitysonar-coveragelicense

ToolBox

ToolBox was created to simplify and automate tasks related to the .Net console. Was born in HardHat project as a Class. Now grown up as a library and can be used by other console applications.

The Code is Dark and Full of Errors! Console is your friend ... don't be afraid!

Menu


Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

What things you need to install?

ToolBox supports netstandard2.1, netcoreapp3.1, net5.0, net6.0 and net7.0 target frameworks.

Installing

ToolBox is available as project or package. We strong recommend add as a NuGet package if don't need make modifications directly on the source code library.

Follow these instructions to add ToolBox in your project.

Add As Package

In your project folder, where is located .csproj file run this command on terminal:

dotnet add package dein.ToolBox

Official documentation: dotnet add package

Add As Reference

Clone ToolBox from GitHub on recommended path. Using this command on terminal:

OSCommand
wingit clone https://github.com/deinsoftware/toolbox.git "D:\Developer\DEIN\Projects\_devTB"
macgit clone https://github.com/deinsoftware/toolbox.git ~/Developer/DEIN/Projects/_devTB

In your project folder, where is located .csproj file run this command on terminal:

OSCommand
windotnet add reference "D:\Developer\DEIN\Projects\_devCC\ToolBox\ToolBox.csproj"
macdotnet add reference ~/Developer/DEIN/Projects/_devCC/ToolBox/ToolBox.csproj

Copy Command Bridge files on the path:

Inside your .csproj add Command Bridge files on build:

<ProjectSdk="Microsoft.NET.Sdk">
<ItemGroupCondition="'$(TargetFramework)' == 'net7.0'">
<!-- Command Bridge -->
<NoneUpdate="cmd.sh"CopyToOutputDirectory="PreserveNewest" />
<NoneUpdate="cmd.bat"CopyToOutputDirectory="PreserveNewest" />
<!-- Projects -->
<ProjectReferenceInclude="..\..\_devTB\ToolBox\ToolBox.csproj" />
</ItemGroup>
</Project>

Official documentation: dotnet add reference

Back to menu


Usage

Keep calm, you are almost done. Review this usage steps and enjoy life.

To understand how this library works, take a look inside Sample folder. Better easy to use a guide than words.

Just go to Sample project folder and run this command on terminal:

cd Sample
dotnet run

Files

Include operations relative to File System and implements IFileSystem and ICommandSystem with specific actions and commands per Operative System.

usingToolBox.Files;

On the main class Program, add static properties DiskConfigurator and PathsConfigurator and inside the Main method create an instance of the library according the Operative System.

classProgram{publicstaticDiskConfigurator_disk{get;set;}publicstaticPathsConfigurator_path{get;set;}staticvoidMain(string[]args){_disk=newDiskConfigurator(FileSystem.Default);switch(OS.GetCurrent()){case"win":_path=newPathsConfigurator(CommandSystem.Win,FileSystem.Default);break;case"mac":_path=newPathsConfigurator(CommandSystem.Mac,FileSystem.Default);break;}//Foo()//Bar()}}

If you want to use _path and/or _disk in other class, add a static using to Program class:

usingstaticNamesapace.Program;

replace Namespace with a defined namespace in your project.

Disk

_disk.FilterCreator(extension[]);//Create a Regex with accepted extensions._disk.CopyAll(source,destination,overwrite,filter[]);//Copy all files and folder from source to destination_disk.CopyDirectories(source,destination);//Copy all folder from source to destination_disk.CopyFiles(source,destination,overwrite,filter[]);//Copy all files from source to destination_disk.DeleteAll(source,recursive);//Delete all files and folders from source

If you want get Notifications about copy or delete process, need implement the INotificationSystem interface.

publicsealedclassConsoleNotificationSystem:INotificationSystem{publicvoidShowAction(stringaction,stringmessage){_colorify.Wrap($" [{action}] {message}",txtPrimary);}}

And send it as a parameter on DiskConfiguration definition.

_disk=newDiskConfigurator(FileSystem.Default,newConsoleNotificationSystem());

Paths

_path.Combine(values[]);//Return combined path. Automatic detect `~` as user folder_path.GetDirectories(path,filter);//Return Folders inside path_path.GetFiles(path,filter);//Return Files inside path

Log

Include operations relative to Logs and implements the IFileSystem with specific actions and commands per Operative System.

usingToolBox.Log;

On the main class Program, add static properties ILogSystem and inside the Main method create an instance of the class according a value (maybe in your config system).

classProgram{privatestaticConfig_conf{get;set;}privatestaticILogSystem_log{get;set;}staticvoidMain(string[]args){_conf=Settings.Read();switch(_conf.log.system){case"csv":_log=newFileLogCsv(FileSystem.Default,_path.Combine("~"),".application.log");break;case"txt":_log=newFileLogTxt(FileSystem.Default,_path.Combine("~"),".application.log");break;}//Foo()//Bar()}}

Save

_log.Save(exception,logLevel);//Save exception on file

Platform

Platform namespace for Operative System detection and commands.

usingToolBox.Platform;OS.IsWin();//Return true on WindowsOS.IsMac();//Return true on MacOSOS.IsGnu();//Return true on LinuxOS.GetCurrent();//Return "win" on Windows//Return "mac" on MacOS//Return "gnu" on Linux

Shell

On the main class Program, add static properties ShellConfigurator and inside the Main method create an instance of the library according the Operative System.

usingToolBox.Bridge;

On the main class Program, add static properties ILogSystem and inside the Main method create an instance of the class according a value (maybe in your config system).

usingstaticToolBox.Notification;
classProgram{publicstaticINotificationSystem_notificationSystem{get;set;}publicstaticIBridgeSystem_bridgeSystem{get;set;}publicstaticShellConfigurator_shell{get;set;}staticvoidMain(string[]args){_notificationSystem=newConsoleNotificationSystem();//Or _notificationSystem = NotificationSystem.Default;switch(OS.GetCurrent()){case"win":_bridgeSystem=BridgeSystem.Bat;break;case"mac":case"gnu":_bridgeSystem=BridgeSystem.Bash;break;}_shell=newShellConfigurator(_bridgeSystem,_notificationSystem);//Foo()//Bar()}}

If you want to use _shell in other class, add a static using to Program class:

usingstaticNamesapace.Program;

replace Namespace with a defined namespace in your project.

Notification

If you want customize shell output need implement the INotificationSystem interface or can use default implementation with NotificationSystem.Default static class.

usingToolBox.Notification;
publicsealedclassConsoleNotificationSystem:INotificationSystem{privatestring_pastMessage{get;set;}="";publicvoidStandardOutput(stringmessage){vardiff=message.Except(_pastMessage).ToArray();if(diff.Length<=2&&message.Contains("%"))//Control Progress Messages{Console.SetCursorPosition(0,Console.CursorTop-1);}_colorify.Wrap($" {message}",txtPrimary);_pastMessage=message;}publicvoidStandardWarning(stringmessage){_colorify.Wrap($" {message}",txtWarning);}publicvoidStandardError(stringmessage){_colorify.Wrap($" {message}",txtDanger);}publicvoidStandardLine(){_colorify.BlankLines();}}

Browse

_shell.Browse(url);//Open and URL in default browser

Term

Run a command in a shell terminal.

_shell.Term(command);//Run a command in hidden mode_shell.Term(command,Output.Hidden);//Run a command in hidden mode_shell.Term(command,Output.Internal);//Run a command in internal mode, showing his results in same terminal with INotificationSystem implementation_shell.Term(command,Output.External);//Run a command in a new terminal window_shell.Term(command,Output.Internal,path);//Path parameter define a path where the command needs to be executed

Using Response to receive command result with: code, stdout and stderr

Responseresult=_shell.Term("dotnet --version",Output.Hidden);_shell.Result(result.stdout,"Not Installed");_colorify.WriteLine(result.code.ToString(),txtInfo);if(result.code==0){_colorify.WriteLine($"Command Works :D",txtSuccess);}else{_colorify.WriteLine(result.stderr,txtDanger);}

Result

_shell.Result(value);//Clean special characters from value and print in terminal._shell.Result(value,warningMessage);//Clean special characters from value and print in terminal or it's empty show the warningMessage.

System

Include operations relative to System.

usingToolBox.System;

Environment Variables

Env.GetValue(key);//Return value from keyEnv.SetValue(key,value);//Set value to key (only for program session, not permanent)Env.IsNullOrEmpty(key);//Return true when value from key is defined

Network

Network.GetLocalIPv4();//Return current ip addressNetwork.GetOctetsIPv4(ip,number);//Return ip address with octets defined on number

User

User.GetUserName();//Return logged usernameUser.GetMachine();//Return machine nameUser.GetDomain();//Return domain name

Transform

Include operations relative to Transform Text.

usingToolBox.Transform;

Strings

Strings.CleanSpecialCharacters(value);//Receive an string and clean \r (carriage return) and \n (new line) characters.Strings.RemoveWords(value,wordsToRemove[]);//Return value without removed wordsStrings.GetWord(value,wordPosition);//Search in value the wordPosition and return the word.Strings.SplitLines[](value,wordPosition);//Receive a value string and split on array when found \n (New Line) character and return an array with all lines.Strings.ExtractLine(value,search);//Receive a value string and split on array when found \n (New Line) character and return first line with search value.Strings.ExtractLine(value,search,wordsToRemove[]);//Receive a value string and split on array when found \n (New Line) character and return first line with search value and removeWords defined.

Validations

Include operations relative to Validations.

usingToolBox.Validations;

Boolean

Bool.SomeFalse(values[]);//Return true if there is false value

Number

Number.IsNumber(value);//Return true if value is numberNumber.IsOnRange(min,value,max);//Return true if number is between min and max

Strings

Strings.SomeNullOrEmpty(values[]);//Return true if there is an empty or null value

Web

Web.IsUrl(value);//Return true if value is an http or https valid address

Back to menu


About

Built With

  • .Net - .Net is a free and open-source web framework, developed by Microsoft and the community.
  • VS Code - Code editing redefined.
  • SonarQube - Continuous code quality.

Contributing

Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the ToolBox on GitHub.

Authors

See also the list of contributors who participated in this project.

Sponsors

If this project help you reduce time to develop, you can give me a cup of coffee.

GitHub Sponsorspaypal

No sponsors yet! Will you be the first?

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Back to menu

About

dein ToolBox - C# .Net Library with utilities like: command line, files, log, platform, shell, system, transform and validation [ Win+Mac+Linux ]

Topics

Resources

Code of conduct

Contributing

Stars

58 stars

Watchers

5 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages