Exemple #1
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();
            ModuleManager.Load();
            ServerController serverStatusController = new ServerController();

            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}]");
            OnOptionLoad(new EventOptionsReloadArgs {
                HttpApiServer = this, HttpOptions = this.Options
            });
            OnStrated(new EventHttpServerStartedArgs {
                HttpApiServer = this
            });
        }
Exemple #2
0
        public void Open()
        {
            var date = GMTDate.Default.DATE;
            var ct   = ContentTypes.TEXT_UTF8;
            var a    = HeaderTypeFactory.Find("Content-Length");

            AppDomain.CurrentDomain.AssemblyResolve += ResolveHandler;
            HttpPacket hp         = new HttpPacket(this, this);
            var        gtmdate    = GMTDate.Default;
            string     serverInfo = $"Server: BeetleX[{typeof(BeetleX.BXException).Assembly.GetName().Version}]/FastHttpApi[{typeof(HttpApiServer).Assembly.GetName().Version}]\r\n";

            HeaderTypeFactory.SERVAR_HEADER_BYTES = Encoding.ASCII.GetBytes(serverInfo);
            mServer = SocketFactory.CreateTcpServer(this, hp)
                      .Setting(o =>
            {
                o.SyncAccept = Options.SyncAccept;
                // o.IOQueues = Options.IOQueues;
                o.DefaultListen.Host = Options.Host;
                // o.IOQueueEnabled = Options.IOQueueEnabled;
                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;
                o.Statistical           = Options.Statistical;
                o.BufferPoolGroups      = Options.BufferPoolGroups;
                o.BufferPoolSize        = Options.BufferPoolSize;
                o.PrivateBufferPool     = Options.PrivateBufferPool;
                o.PrivateBufferPoolSize = Options.MaxBodyLength;
                o.MaxWaitMessages       = Options.MaxWaitQueue;
            });
            if (Options.IOQueueEnabled)
            {
                mRequestIOQueues = new DispatchCenter <IOQueueProcessArgs>(OnIOQueueProcess, Options.IOQueues);
            }
            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();
            ModuleManager.Load();
            if (Options.ManageApiEnabled)
            {
                ServerController serverStatusController = new ServerController();
                mActionFactory.Register(serverStatusController);
            }
            StartTime = DateTime.Now;
            mServer.Open();
            mServerCounter            = new ServerCounter(this);
            mUrlRewrite.UrlIgnoreCase = Options.UrlIgnoreCase;
            mUrlRewrite.Load();
            //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 [IOQueue:{Options.IOQueueEnabled}|Threads:{Options.IOQueues}] [V:{typeof(HttpApiServer).Assembly.GetName().Version}]");
            OnOptionLoad(new EventOptionsReloadArgs {
                HttpApiServer = this, HttpOptions = this.Options
            });
            OnStrated(new EventHttpServerStartedArgs {
                HttpApiServer = this
            });
        }