DirectoryAccess
AtlasX.Engine.RemoteDirectory
class สำหรับอ่าน เขียน และจัดการไฟล์บน local file system
Namespace: AtlasX.Engine.RemoteDirectory
Implements: IDirectoryAccess
Constructors
DirectoryAccess(String)
| Parameter | Type | Required | Description |
rootPath | string | Required | Path หลักของ directory |
Properties
| Name | Type | Description |
RootPath | string | Root path หลักที่กำหนดตอน constructor |
PathName | string | Sub-path ที่ต่อจาก RootPath |
DestinationPath | string | Path เต็มที่ใช้งานจริง ได้จากการรวม RootPath และ PathName |
Methods
| Name | Return | Description |
FileExists(String) | bool | ตรวจสอบว่าไฟล์มีอยู่หรือไม่ |
SaveFile(String, Byte[]) | void | บันทึกไฟล์ลง DestinationPath |
GetFile(String) | FileStream | เปิดและคืนค่าไฟล์เป็น FileStream |
RemoveFile(String) | void | ลบไฟล์ออกจาก DestinationPath |
FileExtension(String, Boolean) | string | คืนค่านามสกุลไฟล์ |
DirectoryExists(String) | bool | ตรวจสอบว่า directory มีอยู่หรือไม่ |
CreateDirectory(String) | void | สร้าง directory |
RemoveDirectory(String) | void | ลบ directory และ contents ทั้งหมดภายใน |
GetHashFromPath(String, HashAlgorithmType) | string | คำนวณ hash ของไฟล์จาก path |
GetHashFromStream(FileStream, HashAlgorithmType) | string | คำนวณ hash ของไฟล์จาก FileStream |
Methods Details
FileExists(String)
ตรวจสอบว่าไฟล์มีอยู่ใน DestinationPath หรือไม่
Returns: bool–true ถ้าไฟล์มีอยู่
| Parameter | Type | Required | Description |
fileName | string | Required | ชื่อไฟล์ที่ต้องการตรวจสอบ |
SaveFile(String, Byte[])
บันทึกไฟล์ลง DestinationPath โดยสร้าง directory อัตโนมัติถ้ายังไม่มี
| Parameter | Type | Required | Description |
fileName | string | Required | ชื่อไฟล์ที่ต้องการบันทึก |
file | byte[] | Required | ข้อมูลไฟล์ในรูปแบบ byte array |
GetFile(String)
ดึงไฟล์จาก DestinationPath และคืนค่าเป็น FileStream
Returns: FileStream– stream ของไฟล์
| Parameter | Type | Required | Description |
fileName | string | Required | ชื่อไฟล์ที่ต้องการเปิด |
RemoveFile(String)
ลบไฟล์ออกจาก DestinationPath
ถ้าไฟล์ไม่มีอยู่จะ skip โดยไม่เกิด exception
| Parameter | Type | Required | Description |
fileName | string | Required | ชื่อไฟล์ที่ต้องการลบ |
FileExtension(String, Boolean)
คืนค่านามสกุลของไฟล์
| Parameter | Type | Required | Description |
fileName | string | Required | ชื่อไฟล์ |
excludeDot | bool | Optional | ถ้าเป็น true จะตัด . นำหน้าออก เช่น .pdf > pdf |
DirectoryExists(String)
ตรวจสอบว่า directory มีอยู่หรือไม่
Returns: bool–true ถ้า directory มีอยู่
| Parameter | Type | Required | Description |
directoryName | string? | Optional | ชื่อ sub-directory ถ้าไม่ระบุจะตรวจสอบที่ DestinationPath |
CreateDirectory(String)
สร้าง directory
| Parameter | Type | Required | Description |
directoryName | string? | Optional | ชื่อ sub-directory ถ้าไม่ระบุจะสร้างที่ DestinationPath |
RemoveDirectory(String)
ลบ directory และ contents ทั้งหมดภายใน
| Parameter | Type | Required | Description |
directoryName | string? | Optional | ชื่อ sub-directory ถ้าไม่ระบุจะลบที่ DestinationPath |
GetHashFromPath(String, HashAlgorithmType)
คำนวณ hash ของไฟล์จาก path
Returns: string– hash string ในรูปแบบ uppercase hex
| Parameter | Type | Required | Description |
filePath | string | Required | Path ของไฟล์ที่ต้องการคำนวณ hash (อิงจาก DestinationPath) |
algorithmType | HashAlgorithmType | Optional | Algorithm ที่ใช้คำนวณ hash ค่าเริ่มต้นคือ SHA256 |
GetHashFromStream(FileStream, HashAlgorithmType)
คำนวณ hash ของไฟล์จาก FileStream
Returns: string– hash string ในรูปแบบ uppercase hex
| Parameter | Type | Required | Description |
stream | FileStream | Required | FileStream ของไฟล์ที่ต้องการคำนวณ hash |
algorithmType | HashAlgorithmType | Optional | Algorithm ที่ใช้คำนวณ hash ค่าเริ่มต้นคือ SHA256 |