# Auxiliary **Repository Path**: hl_zhang346/auxiliary ## Basic Information - **Project Name**: Auxiliary - **Description**: it is a collection of tool we used in past. 1. Export the data as excel. 2, Logger 3, ObjectCopier 4, Scanner 5, Zip 6, RestApi 7, Queue 8, DirectoryFileHelper - **Primary Language**: C# - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-08-16 - **Last Updated**: 2022-08-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: miniExcel, RestSharp ## README # Auxiliary #### Scanner class #### Read the following parameters from Scanner---Symbol DS6708 Barcode Scanner ```code     // check if all barcode 输入是否完毕 {EOT} If (Asc(e.KeyChar) == 4) {      // decode the keychar var scanner = New Scanner(_myKeyCode)               // get the value of Partnumber, Quantity, LotCode and DateCode var Partnumber = scanner.getPartNumber().Trim() var quantity = scanner.getQuantity var lotcode = scanner.getLotCode var datecode = scanner.getDateCode()           // 清除做为存取KeyCode Ascii value 的List _myKeyCode.Clear() } ``` ## RestApi #### Calling api with RestSharp and WebClient easily * Send() Send your request with RestSharp => Parameters : string baseUrl, string functionName, Method method, IDictionary headers, IDictionary parametersBody, string userName, string password => Return: IRestResponse ```bash IDictionary body = new Dictionary(); body.Add("action", action); body.Add("CellNumber", phoneNumber); IDictionary header = new Dictionary(); header.Add("content-type", "application/json;charset=UTF-8"); string output = RestApi.Send(url, header, body, "POST"); var responseDTO = JsonConvert.DeserializeObject(output); ``` * Send() Send your request with RestSharp => Parameters : string baseUrl, string functionName, Method method, IDictionary headers, object body, string userName, string password => Return: IRestResponse ```bash IDictionary body = new Dictionary(); body.Add("action", action); body.Add("CellNumber", phoneNumber); IDictionary header = new Dictionary(); header.Add("content-type", "application/json;charset=UTF-8"); string output = RestApi.Send(url, header, body, "POST"); var responseDTO = JsonConvert.DeserializeObject(output); ``` * Send() Send your request with WebClient => Parameters : string url, IDictionary headers, IDictionary parametersBody, string method = "GET", bool contentLength = true => Return: string ```bash IDictionary body = new Dictionary(); body.Add("action", action); body.Add("CellNumber", phoneNumber); IDictionary header = new Dictionary(); header.Add("content-type", "application/json;charset=UTF-8"); string output = RestApi.Send(url, header, body, "POST"); var responseDTO = JsonConvert.DeserializeObject(output); ``` ## Zip #### create a zip file of the files provided * Compress() Create a ZIP file of the files provided. => Parameters : IEnumerable< string > fileNames, string destinationFileName => Return: void * Compress() Compress entire folder by passing directory Path => Parameters : string directoryPath => Return: void * Decompress() Decompress *.zip file, if pathIsDirectory pass as false. (One Zip file) Decompress every *.zip files inside filder by passing directory Path, if pathIsDirectory pass as true. (Multiple Zip files) => Parameters : string path, bool pathIsDirectory = false => Return: void * Decompress() Decompress *.zip file by passing FileInfo If you pass newFileName, the zip file extracted on this path, otherwise it (if you pass newFileName as null, default value) the zip file extracted on the parent folder => Parameters : System.IO.FileInfo fileToDecompress, string newFileName = null => Return: void ## Queue #### it is a new data type * Push() push the values of a list to Queue * Pop() pop a object from queue #### ObjectCopier class #### Provides a method for performing a deep copy of an object * Clone() Perform a deep copy of the object via serialization. Be careful, The type must be serializable. => Parameters : T source => Return: T ```bash var person = new Person(); var clonedPerson = person.Clone(); ``` ## Logger class #### Logger helps you to log texts, to a *.log file - void Log(this Exception ex, string path = "") - void Log(this string text, string path = "") - void LogToNewFile(this string text, string path = "") - string Read(this string path) ## IniFile class #### read/Write/Delete a string from a specified section in IniFile - ReadString(string section, string key) - ReadBoolean(string section, string key) - ReadDecimal(string section, string key) - ReadDouble(string section, string key) - ReadFloat(string section, string key) - ReadInteger(string section, string key) - ReadDate(string section, string key) - ReadDateTime(string section, string) - WriteString(string section, string key, string value) - WriteBoolean(string section, string key, bool value) - WriteDecimal(string section, string key, decimal value) - WriteDouble(string section, string key, double value) - WriteFloat(string section, string key, float value) - WriteInteger(string section, string key, integer value) - WriteDate(string section, string key, date value) - WriteDateTime(string section, string, datetime value) - bool SectionExists(string section) - bool KeyExists(string section, string key) - void DeleteKey(string section, string key) - void DeleteSection(string section) #### DirectoryFileHelper class #### it is a collection of direcotry operation, Createfolder, copyFolder * CreateFolderIfNeeded() Create a folder if it doesn't exist => Parameters : string path => Return: bool ```bash DirectoryFileHelper.CreateFolderIfNeeded("C:/My Folder"); ``` * CopyFolder() Copy a Folder (including every files and sub folders in it) from 'sourcePath' to 'destinationPath' => Parameters : string sourcePath, string destinationPath => Return: bool ```bash DirectoryFileHelper.CopyFolder("C:/My Folder1", "C:/My Folder2"); ``` * CopyFile() Copy a File from 'sourcePath' to 'destinationPath' => Parameters : string sourcePath, string destinationPath => Return: bool ```bash DirectoryFileHelper.CopyFile("C:/My Folder1/image.jpg", "C:/My Folder2/image.jpg"); ``` * Download() Download a file by its 'url' and save it to 'destination' => Parameters : string url, string destination => Return: bool ```bash DirectoryFileHelper.Download("https://google.com/1.jpg", "C:/My Folder1/image.jpg"); ``` * IsImage() Undrasting this file is image or not => Parameters : string contentType => Return: bool ```bash DirectoryFileHelper.IsImage("C:/My Folder1", "C:/My Folder2"); ``` * GetMimeTypeFromFilePath() Get Mime Type From File Path => Parameters : string filePath => Return: string ```bash DirectoryFileHelper.GetMimeTypeFromFilePath("C:/My Folder1/image.jpg"); ``` * GetMimeTypeFromFilePath() Get Mime Type From File Format => Parameters : string format => Return: string ```bash DirectoryFileHelper.GetMimeTypeFromFilePath(".jpg"); ``` ## IpAddress class #### IpAddress helps you to work with IPs * IsInRange() Return true, if ip is in the range of lowerRange and upperRange => Parameters : IPAddress ip, IPAddress lowerRange, IPAddress upperRange => Return: bool