Public Class AuditManager
Public Enum AuditType
Exception
General
End Enum
Public Shared Function GetPath() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function
Public Shared Sub Write(ByVal _Type As AuditType?, ByVal _Description As String, Optional ByVal _Location As String = Nothing, Optional ByVal _Except As Exception = Nothing)
Dim _Stack As System.Diagnostics.StackTrace
If _Except IsNot Nothing Then
_Stack = New System.Diagnostics.StackTrace(_Except, True)
Else
_Stack = Nothing
End If
Using _F As New IO.StreamWriter(GetPath() & FormatDateTime(Date.Now, DateFormat.ShortDate).Replace("/", String.Empty) & ".LOG", True)
Dim tmpString As New Text.StringBuilder
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("WHEN:" & vbCrLf)
tmpString.Append(Date.Now & vbCrLf)
If _Type.HasValue Then
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("TYPE:" & vbCrLf)
tmpString.Append([Enum].GetName(GetType(AuditType), _Type) & vbCrLf)
End If
If _Location IsNot Nothing Then
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("LOCATION:" & vbCrLf)
tmpString.Append(_Location & vbCrLf)
End If
tmpString.Append("-------------------------------------------------" & vbCrLf)
If _Stack IsNot Nothing Then
tmpString.Append("STACKTRACE:" & vbCrLf)
tmpString.Append(_Stack.ToString() & vbCrLf)
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("STACK FRAMES:" & vbCrLf)
For Each frame In _Stack.GetFrames()
tmpString.Append(" - FILE:" & frame.GetFileName() & vbCrLf)
tmpString.Append(" - METHOD:" & frame.GetMethod().Name & vbCrLf)
tmpString.Append(" - LINE:" & frame.GetFileLineNumber() & vbCrLf)
tmpString.Append(" - COLUMN:" & frame.GetFileColumnNumber() & vbCrLf)
Next
End If
If _Except IsNot Nothing Then
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("SOURCE:" & vbCrLf)
tmpString.Append(_Except.Source & vbCrLf)
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("MESSAGE:" & vbCrLf)
tmpString.Append(_Except.Message & vbCrLf)
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("DATA:" & vbCrLf)
tmpString.Append(_Except.Data.ToString() & vbCrLf)
End If
tmpString.Append("-------------------------------------------------" & vbCrLf)
tmpString.Append("NOTES:" & vbCrLf)
tmpString.Append(_Description & vbCrLf)
tmpString.Append("-------------------------------------------------" & vbCrLf)
_F.Write(tmpString.ToString())
_F.Close()
End Using
End Sub
End Class
Imports System.Reflection
Imports System.IO
Imports System.Net
Imports System.Threading.Tasks
Module WarmUpService
Private _SiteList As New List(Of Typing)
Public Sub Main()
AuditManager.Write(AuditManager.AuditType.General, "Fireing Up...")
DoTheWarmUp()
AuditManager.Write(AuditManager.AuditType.General, "All Set...")
End Sub
Private Sub DoTheWarmUp()
Try
Parallel.Invoke(Sub()
SetAllowUnsafeHeaderParsing20()
End Sub,
Sub()
Dim _X As XElement = XElement.Load(AuditManager.GetPath() & "Settings.xml")
_SiteList = (From n In _X...<Site>.AsParallel()
Select New Typing() With {
.Page = n.@page,
.Url = n.@url
}).ToList()
Parallel.ForEach(_SiteList, Sub(Item)
Using _WC As New WebClient()
_WC.Headers.Add("user-agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13")
_WC.DownloadData(Item.Url & Item.Page)
End Using
End Sub)
End Sub)
Catch ex As Exception
AuditManager.Write(AuditManager.AuditType.Exception, "There was an issue!", "DoTheWarmUp", ex)
End Try
End Sub
Private Sub SetAllowUnsafeHeaderParsing20()
Dim a As New System.Net.Configuration.SettingsSection
Dim aNetAssembly As System.Reflection.Assembly = Assembly.GetAssembly(a.GetType)
Dim aSettingsType As Type = aNetAssembly.GetType("System.Net.Configuration.SettingsSectionInternal")
Dim args As Object() = Nothing
Dim anInstance As Object = aSettingsType.InvokeMember("Section", BindingFlags.Static Or BindingFlags.GetProperty Or BindingFlags.NonPublic, Nothing, Nothing, args)
Dim aUseUnsafeHeaderParsing As FieldInfo = aSettingsType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic Or BindingFlags.Instance)
aUseUnsafeHeaderParsing.SetValue(anInstance, True)
End Sub
Partial Public Class Typing
Public Property Url As String
Public Property Page As String
End Class
End Module
<Settings>
<Site url="http://www.o7thwebdesign.com" page="/" />
<Site url="http://www.facchinifacchinipa.com" page="/" />
<Site url="http://skor.in" page="/" />
<Site url="http://o7t.in" page="/" />
</Settings>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)