コード例 #1
0
 public HttpApiServer(HttpConfig serverConfig)
 {
     mFileLog        = new FileLogWriter("BEETLEX_HTTP_SERVER");
     FrameSerializer = this;
     if (serverConfig != null)
     {
         ServerConfig = serverConfig;
     }
     else
     {
         ServerConfig = LoadConfig();
     }
     mActionFactory  = new ActionHandlerFactory(this);
     mResourceCenter = new StaticResurce.ResourceCenter(this);
     mUrlRewrite     = new RouteRewrite(this);
     mModuleManage   = new ModuleManage(this);
 }
コード例 #2
0
 public HttpApiServer(HttpOptions options)
 {
     mFileLog        = new FileLogWriter("BEETLEX_HTTP_SERVER");
     FrameSerializer = this;
     if (options != null)
     {
         Options = options;
     }
     else
     {
         Options = LoadOptions();
     }
     mActionFactory  = new ActionHandlerFactory(this);
     mResourceCenter = new StaticResurce.ResourceCenter(this);
     mUrlRewrite     = new RouteRewrite(this);
     mModuleManage   = new ModuleManage(this);
 }
コード例 #3
0
ファイル: HttpApiServer.cs プロジェクト: Xusp/FastHttpApi
        public void Open()
        {
            NetConfig config = new NetConfig();

            config.Host                = ServerConfig.Host;
            config.Port                = ServerConfig.Port;
            config.CertificateFile     = ServerConfig.CertificateFile;
            config.CertificatePassword = ServerConfig.CertificatePassword;
            config.BufferSize          = ServerConfig.BufferSize;
            config.LogLevel            = ServerConfig.LogLevel;
            config.Combined            = ServerConfig.PacketCombined;
            config.SessionTimeOut      = ServerConfig.SessionTimeOut;
            config.UseIPv6             = ServerConfig.UseIPv6;
            config.BufferPoolMaxMemory = ServerConfig.BufferPoolMaxMemory;
            if (!string.IsNullOrEmpty(config.CertificateFile))
            {
                config.SSL = true;
            }
            config.LittleEndian = false;
            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp = new HttpPacket(this, this);

            mServer = SocketFactory.CreateTcpServer(config, this, hp);
            Name    = "BeetleX Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = ServerConfig.StaticResourcePath;
            mResourceCenter.Debug = ServerConfig.Debug;
            mResourceCenter.Load();
            ModuleManage.Load();
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = ServerConfig.UrlIgnoreCase;
            mUrlRewrite.AddRegion(this.ServerConfig.Routes);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };
            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi start@[v:{typeof(HttpApiServer).Assembly.GetName().Version}]");
        }
コード例 #4
0
        public void Open()
        {
            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp = new HttpPacket(this, this);

            mServer = SocketFactory.CreateTcpServer(this, hp)
                      .Setting(o =>
            {
                o.DefaultListen.Host  = Options.Host;
                o.DefaultListen.Port  = Options.Port;
                o.BufferSize          = Options.BufferSize;
                o.LogLevel            = Options.LogLevel;
                o.Combined            = Options.PacketCombined;
                o.SessionTimeOut      = Options.SessionTimeOut;
                o.UseIPv6             = Options.UseIPv6;
                o.BufferPoolMaxMemory = Options.BufferPoolMaxMemory;
                o.LittleEndian        = false;
            });
            if (Options.SSL)
            {
                mServer.Setting(o =>
                {
                    o.AddListenSSL(Options.CertificateFile, Options.CertificatePassword, o.DefaultListen.Host, Options.SSLPort);
                });
            }
            Name = "BeetleX Http Server";
            if (mAssemblies != null)
            {
                foreach (System.Reflection.Assembly assembly in mAssemblies)
                {
                    mResourceCenter.LoadManifestResource(assembly);
                }
            }
            mResourceCenter.LoadManifestResource(typeof(HttpApiServer).Assembly);
            mResourceCenter.Path  = Options.StaticResourcePath;
            mResourceCenter.Debug = Options.Debug;
            mResourceCenter.Load();
            ModuleManage.Load();
            ServerStatusController serverStatusController = new ServerStatusController();

            mActionFactory.Register(serverStatusController);
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase;
            mUrlRewrite.AddRegion(this.Options.Routes);
            HeaderTypeFactory.Find(HeaderTypeFactory.HOST);
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                using (System.IO.StreamWriter writer = new StreamWriter("__UnhandledException.txt"))
                {
                    Exception error = e.ExceptionObject as Exception;
                    writer.WriteLine(DateTime.Now);
                    if (error != null)
                    {
                        writer.WriteLine(error.Message);
                        writer.WriteLine(error.StackTrace);
                        if (error.InnerException != null)
                        {
                            writer.WriteLine(error.InnerException.Message);
                            writer.WriteLine(error.InnerException.StackTrace);
                        }
                    }
                    else
                    {
                        writer.WriteLine("Unhandled Exception:" + e.ExceptionObject.ToString());
                    }
                    writer.Flush();
                }
            };
            mServer.Log(LogType.Info, null, $"BeetleX FastHttpApi start@[v:{typeof(HttpApiServer).Assembly.GetName().Version}]");
        }