Click here to Skip to main content
15,896,201 members
Articles / Web Development / HTML

Gallery Server Pro - An ASP.NET Gallery for Sharing Photos, Video, Audio and Other Media

Rate me:
Please Sign up or sign in to vote.
4.86/5 (131 votes)
18 Oct 2013GPL331 min read 829.7K   539  
Gallery Server Pro is a complete, stable ASP.NET gallery for sharing photos, video, audio and other media. This article presents the overall architecture and major features.
Option Strict On
Option Explicit On

Imports System
Imports System.Diagnostics

Public Class TraceEntry
	Public RunGuid As System.Guid
	Public TraceLevel As TraceLevel
	Public ValueName As String
	Public Value As Object
	Public TraceIssue As TraceIssues
	Public Issue As String
	Public NameSpaceName As String
	Public ClassName As String
	Public MethodName As String
	Public MethodBase As Reflection.MethodBase
	Public Row As Int32
	Public Col As Int32

	Public Sub New( _
							ByVal runGUID As System.Guid, _
							ByVal stackFrame As StackFrame, _
							ByVal params() As Object, _
							ByVal traceLevel As TraceLevel, _
							ByVal value As Object, _
							ByVal valueName As String, _
							ByVal traceIssue As TraceIssues, _
							ByVal issue As String)
		SetStack(stackFrame, params)
		Me.RunGuid = runGUID
		Me.TraceLevel = traceLevel
		Me.Value = value
		Me.ValueName = valueName
		Me.TraceIssue = traceIssue
		Me.Issue = issue
	End Sub

	Public Overrides Function ToString() As String
		Return FormatTraceOutput(Me.RunGuid, Me.NameSpaceName, Me.ClassName, _
								Me.MethodName, Me.Row, Me.Col, Me.ValueName, _
								Me.ValueName, Me.TraceLevel, Me.TraceIssue, Me.Issue)
	End Function

	Public Shared Function FormatTraceOutput( _
							ByVal runGUID As System.Guid, _
							ByVal stackFrame As StackFrame, _
							ByVal params() As Object, _
							ByVal traceLevel As TraceLevel, _
							ByVal value As Object, _
							ByVal valueName As String, _
							ByVal traceIssue As TraceIssues, _
							ByVal issue As String) _
							As String
		Dim nspace As String = String.Empty
		Dim className As String = String.Empty
		Dim methodName As String = String.Empty
		Dim row As Int32
		Dim col As Int32

		SetStack(stackFrame, params, nspace, className, methodName, row, col)
		Return FormatTraceOutput(runGUID, nspace, className, methodName, row, col, _
								value, valueName, traceLevel, traceIssue, issue)

	End Function

	Public Shared Function FormatTraceOutput( _
							ByVal runGUID As System.Guid, _
							ByVal nspace As String, _
							ByVal className As String, _
							ByVal methodName As String, _
							ByVal row As Int32, _
							ByVal col As Int32, _
							ByVal value As Object, _
							ByVal valueName As String, _
							ByVal traceLevel As TraceLevel, _
							ByVal traceIssue As TraceIssues, _
							ByVal issue As String) _
							As String
		Dim sVal As String
		If value Is Nothing Then
			sVal = ""
		Else
			sVal = value.ToString
		End If
		If sVal.Length > 0 Then
			If valueName Is Nothing OrElse valueName = "" Then
				sVal = "(Value=" & sVal & ")"
			Else
				sVal = "(" & valueName & "=" & sVal & ")"
			End If
		End If
		'Return runGUID.ToString & "-" & DateTime.Now.ToString & "-" & _
		'         nspace & "." & className & "." & methodName & _
		'         " row,col=" & row.ToString & "," & col.ToString & _
		'         sVal & " level=" & traceLevel.ToString() & " - " & issue
		Return "(" & traceLevel.ToString() & ") " & issue.Trim() & "; " & nspace & "." & className & "." & methodName & " (" & row.ToString & _
			"," & col.ToString & ") " & sVal
	End Function


#Region "Private Support Routines"

	Private Sub SetStack( _
					 ByVal stackFrame As StackFrame, _
					 ByVal params() As Object)

		' string[] stackdetails = stackFrame.GetMethod().Trim().Split('.')
		MethodBase = stackFrame.GetMethod()
		NameSpaceName = MethodBase.ReflectedType.Namespace
		ClassName = MethodBase.ReflectedType.Name
		MethodName = MethodWithParams(MethodBase, params)
		Row = stackFrame.GetFileLineNumber
		Col = stackFrame.GetFileColumnNumber
	End Sub

	Private Shared Sub SetStack( _
					 ByVal stackFrame As StackFrame, _
					 ByVal params() As Object, _
					 ByRef nspace As String, _
					 ByRef className As String, _
					 ByRef methodName As String, _
					 ByRef row As Int32, _
					 ByRef col As Int32)

		' string[] stackdetails = stackFrame.GetMethod().Trim().Split('.')
		Dim method As Reflection.MethodBase = stackFrame.GetMethod()
		nspace = method.ReflectedType.Namespace
		className = method.ReflectedType.Name
		methodName = MethodWithParams(method, params)
		row = stackFrame.GetFileLineNumber
		col = stackFrame.GetFileColumnNumber

	End Sub

	Private Shared Function MethodWithParams( _
					 ByVal method As Reflection.MethodBase, _
					 ByVal params() As Object) _
					 As String
		' The decision not to use a StringBuilder was deliberate
		' I don't expect more than six parameters often, and I do 
		' expect frequently to have none. 
		Dim ret As String = method.Name & "("
		Dim methodparams As Reflection.ParameterInfo()
		methodparams = method.GetParameters()
		If Tools.SkipArguments Or methodparams.Length = 0 Then
			Return ret & ")"
		Else
			If params Is Nothing Then
				For i As Int32 = 0 To methodparams.GetUpperBound(0)
					ret &= methodparams(i).ParameterType.Name & ", "
				Next
				Return ret.Substring(0, ret.Length - 1) & ")"
			ElseIf methodparams.Length <> params.Length Then
				Return ret & " trace param info is inconsistent )"
			Else
				For i As Int32 = 0 To methodparams.GetUpperBound(0)
					If methodparams(i).ParameterType Is GetType(System.String) Then
						ret &= methodparams(i).ParameterType.Name & " " & _
										 methodparams(i).Name & "=" & _
										 """" & params(i).ToString & """, "
						'ElseIf GetType(Windows.Forms.Control).IsAssignableFrom(methodparams(i).ParameterType) Then
						'   ret &= methodparams(i).ParameterType.Name & " " & _
						'            methodparams(i).Name & "=" & _
						'            """" & CType(params(i), Windows.Forms.Control).Name & """, "
					Else
						ret &= methodparams(i).ParameterType.Name & " " & _
										 methodparams(i).Name & "=" & _
										 params(i).ToString & ", "
					End If
				Next
				Return ret.Substring(0, ret.Length - 2) & ")"
			End If
		End If
	End Function
#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior) Tech Info Systems
United States United States
I have nearly 20 years of industry experience in software development, architecture, and Microsoft Office products. My company Tech Info Systems provides custom software development services for corporations, governments, and other organizations. Tech Info Systems is a registered member of the Microsoft Partner Program and I am a Microsoft Certified Professional Developer (MCPD).

I am the creator and lead developer of Gallery Server Pro, a free, open source ASP.NET gallery for sharing photos, video, audio, documents, and other files over the web. It has been developed over several years and has involved thousands of hours. The end result is a robust, configurable, and professional grade gallery that can be integrated into your web site, whether you are a large corporation, small business, professional photographer, or a local church.

Comments and Discussions