Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Vazor/FileProvider/VazorFileInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Imports Microsoft.Extensions.FileProviders
Public Class VazorFileInfo
Implements IFileInfo

Private view As MemoryStream
Private path As String
Private ReadOnly view As MemoryStream
Private ReadOnly path As String

Public Sub New(ByVal path As String)
Me.path = path
view = VazorViewMapper.Find(path)
Me.view = VazorViewMapper.Find(path)
End Sub

Public ReadOnly Property Exists() As Boolean Implements IFileInfo.Exists
Expand All @@ -29,13 +29,13 @@ Public Class VazorFileInfo

Public ReadOnly Property Length() As Long Implements IFileInfo.Length
Get
Return view.Length
Return Me.view.Length
End Get
End Property

Public ReadOnly Property Name() As String Implements IFileInfo.Name
Get
Return path
Return Me.path
End Get
End Property

Expand All @@ -46,7 +46,7 @@ Public Class VazorFileInfo
End Property

Public Function CreateReadStream() As Stream Implements IFileInfo.CreateReadStream
Return view
Return Me.view
End Function

End Class
32 changes: 16 additions & 16 deletions Vazor/FileProvider/VazorViewMapper.vb
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
Imports System.Collections.Concurrent
Imports System.Threading
Imports System.IO
Imports System.Text

Public Class VazorViewMapper
Shared map As New ConcurrentDictionary(Of String, ViewInfo)
Private Shared ReadOnly map As New ConcurrentDictionary(Of String, ViewInfo)

Public Shared Function Add(view As VazorView) As String
Dim key = view.Name & "_" & Guid.NewGuid.ToString
Dim key = view.Name & "_" & Guid.NewGuid.ToString()
If map.TryAdd(key, New ViewInfo(view.Content, view.Path, 1)) Then Return key
Return ""
End Function

Public Shared Sub AddStatic(view As VazorView)
Dim key = IO.Path.Combine(ViewInfo.FixPath(view.Path), view.Name) + ".cshtml"
Dim key = ViewInfo.FixPath(Path.Combine(view.Path, view.Name)) + ".cshtml"
map.TryAdd(key, New ViewInfo(view.Content, view.Path, -1))
End Sub

Public Shared Function Find(Path As String) As IO.MemoryStream
Public Shared Function Find(Path As String) As MemoryStream
Dim key = ViewInfo.FixPath(Path)
If map.ContainsKey(key) Then
Return New IO.MemoryStream(map(key).ViewContent)
Dim value As ViewInfo = Nothing
If map.TryGetValue(key, value) Then
Return New MemoryStream(value.ViewContent)
Else
Dim viewPath = ViewInfo.FixPath(IO.Path.GetDirectoryName(Path))
Dim viewName = IO.Path.GetFileNameWithoutExtension(Path)

If map.ContainsKey(viewName) Then
Dim vd = map(viewName)
Dim vd As ViewInfo = Nothing
If map.TryGetValue(viewName, vd) Then
If vd.Path = viewPath Then
If vd.Times = 1 Then
vd.Times = 2
ElseIf vd.Times = 2 Then ' if Times = -1 it is a lauout view, don't delete it
ElseIf vd.Times = 2 Then ' if Times = -1 it is a layout view, don't delete it
map.TryRemove(viewName, Nothing)
End If
Return New IO.MemoryStream(vd.ViewContent)
ElseIf Not viewName.StartsWith("_") Then
Return New IO.MemoryStream(Text.Encoding.UTF8.GetBytes(CreatePage(viewName)))
Return New MemoryStream(vd.ViewContent)
ElseIf Not viewName.StartsWith("_"c) Then
Return New MemoryStream(Encoding.UTF8.GetBytes(CreatePage(viewName)))
Else
Return Nothing
End If
Expand All @@ -45,8 +46,7 @@ Public Class VazorViewMapper
End Function

Private Shared Function CreatePage(viewName As String) As Char()
Return _
$"@page
Return $"@page
@model {viewName}Model

