The main server entry point
예제 #1
0
파일: Program.cs 프로젝트: Cyral/Bricklayer
        static void Main(string[] args)
        {
            //Setup console events
            consoleHandler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(consoleHandler, true);

            //Setup forms stuff, to possibly be used if an error occurs and a dialog needs to be opened
            System.Windows.Forms.Application.EnableVisualStyles();
            System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

            Console.Title = title;

            //Only show error screen in release builds
            #if DEBUG
                Server = new Server();
                Server.Run();
            #else
                try
                {
                    Server = new Server();
                    Server.Run();
                }
                catch (Exception e)
                {
                    //Open all exceptions in an error dialog
                   System.Windows.Forms.Application.Run(new Bricklayer.Common.ExceptionForm(e));
            }
            #endif
        }
예제 #2
0
파일: IO.cs 프로젝트: Cyral/Bricklayer
        private static void LoadPlugin(Server server, string file)
        {
            //Verify file name
            if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
                return;

            Assembly asm = null;

            //Load file
            try
            {
                asm = Assembly.LoadFile(file);
            }
            catch (Exception)
            {
                Log.WriteLine(LogType.Error, "Unable to load {0}", file);
            }

            Type pluginInfo = null;
            try
            {
                Type[] types = asm.GetTypes();
                Type pluginType = typeof(IPlugin);

                foreach (var t in types)
                {
                    if (pluginType.IsAssignableFrom((Type)t))
                    {
                        pluginInfo = t;
                        break;
                    }
                }

                //Create instance of the plugin and add it to the server
                if (pluginInfo != null)
                {
                    Object instance = Activator.CreateInstance(pluginInfo);
                    IPlugin plugin = (IPlugin)instance;
                    server.RegisterPlugin(plugin);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(ex.ToString(), ConsoleColor.Red);
            }
        }
예제 #3
0
파일: IO.cs 프로젝트: Cyral/Bricklayer
        public static void LoadPlugins(Server server)
        {
            if (!Directory.Exists(pluginFolder))
                Directory.CreateDirectory(pluginFolder);
            string[] files = Directory.GetFiles(pluginFolder, "*.dll");

            List<string> loadedFiles = new List<String>(); //Temporary check for loaded files
            foreach (var file in files)
            {
                //Don't load duplicate files
                string md5 = GetFileMD5(file);
                if (!loadedFiles.Contains(md5))
                {
                    LoadPlugin(server, Path.Combine(Environment.CurrentDirectory, file));
                    loadedFiles.Add(md5);
                }
                else
                {
                    Log.WriteLine(string.Format("Duplicate plugin {0} ({1}) not loaded", Path.GetFileName(file), md5.Substring(0, 7)), ConsoleColor.Red);
                }
            }
        }