Aselia.Common.Hotswap.DomainManager.InitializeCore C# (CSharp) Method

InitializeCore() private method

private InitializeCore ( Assembly asm ) : void
asm System.Reflection.Assembly
return void
        private void InitializeCore(Assembly asm)
        {
            Type[] types = (from x in asm.GetTypes()
                            where x.BaseType == typeof(ServerBase)
                            select x).ToArray();
            if (types.Length != 1)
            {
                throw new InvalidOperationException("There must be exactly one type extending ServerBase in the core assembly.");
            }

            try
            {
                if (Server == null)
                {
                    Server = (ServerBase)types[0].GetConstructor(new Type[] { typeof(DomainManager) }).Invoke(new object[] { this });
                }
                else
                {
                    ServerBase old = Server;
                    Server = (ServerBase)types[0].GetConstructor(new Type[] { typeof(DomainManager), typeof(ServerBase) }).Invoke(new object[] { this, Server });
                    old.Unload();
                    Server.Load();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to instantiate or hotswap the core server.", ex);
            }
        }