Example #1
0
        /// <summary>
        /// 核心运行方法
        /// </summary>
        internal void InternalRun()
        {
            this.serviceStatus = new ServiceStatus(this);
            this.bootstrap     = new CustomBootstrapper(
                this,
                this.registedModules,
                this.OnServiceStarting,
                this.OnRequestStart,
                this.EnableCors);

            var urls = new List <Uri>();

            this.RunningUrls.ToList().ForEach((u) =>
            {
                urls.Add(new Uri(u));
            });

            this.serverDisposable = new NancyHost(this.bootstrap, urls.ToArray());
            ((NancyHost)this.serverDisposable).Start();
            serviceRunning = true;

            //输出已注册的模块
            this.OutputRegistedModules();
            this.StartUpdateServiceStatusThread();
            this.WriteToLog($"服务[{serviceName}]已运行,端口 {string.Join(", ", this.RunningUrls)}");
        }
Example #2
0
        /// <summary>
        /// 核心运行方法
        /// </summary>
        internal void InternalRun()
        {
            this.bootstrap = new CustomBootstrapper(
                this,
                this.registedModules,
                this.OnServiceStarting,
                this.OnRequestStart,
                this.EnableCors);

            this.serverDisposable = WebApp.Start(this.StartOptions, (app) =>
            {
                try
                {
                    //使用 Nancy 框架
                    app.UseNancy((options) =>
                    {
                        options.Bootstrapper = bootstrap;
                        options.PassThroughWhenStatusCodesAre(
                            HttpStatusCode.NotFound,
                            HttpStatusCode.InternalServerError
                            );
                    });
                }
                catch (Exception ex)
                {
                    WriteToLog(ex.Message, ex);
                }

                //配置 OWIN,预留作为扩展
                try
                {
                    this.ConfigureOwin(app);
                }
                catch (Exception ex)
                {
                    WriteToLog("ConfigurationOwin(app) 发生异常!", ex);
                }
            });
            serviceRunning = true;

            //输出已注册的模块
            this.OutputRegistedModules();
            this.StartUpdateServiceStatusThread();
            this.WriteToLog($"服务 {serviceName} 已运行,端口 {string.Join(", ", this.RunningUrls)}");
        }