SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
Program.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Runtime.InteropServices;
6 using System.IO;
7 
8 namespace SeciUserInterface
9 {
10  class Program
11  {
12  [STAThread]
13  static void Main()
14  {
15  //See if Seci is already running, if so ignore this request
16  if (SeciRunning())
17  {
18  return;
19  }
21  comObj.InitialiseCom();
22 
23  App app = new App();
24  app.MainWindow = new UserInterface();
25  app.MainWindow.Show();
26  app.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(app_DispatcherUnhandledException);
27 
28  try
29  {
30  app.Run();
31  }
32  catch (Exception err)
33  {
34  //Dump the error message to file
35  DumpErrorToFile(err);
36  }
37 
38  comObj.DisposeCom();
39  }
40 
41  static void app_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
42  {
43  //Dump the error message to file
44  DumpErrorToFile(e.Exception);
45 
46  e.Handled = true;
47  }
48 
49  private static void DumpErrorToFile(Exception err)
50  {
51  String loc = System.Reflection.Assembly.GetExecutingAssembly().Location;
52  String file = loc.Substring(0, loc.LastIndexOf('\\')) + "\\Seci_crash.log";
53  using (StreamWriter sw = new StreamWriter(file, true))
54  {
55  String date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
56  sw.WriteLine(date + " " + err.Message + " " + err.Source);
57  sw.WriteLine(err.StackTrace);
58  }
59  }
60 
61  private static Boolean SeciRunning()
62  {
63  System.Diagnostics.Process[] procList;
64  procList = System.Diagnostics.Process.GetProcessesByName("SeciUserInterface");
65 
66  if (procList.GetLength(0) > 1)
67  {
68  return true;
69  }
70 
71  return false;
72  }
73  }
74 }
static void app_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
Definition: Program.cs:41
static void Main()
Definition: Program.cs:13
Interaction logic for SeciUserInterface.xaml
This class is for accessing Seci via COM. The COM interface is registered when Seci starts and unregi...
Definition: ComInterface.cs:21
static void DumpErrorToFile(Exception err)
Definition: Program.cs:49
static Boolean SeciRunning()
Definition: Program.cs:61