<%@ Application Language="VB" %>

<script runat="server">
    '<moduleinfo>
    '   Creator: © Prostoysoft
    '   Created: 2010-04-29
    '   Description: project SimpleSite
    '</moduleinfo>

    '// Application //
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next
        
        '<setting russian culture
        Dim ci As System.Globalization.CultureInfo, sName As String
        sName = System.Threading.Thread.CurrentThread.CurrentCulture.Name 'eg "ru-RU"
        If sName <> "ru-RU" Then
            ci = New System.Globalization.CultureInfo("ru-RU")
            System.Threading.Thread.CurrentThread.CurrentCulture = ci
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci
        End If
        '/>
        
        Application("WS") = New SSService.CService1
        SSService.CService1.ApplicationStart(Server.MapPath(""))
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        SSService.CService1.CloseDb() 'CLOSE DB
    End Sub
    
    '// Session //
    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next
        
        '<setting russian culture
        Dim ci As System.Globalization.CultureInfo, sName As String
        sName = System.Threading.Thread.CurrentThread.CurrentCulture.Name 'eg "ru-RU"
        If sName <> "ru-RU" Then
            ci = New System.Globalization.CultureInfo("ru-RU")
            System.Threading.Thread.CurrentThread.CurrentCulture = ci
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci
        End If
        '/>
        
        SSService.CService1.SessionStart()
    End Sub
    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        On Error Resume Next 'тут Session.Count = 0
        
        Dim sUserID As String = Application(Session.SessionID)
        If sUserID > "" Then
            SSService.CService1.SetUserLastLogoutTime(sUserID)
        End If
        SSCommon.DeleteOldFilesByPattern(Session("ImagesFolder"), "temp_*", False, 1)
        SSCommon.DeleteOldFilesByPattern(Session("DocumentsFolder"), "temp_*", False, 1)
        SSService.CService1.CloseDb() 'CLOSE DB
    End Sub
    
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        Dim sPath As String
        sPath = Request.Path
        If sPath Like "*.aspx" Then
            SSService.CService1.OpenDb() 'OPEN DB
        End If
    End Sub
    Protected Sub Application_EndRequest(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim sPath As String
        sPath = Request.Path
        If sPath Like "*.aspx" Then
            SSService.CService1.CloseDb() 'CLOSE DB
        End If
    End Sub
    
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        'Code that runs when an unhandled error occurs
    End Sub
</script>