| 1 | #Region "Microsoft.VisualBasic::62c2943496b0132cd5dcce5a958e738f, Microsoft.VisualBasic.Core\Net\MIME\ContentType.vb" |
| 2 | |
| 3 | ' Author: |
| 4 | ' |
| 5 | ' asuka (amethyst.asuka@gcmodeller.org) |
| 6 | ' xie (genetics@smrucc.org) |
| 7 | ' xieguigang (xie.guigang@live.com) |
| 8 | ' |
| 9 | ' Copyright (c) 2018 GPL3 Licensed |
| 10 | ' |
| 11 | ' |
| 12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
| 13 | ' |
| 14 | ' |
| 15 | ' This program is free software: you can redistribute it and/or modify |
| 16 | ' it under the terms of the GNU General Public License as published by |
| 17 | ' the Free Software Foundation, either version 3 of the License, or |
| 18 | ' (at your option) any later version. |
| 19 | ' |
| 20 | ' This program is distributed in the hope that it will be useful, |
| 21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | ' GNU General Public License for more details. |
| 24 | ' |
| 25 | ' You should have received a copy of the GNU General Public License |
| 26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 | |
| 28 | |
| 29 | |
| 30 | ' /********************************************************************************/ |
| 31 | |
| 32 | ' Summaries: |
| 33 | |
| 34 | ' Structure ContentType |
| 35 | ' |
| 36 | ' Properties: Details, FileExt, IsEmpty, MIMEType, Name |
| 37 | ' |
| 38 | ' Function: __createObject, ToString |
| 39 | ' |
| 40 | ' |
| 41 | ' /********************************************************************************/ |
| 42 | |
| 43 | #End Region |
| 44 | |
| 45 | Imports System.Data.Linq.Mapping |
| 46 | Imports System.Runtime.CompilerServices |
| 47 | Imports Microsoft.VisualBasic.Language.Default |
| 48 | Imports Microsoft.VisualBasic.Text |
| 49 | |
| 50 | Namespace Net.Protocols.ContentTypes |
| 51 | |
| 52 | ''' <summary> |
| 53 | ''' MIME types / Internet Media Types |
| 54 | ''' </summary> |
| 55 | Public Structure ContentType : Implements IsEmpty |
| 56 | |
| 57 | ''' <summary> |
| 58 | ''' Type name or brief info |
| 59 | ''' </summary> |
| 60 | ''' <returns></returns> |
| 61 | Public Property Name As String |
| 62 | ''' <summary> |
| 63 | ''' MIME Type / Internet Media Type |
| 64 | ''' </summary> |
| 65 | ''' <returns></returns> |
| 66 | <Column(Name:="MIME Type / Internet Media Type")> Public Property MIMEType As String |
| 67 | |
| 68 | ''' <summary> |
| 69 | ''' File Extension |
| 70 | ''' </summary> |
| 71 | ''' <returns></returns> |
| 72 | <Column(Name:="File Extension")> |
| 73 | Public Property FileExt As String |
| 74 | |
| 75 | ''' <summary> |
| 76 | ''' More Details |
| 77 | ''' </summary> |
| 78 | ''' <returns></returns> |
| 79 | <Column(Name:="More Details")> Public Property Details As String |
| 80 | |
| 81 | Public ReadOnly Property IsEmpty() As Boolean Implements IsEmpty.IsEmpty |
| 82 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 83 | Get |
| 84 | Return Name Is Nothing AndAlso |
| 85 | MIMEType Is Nothing AndAlso |
| 86 | FileExt Is Nothing AndAlso |
| 87 | Details Is Nothing |
| 88 | End Get |
| 89 | End Property |
| 90 | |
| 91 | Public Overrides Function ToString() As String |
| 92 | Return $"{MIMEType} (*{FileExt})" |
| 93 | End Function |
| 94 | |
| 95 | Friend Shared Function __createObject(line As String) As ContentType |
| 96 | Dim tokens As String() = line.Split(ASCII.TAB) |
| 97 | |
| 98 | If tokens.IsNullOrEmpty OrElse tokens.Length < 3 Then |
| 99 | Call line.Warning |
| 100 | Return Nothing |
| 101 | Else |
| 102 | Dim mime As New ContentType With { |
| 103 | .Name = tokens(Scan0), |
| 104 | .MIMEType = tokens(1), |
| 105 | .FileExt = tokens(2), |
| 106 | .Details = tokens(3) |
| 107 | } |
| 108 | Return mime |
| 109 | End If |
| 110 | End Function |
| 111 | End Structure |
| 112 | End Namespace |