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!
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
What things you need to install?
ToolBox supports netstandard2.1, netcoreapp3.1, net5.0, net6.0 and net7.0 target frameworks.
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.
In your project folder, where is located .csproj file run this command on terminal:
dotnet add package dein.ToolBox
Official documentation: dotnet add package
Clone ToolBox from GitHub on recommended path. Using this command on terminal:
| OS | Command |
|---|---|
| win | git clone https://github.com/deinsoftware/toolbox.git "D:\Developer\DEIN\Projects\_devTB" |
| mac | git 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:
| OS | Command |
|---|---|
| win | dotnet add reference "D:\Developer\DEIN\Projects\_devCC\ToolBox\ToolBox.csproj" |
| mac | dotnet 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
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
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.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 sourceIf 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());_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 pathInclude 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()}}_log.Save(exception,logLevel);//Save exception on filePlatform 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 LinuxOn 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.
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();}}_shell.Browse(url);//Open and URL in default browserRun 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 executedUsing 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);}_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.Include operations relative to System.
usingToolBox.System;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 definedNetwork.GetLocalIPv4();//Return current ip addressNetwork.GetOctetsIPv4(ip,number);//Return ip address with octets defined on numberUser.GetUserName();//Return logged usernameUser.GetMachine();//Return machine nameUser.GetDomain();//Return domain nameInclude operations relative to Transform Text.
usingToolBox.Transform;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.Include operations relative to Validations.
usingToolBox.Validations;Bool.SomeFalse(values[]);//Return true if there is false valueNumber.IsNumber(value);//Return true if value is numberNumber.IsOnRange(min,value,max);//Return true if number is between min and maxStrings.SomeNullOrEmpty(values[]);//Return true if there is an empty or null valueWeb.IsUrl(value);//Return true if value is an http or https valid address- .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.
Please read CONTRIBUTING for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the ToolBox on GitHub.
- Camilo Martinez [Equiman]
See also the list of contributors who participated in this project.
If this project help you reduce time to develop, you can give me a cup of coffee.
No sponsors yet! Will you be the first?
This project is licensed under the MIT License - see the LICENSE file for details.
- StackOverflow: The largest online community for programmers.
