Startup.cs

00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using System.Reflection;
00005 using System.IO;
00006 using Server.Data;
00007 using Server.Net;
00008 using System.Diagnostics;
00009 using System.Runtime.InteropServices;
00010 
00014 namespace Server
00015 {
00021     public class Startup
00022     {
00023         private static Catalogue catalogue;
00028         public static void Main(string[] args)
00029         {
00030             
00031             // Create the persistent data layer
00032             IPersistentData persistentdata = new BinaryData(Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location));
00033 
00034             #region Win32 Only!
00035             // Use interop to set a console control handler.
00036             MyWin32.SetConsoleCtrlHandler(new MyWin32.HandlerRoutine(delegate(Server.MyWin32.CtrlTypes type) {
00037                 if (catalogue != null)
00038                     catalogue.SaveData();
00039 
00040                 System.Environment.Exit(0);
00041 
00042                 return true;
00043             }), true);
00044             #endregion
00045 
00046             // Create the catalogue
00047             catalogue = new Catalogue(persistentdata);
00048 
00049             // Create new console
00050             ServerConsole sc = new ServerConsole(catalogue);
00051             // Create RMI server object
00052             RMIServer rs = new RMIServer(catalogue);
00053             // Start the server
00054             rs.Start();
00055            
00056             // Start the console
00057             sc.StartConsole();
00058             catalogue.SaveData();
00059         }
00060 
00061     }
00062     #region Win32 Only!
00063 
00064     // A simple class that exposes two static Win32 functions.
00065     // One is a delegate type and the other is an enumerated type.
00066     public class MyWin32
00067     {
00068         // Declare the SetConsoleCtrlHandler function 
00069         // as external and receiving a delegate.   
00070         [DllImport("Kernel32")]
00071         public static extern Boolean SetConsoleCtrlHandler(HandlerRoutine Handler,
00072             Boolean Add);
00073 
00074         // A delegate type to be used as the handler routine 
00075         // for SetConsoleCtrlHandler.
00076         public delegate Boolean HandlerRoutine(CtrlTypes CtrlType);
00077 
00078         // An enumerated type for the control messages 
00079         // sent to the handler routine.
00080         public enum CtrlTypes
00081         {
00082             CTRL_C_EVENT = 0,
00083             CTRL_BREAK_EVENT,
00084             CTRL_CLOSE_EVENT,
00085             CTRL_LOGOFF_EVENT = 5,
00086             CTRL_SHUTDOWN_EVENT
00087         }
00088     }
00089     #endregion
00090 
00091 }

Generated on Thu Dec 21 06:21:55 2006 for SCRAML by  doxygen 1.5.1-p1