Exemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //if (e.Args != null && e.Args.Count() > 0)
            //{
            //    //this.Properties["IsStartup"] = e.Args[0];
            //    MessageBox.Show(e.Args[0].ToString());
            //}
            AppDomain.CurrentDomain.SetData("DataDirectory", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
            if (!File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ASDatabase.db"))
            {
                File.Copy(Directory.GetCurrentDirectory() + "\\App_Data\\ASDatabase.db", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ASDatabase.db", true);
            }

            DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
            var currentProcess = Process.GetCurrentProcess();
            var runningProcess = (from process in Process.GetProcesses()
                                  where
                                  process.Id != currentProcess.Id &&
                                  process.ProcessName.Equals(
                                      currentProcess.ProcessName,
                                      StringComparison.Ordinal)
                                  select process).FirstOrDefault();


            if (runningProcess != null)
            {
                runningProcess.Kill();
                runningProcess.Dispose();
            }

            SQLiteConnection conn = new SQLiteConnection("Data Source=" + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\ASDatabase.db");

            conn.Open();
            using (SQLiteCommand command = conn.CreateCommand())
            {
                command.CommandText = "vacuum;";
                command.ExecuteNonQuery();
            }
            conn.Close();
            try
            {
                var entities = new ASDatabaseEntities();
                int i        = entities.Alarms.Count();
            }
            catch (System.Exception)
            {
                RequirementsWindow w = new RequirementsWindow();
                w.ShowDialog();
            };
            base.OnStartup(e);
        }
 public MainWindow()
 {
     InitializeComponent();
     Closing += (s, e) => ViewModelLocator.Cleanup();
     entities = new ASDatabaseEntities();
 }