Imports System.Text.RegularExpressions
Namespace Parsing
Public Class CreationOption
Public Enum DocumentFormat
Html
Txt
End Enum
Private _OneSourceOneDoc As Boolean = False
Private _IncludePrivates As Boolean = False
Private _ShowUndocumented As Boolean = True
Private _Format As DocumentFormat = DocumentFormat.Html
Public Property OneSourceOneDoc() As Boolean
Get
Return _OneSourceOneDoc
End Get
Set(ByVal Value As Boolean)
_OneSourceOneDoc = Value
End Set
End Property
Public Property IncludePrivates() As Boolean
Get
Return _IncludePrivates
End Get
Set(ByVal Value As Boolean)
_IncludePrivates = Value
End Set
End Property
Public Property ShowUndocumented() As Boolean
Get
Return _ShowUndocumented
End Get
Set(ByVal Value As Boolean)
_ShowUndocumented = Value
End Set
End Property
Public Property Format() As DocumentFormat
Get
Return _Format
End Get
Set(ByVal value As DocumentFormat)
_Format = value
End Set
End Property
End Class
Public Class DocumentationCreator
Private _Options As CreationOption
Private _DocumentTitle As String
Private _Sources As List(Of String)
Public ReadOnly Property Options() As CreationOption
Get
Return _Options
End Get
End Property
Public ReadOnly Property Sources() As List(Of String)
Get
Return _Sources
End Get
End Property
Public Property DocumentTitle() As String
Get
Return _DocumentTitle
End Get
Set(ByVal value As String)
_DocumentTitle = value
End Set
End Property
Sub New()
_Options = New CreationOption
_Sources = New List(Of String)
_DocumentTitle = "Progetto 1"
End Sub
Private Function AccomplishOptions(ByVal El As Entity) As Boolean
Dim IsPrivate As Boolean = (El.Declaration.Contains("Private") Or El.Declaration.Contains("Protected"))
Dim IsUndocumented As Boolean = El.Documentation.Summary.Contains("Documentazione assente")
Dim AccomplishPrivate As Boolean
Dim AccomplishUndocumented As Boolean
If (Me.Options.IncludePrivates = False) And IsPrivate Then
AccomplishPrivate = False
Else
AccomplishPrivate = True
End If
If (Me.Options.ShowUndocumented = False) And IsUndocumented Then
AccomplishUndocumented = False
Else
AccomplishUndocumented = True
End If
Return (AccomplishPrivate And AccomplishUndocumented)
End Function
Private Sub AppendComment(ByVal S As System.Text.StringBuilder, ByVal Value As String, ByVal Type As String, ByVal DisplayedName As String)
If String.IsNullOrEmpty(Value) Then
Exit Sub
End If
S.AppendLine("<tr>")
S.AppendFormat("<td class='{0}' width='20%'>{1}</td>{2}", Type, DisplayedName, vbCrLf)
S.AppendFormat("<td class='{0}'>{1}</td>{2}", Type, Value, vbCrLf)
S.AppendLine("</tr>")
End Sub
Private Sub AppendParams(ByVal S As System.Text.StringBuilder, ByVal Value As Comments.ParamCommentList, ByVal Type As String, ByVal DisplayedName As String)
If Value Is Nothing OrElse Value.Count = 0 Then
Exit Sub
End If
S.AppendLine("<tr>")
S.AppendFormat("<td class='{0}' width='20%'>{1}</td>{2}", Type, DisplayedName, vbCrLf)
S.AppendFormat("<td class='{0}'>", Type)
For Each Param As Comments.ParamComment In Value
S.AppendFormat("<b>{0}</b><br>{1}<br>{2}{2}", Param.ParameterName, Param.ParameterDescription, vbCrLf)
Next
S.AppendLine("</td>")
S.AppendLine("</tr>")
End Sub
Private Function ReplaceSpecialChar(ByVal S As String) As String
S = S.Replace("à", "à")
S = S.Replace("è", "è")
S = S.Replace("é", "é")
S = S.Replace("ì", "ì")
S = S.Replace("ò", "ò")
S = S.Replace("ù", "ù")
Return S
End Function
Private Sub AppendMemberList(ByVal S As System.Text.StringBuilder, ByVal El As Entity, ByVal Links As List(Of String))
Dim Text As String = El.Name & " <font style='font-size:8pt;'>(" & CodeParser.GetNameFromType(El.Type) & ")</font>"
Do While Links.Contains(El.Id)
El.Id &= "D"
Loop
Links.Add(El.Id)
If El.IsContainer Then
S.AppendFormat("<li> <a href='#{0}'>{1}</a> </li>{2}", El.Id, Text, vbCrLf)
S.AppendLine("<ul>")
For Each Child As Entity In El.Children
If AccomplishOptions(Child) Then
AppendMemberList(S, Child, Links)
End If
Next
S.AppendLine("</ul>")
Else
S.AppendFormat("<li> <a href='#{0}'>{1}</a> </li>{2}", El.Id, Text, vbCrLf)
End If
End Sub
Private Sub AppendMemberDocumentation(ByVal S As System.Text.StringBuilder, ByVal El As Entity)
Dim Doc As Comments.DocumentationComment = El.Documentation
Dim Header As String
If El.IsContainer Then
Header = "class"
S.AppendLine("<div class='container'>")
Else
Header = "member"
End If
S.AppendFormat("<div class='{0}'><a name='{1}'>{2}</a></div>{3}", Header, El.Id, El.Name & " <font style='font-size:11pt;'>(" & CodeParser.GetNameFromType(El.Type) & ")</font>", vbCrLf)
S.AppendLine("<table border='0' width='99%' align='center'>")
AppendComment(S, El.Declaration, "signature", "Signature")
AppendComment(S, Doc.Summary, "summary", "Descrizione")
AppendComment(S, Doc.Remarks, "remarks", "Dettagli")
AppendComment(S, Doc.See, "see", "Vedi anche")
AppendComment(S, Doc.SeeAlso, "see", "Vedi anche")
If El.GetCommentType() <> EntityCommentType.Generic Then
Dim DetailedDoc As Comments.MethodComment = CType(Doc, Comments.MethodComment)
AppendParams(S, DetailedDoc.Params, "params", "Parametri")
AppendParams(S, DetailedDoc.TypeParams, "typeparams", "Parametri Generics")
AppendParams(S, DetailedDoc.Exceptions, "exception", "Eccezioni")
AppendComment(S, DetailedDoc.Returns, "returns", "Valore restituito")
End If
S.AppendLine("</table>")
S.AppendLine("<br><br>")
If El.IsContainer Then
For Each Child As Entity In El.Children
If AccomplishOptions(Child) Then
AppendMemberDocumentation(S, Child)
End If
Next
S.AppendLine("</div>")
S.AppendLine("<br>")
End If
End Sub
Private Sub CreateHtml(ByVal Result As ParserResult, ByVal FileName As String, ByVal SourceName As String, Optional ByVal IsFirstFile As Boolean = True)
Dim Builder As New System.Text.StringBuilder()
Dim Links As New List(Of String)
If IsFirstFile Then
Builder.Append(My.Resources.ReportTemplate.Replace("|||Doc|||", Me.DocumentTitle))
End If
With Builder
If IsFirstFile Then
.AppendLine("<div class='doctitle'>Documentazione " & Me.DocumentTitle & "</div>")
End If
.AppendLine("<div class='filename'>" & SourceName & "</div>")
.AppendLine("<div class='subtitle'>Generata con TDocumentation dotNet v1.0</div><br>")
.AppendLine("Sintesi del progetto:")
.AppendLine("<ul>")
For Each El As Entity In Result
If AccomplishOptions(El) Then
AppendMemberList(Builder, El, Links)
End If
Next
.AppendLine("</ul>")
Links.Clear()
For Each El As Entity In Result
If AccomplishOptions(El) Then
AppendMemberDocumentation(Builder, El)
End If
Next
.AppendLine("</body>")
.AppendLine("</html>")
End With
IO.
File.
WriteAllText(FileName, ReplaceSpecialChar
(Builder.
ToString))
End Sub
Private Sub CreateHtml
(ByVal Folder As String)
Dim Parser As New CodeParser()
Dim Result As ParserResult
Dim CreatedFiles As New List(Of String)
Dim PutHeader As Boolean = True
For Each Source As String In Me.Sources
Dim File As String = Folder & "\Documentazione " & Me.
DocumentTitle & " (" & IO.
Path.
GetFileName(Source
) & ").html"
Parser.Load(Source)
Result = Parser.ParseCode
Me.
CreateHtml(Result,
File, IO.
Path.
GetFileName(Source
), PutHeader
)
If Me.Options.OneSourceOneDoc Then
PutHeader = False
End If
Next
If Me.Options.OneSourceOneDoc Then
Dim FinalDocumentText As New System.Text.StringBuilder
For Each File As String In CreatedFiles
FinalDocumentText.
AppendLine(IO.
File.
ReadAllText(File))
Next
IO.
File.
WriteAllText(Folder & "\Documentazione " & Me.
DocumentTitle & ".html", FinalDocumentText.
ToString)
End If
End Sub
Public Sub Create
(ByVal Folder As String)
If Me.Options.Format = CreationOption.DocumentFormat.Html Then
End If
End Sub
End Class
End Namespace