Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic.Net
Namespace FileSystem.Protocols
'''
''' Represents a local file or remote file its location on the network.
''' (表示一个本地文件或者网络上面的文件的位置)
'''
Public Class FileURI
'''
''' The services portal of this remote filesystem object.
''' (远程文件服务对象的服务接口)
'''
'''
Public Property EntryPoint As IPEndPoint
'''
''' The reference location of this file system object on the target machine.
''' (目标机器()上面的文件系统的引用的位置)
'''
'''
Public Property File As String
'''
''' Is this file system object is a local file?.(是否为本地文件)
'''
'''
Public ReadOnly Property IsLocal As Boolean
Get
Return EntryPoint Is Nothing
End Get
End Property
Sub New(uri As String)
Dim addr As String = Regex.Match(uri, "^\d+@\d+(\.\d+){3}[:]\/\/").Value
If String.IsNullOrEmpty(addr) Then '本地文件
File = uri
EntryPoint = Nothing
Else ' 远程文件
File = uri.Replace(addr, "")
Dim Tokens As String() = addr.Split(":"c).First.Split("@"c)
EntryPoint = New IPEndPoint(Tokens(1), Scripting.CTypeDynamic(Of Integer)(Tokens(Scan0)))
End If
End Sub
Sub New(path As String, portal As IPEndPoint)
File = path
EntryPoint = portal
End Sub
Sub New()
End Sub
'''
''' {port}@{ipaddress}://C:\xxx\xxx.file
'''
'''
Public Overrides Function ToString() As String
If EntryPoint Is Nothing Then
Return File
Else
Return $"{EntryPoint.Port}@{EntryPoint.IPAddress}://{File}"
End If
End Function
'''
''' port@remote_IP://hash+<path>
'''
'''
'''
'''
Public Shared Sub FileStreamParser(uri As String, ByRef remote As IPEndPoint, ByRef handle As FileHandle)
Dim file As New FileURI(uri)
remote = file.EntryPoint
uri = file.File
Dim hash As String = Regex.Match(uri, "^\d+\+").Value
uri = Mid(uri, hash.Length + 1)
handle = New FileHandle With {
.FileName = uri,
.HashCode = Scripting.CTypeDynamic(Of Integer)(hash)
}
End Sub
End Class
End Namespace