#Region "Microsoft.VisualBasic::ea59a5e11880b4d0f4759ad740bb81fe, ComputingServices\FileSystem\Protocols\FileURI.vb"
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see .
' /********************************************************************************/
' Summaries:
' Class FileURI
'
' Properties: EntryPoint, File, IsLocal
'
' Constructor: (+3 Overloads) Sub New
'
' Function: ToString
'
' Sub: FileStreamParser
'
'
' /********************************************************************************/
#End Region
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