<div>
Expand Down
6 changes: 3 additions & 3 deletions Vazor/FileProvider/ViewInfo.vb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Friend Class ViewInfo
Public ViewContent As Byte()
Public Path As String
Public Times As Integer
Public Property ViewContent As Byte()
Public Property Path As String
Public Property Times As Integer

Public Sub New(viewContent() As Byte, path As String, times As Integer)
Me.ViewContent = viewContent
Expand Down
24 changes: 12 additions & 12 deletions Vazor/VazorExtensions.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Imports System.Runtime.CompilerServices
Imports ZML

Public Module VazorExtensions
Public Const Ampersand = "__amp__;"
Public Const GreaterThan = "__gtn__;"
Public Const LessThan = "__ltn__;"
Public Const Ampersand As String = "__amp__;"
Public Const GreaterThan As String = "__gtn__;"
Public Const LessThan As String = "__ltn__;"

<Extension>
Public Function ToHtmlString(x As XElement, ParamArray tagsToRemove() As String) As String
Expand All @@ -20,15 +20,15 @@ Public Module VazorExtensions

For Each tag In tagsToRemove
Dim open, close As String
If tag.StartsWith("<") Then
If tag.StartsWith("<"c) Then
open = tag
close = tag.Insert(1, "/")
Else
open = "<" + tag
close = "</" + tag
End If

If Not tag.EndsWith(">") Then
If Not tag.EndsWith(">"c) Then
open += ">"
close += ">"
End If
Expand All @@ -43,19 +43,19 @@ Public Module VazorExtensions

<Extension>
Public Function ParseTemplate(Of T)(xml As XElement, model As T) As String
Dim result = From elm In xml.Descendants()
Where elm.Attribute("ForEach") IsNot Nothing
Dim result As IEnumerable(Of XElement) = From elm In xml.Descendants()
Where elm.Attribute("ForEach") IsNot Nothing

Dim newHtml As New Text.StringBuilder(xml.ToString(SaveOptions.DisableFormatting))
Dim mFields() As FieldInfo = Nothing
Dim mProperties() As PropertyInfo = Nothing

Dim tag = ""
Dim attrValue = ""
Dim tag As String = ""
Dim attrValue As String = ""
Dim newContent As Text.StringBuilder = Nothing

Dim Evaluate = Sub(m As Object)
Dim newTag = tag
Dim newTag As String = tag
Dim exp As String
For Each f In mFields
exp = $"<{attrValue}.{f.Name} />"
Expand All @@ -69,13 +69,13 @@ Public Module VazorExtensions
newContent.AppendLine(newTag)
End Sub

For Each elm In result
For Each elm As XElement In result
Dim content = elm.ToString(SaveOptions.DisableFormatting)
attrValue = elm.Attribute("ForEach").Value
tag = content.Replace($" ForEach={"""" + attrValue + """"}", "")
newContent = New Text.StringBuilder()

Dim modelType = GetType(T)
Dim modelType As Type = GetType(T)
Dim type As Type = Nothing
If modelType.IsGenericType Then
type = modelType.GetGenericArguments()(0)
Expand Down
7 changes: 2 additions & 5 deletions Vazor/VazorSharedView.vb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
End Sub

Public Shared Sub CreateAll()

Dim types = From t In Reflection.Assembly.GetCallingAssembly().GetTypes()
Where t.IsClass AndAlso
Not t.IsAbstract AndAlso
t.IsSubclassOf(GetType(VazorSharedView))
Dim types As IEnumerable(Of Type) = From t In Reflection.Assembly.GetCallingAssembly().GetTypes()
Where t.IsClass AndAlso Not t.IsAbstract AndAlso t.IsSubclassOf(GetType(VazorSharedView))

For Each type As Type In types
Activator.CreateInstance(type)
Expand Down
2 changes: 1 addition & 1 deletion Vazor/VazorView.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Public Overridable ReadOnly Property Content() As Byte()
Get
Dim html = GetVbXml().ParseZml
Dim html As String = GetVbXml().ParseZML()
Return Encoding.GetBytes(html)
End Get
End Property
Expand Down