using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Windows;
using System.IO;
using System.Reflection;

namespace Orders
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        static App()
        {
        }

        protected override void OnStartup(StartupEventArgs e)
        {
            // Specify where Entity Framework should look for the Northwind database.
            string folder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), @"..\..\..\..\Data"));
            string dbFile = Path.Combine(folder, "Northwnd.mdf");
            AppDomain.CurrentDomain.SetData("DataDirectory", folder);
            if (!File.Exists(dbFile))
                throw new Exception("Sample database Northwnd.mdf must be created in the Data folder. Run the CreateSampleDB utility to create the Northwind database");

            base.OnStartup(e);

            // Put the lists of cities and countries to the application resources
            // so they are accessible from any window or user control.
            var objectContext = (NORTHWNDEntities) C1.Data.Entities.EntityClientCache.GetDefault(typeof(NORTHWNDEntities)).DbContext;
            Resources.Add("Cities", objectContext.Cities);
            Resources.Add("Countries", objectContext.Countries);

            MainWindow window = new MainWindow();
            window.Show();
        }
    }
}
