コード例 #1
0
        protected void InitHandlers()
        {
            this.DEPENDENCIES = new Dictionary <string, object> {
            };

            Server.Log.Debugger.CallEvent(Server.net.Airtower.INFO_EVENT, "Loading server dependencies...");
            Assembly CurrentAssembly = Assembly.GetExecutingAssembly();
            string   Namespace       = "Times.Client.Dependencies"; // Change if if you mean to change the name space of the class

            // Prefer using String.Equal comparison.
            Type[] Dependencies = CurrentAssembly.GetTypes().Where(type => String.Equals(type.Namespace, Namespace, StringComparison.Ordinal) && type.IsClass &&
                                                                   !type.IsAbstract).ToArray();

            for (var _loc1_ = 0; _loc1_ < Dependencies.Length; _loc1_++)
            {
                try
                {
                    var    Class = Activator.CreateInstance(Dependencies[_loc1_]);
                    string linkage_name;

                    if (Dependencies[_loc1_].GetProperty("CLASS_LINKAGE_NAME") != null)
                    {
                        linkage_name = ((dynamic)Class).CLASS_LINKAGE_NAME;
                    }
                    else
                    {
                        linkage_name = Dependencies[_loc1_].Name;
                    }

                    this.DEPENDENCIES[linkage_name] = Class;
                }
                catch (Exception Excep)
                {
                    Server.Log.Debugger.CallEvent(Server.net.Airtower.ERROR_EVENT, "Unable to load dependency : \n" + Excep.InnerException);
                    Server.Log.Debugger.CallEvent(Server.net.Airtower.WARN_EVENT, "Server exited!");
                    Server.Log.Debugger.CallEvent(Server.net.Airtower.WARN_EVENT, Excep.ToString());
                    Console.Write("Press any key to exit...");
                    Console.Read();
                    Environment.Exit(0);
                }
            }

            Server.Log.Debugger.CallEvent(Server.net.Airtower.INFO_EVENT,
                                          String.Format("Successfully loaded {0} dependencies!", Dependencies.Length));
        }