Imports System.IO
Imports System.Reflection
Imports C1.Data.Entities

Class Application

    ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
    ' can be handled in this file.

    Public Shared ClientCache As EntityClientCache

    Private Sub Application_Startup(sender As Object, e As System.Windows.StartupEventArgs) Handles Me.Startup
        ' Specify where Entity Framework should look for the Northwind database.
        Dim folder As String = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "..\..\..\..\Data"))
        Dim dbFile As String = Path.Combine(folder, "Northwnd.mdf")
        AppDomain.CurrentDomain.SetData("DataDirectory", folder)
        If Not File.Exists(dbFile) Then
            Throw New Exception("Sample database Northwnd.mdf must be created in the Samples\\Data folder. Run the CreateSampleDB utility to create the Northwind database")
        End If

        ' Get a global ClientCache and save it in a static field
        ' so it is accessible from any class of the project.
        ClientCache = EntityClientCache.GetDefault(GetType(NORTHWNDEntities))
    End Sub

End Class
