Пример #1
0
        private void HandleException(IHttpContext context, Exception ex)
        {
            IResponse response = context.Response;
            IRequest  request  = context.Request;

            if (response.OutputStream != null)
            {
                using (StreamWriter sw = new StreamWriter(response.OutputStream))
                {
                    string description = "({0})"._Format(ex.Message);
                    response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                    response.StatusDescription = description;
                    sw.Write(@"<!DOCTYPE html>
<html>
<body>
<h1>Internal Server Exception</h1>
<p>" + description + "</p></body></html>");
                    sw.Flush();
                }
            }
            MainLogger.AddEntry("An error occurred handling the request: ({0})\r\n*** Request Details {1}***\r\n{2}\r\n\r\n{3}",
                                ex,
                                request.GetClientIp(),
                                ex.Message,
                                request.TryPropertiesToString(),
                                ex.GetMessageAndStackTrace());
        }
Пример #2
0
        private void HandleResponderNotFound(IHttpContext context)
        {
            IResponse response = context.Response;
            IRequest  request  = context.Request;

            string path          = request.Url.ToString();
            string messageFormat = "No responder was found for the path: {0}";
            string description   = "Responder not found";

            using (StreamWriter sw = new StreamWriter(response.OutputStream))
            {
                response.StatusCode        = (int)HttpStatusCode.NotFound;
                response.StatusDescription = description;
                sw.Write(@"<!DOCTYPE html>
<html>
<body>
<h1>" + description + @"</h1>
<p>" + string.Format(messageFormat, path) + @"</p>
</body>
</html>");
                sw.Flush();
                sw.Close();
            }
            string logMessageFormat = "[ClientIp: {0}] No responder found for the path: {1}";

            MainLogger.AddEntry(logMessageFormat, LogEventType.Warning, request.GetClientIp(), path);
        }
Пример #3
0
        public virtual void Initialize()
        {
            if (!this.IsInitialized)
            {
                OnInitializing();
                LoadConf();

                Subscribe(MainLogger);
                SubscribeResponders(MainLogger);

                MainLogger.AddEntry("{0} initializing: \r\n{1}", this.GetType().Name, this.PropertiesToString());

                InitializeCommonSchemas();

                InitializeResponders();

                InitializeUserManagers();

                InitializeApps();

                ConfigureHttpServer();

                RegisterWorkspaceDaos();

                OnInitialized();
            }
            else
            {
                MainLogger.AddEntry("Initialize called but the {0} was already initialized", LogEventType.Warning, this.GetType().Name);
            }
        }
Пример #4
0
        private void HandleException(IHttpContext context, Exception ex)
        {
            IResponse response = context.Response;
            IRequest  request  = context.Request;

            if (response.OutputStream != null)
            {
                using (StreamWriter sw = new StreamWriter(response.OutputStream))
                {
                    string description = "({0})"._Format(ex.Message);
                    response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                    response.StatusDescription = description;
                    sw.WriteLine("<!DOCTYPE html>");
                    Tag html = new Tag("html");
                    html.Child(new Tag("body")
                               .Child(new Tag("h1").Text("Internal Server Exception"))
                               .Child(new Tag("p").Text(description))
                               );
                    sw.WriteLine(html.ToHtmlString());
                    sw.Flush();
                }
            }
            MainLogger.AddEntry("An error occurred handling the request: ({0})\r\n*** Request Details {1}***\r\n{2}\r\n\r\n{3}",
                                ex,
                                request.GetClientIp(),
                                ex.Message,
                                request.TryPropertiesToString(),
                                Args.GetMessageAndStackTrace(ex));
        }
Пример #5
0
        private void HandleResponderNotFound(IHttpContext context)
        {
            IResponse response = context.Response;
            IRequest  request  = context.Request;

            string path          = request.Url.ToString();
            string messageFormat = "No responder was found for the path: {0}";
            string description   = "Responder not found";

            using (StreamWriter sw = new StreamWriter(response.OutputStream))
            {
                response.StatusCode        = (int)HttpStatusCode.NotFound;
                response.StatusDescription = description;
                sw.WriteLine("<!DOCTYPE html>");
                Tag html = new Tag("html");
                html.Child(new Tag("body")
                           .Child(new Tag("h1").Text(description))
                           .Child(new Tag("p").Text(string.Format(messageFormat, path)))
                           );
                sw.WriteLine(html.ToHtmlString());
                sw.Flush();
                sw.Close();
            }
            string logMessageFormat = "[ClientIp: {0}] No responder found for the path: {1}";

            MainLogger.AddEntry(logMessageFormat, LogEventType.Warning, request.GetClientIp(), path);
        }
Пример #6
0
        protected void TryAddAdditionalLoggers(BamConf conf)
        {
            Type[]    loggerTypes;
            ILogger[] loggers = new ILogger[] { };
            try
            {
                loggers = conf.GetAdditionalLoggers(out loggerTypes);
            }
            catch (Exception ex)
            {
                MainLogger.AddEntry("An error occurred getting additional loggers: {0}", ex, ex.Message);
            }

            loggers.Each(logger =>
            {
                try
                {
                    AddLogger(logger);
                }
                catch (Exception ex)
                {
                    MainLogger.AddEntry("An error occurred trying to add a logger: {0}", ex, ex.Message);
                }
            });

            AdditionalLoggers = loggers;
        }
Пример #7
0
 private void EnsureDefaults()
 {
     if (this.MaxThreads <= 0)
     {
         this.MaxThreads = 50;
         MainLogger.AddEntry("Set MaxThreads to default value {0}", this.MaxThreads);
     }
 }
Пример #8
0
 /// <summary>
 /// Initialize server level schemas
 /// </summary>
 protected virtual void InitializeCommonSchemas()
 {
     OnSchemasInitializing();
     SchemaInitializers.Each(schemaInitializer =>
     {
         OnSchemaInitializing(schemaInitializer);
         if (!schemaInitializer.Initialize(MainLogger, out Exception ex))
         {
             MainLogger.AddEntry("An error occurred initializing schema ({0}): {1}", ex, schemaInitializer.SchemaName, ex.Message);
         }
         OnSchemaInitialized(schemaInitializer);
     });
     OnSchemasInitialized();
 }
Пример #9
0
        public ITemplateManager GetAppTemplateRenderer(string appName)
        {
            Dictionary <string, AppContentResponder> container = ContentResponder.AppContentResponders;

            if (container.ContainsKey(appName))
            {
                return(container[appName].AppTemplateManager);
            }
            else
            {
                MainLogger.AddEntry("Unable to retrieve AppDustRenderer for the specified app name: {0}", LogEventType.Warning, appName);
                return(null);
            }
        }
Пример #10
0
 protected virtual void InitializeUserManagers()
 {
     ContentResponder.AppConfigs.Each(appConfig =>
     {
         try
         {
             UserManager mgr             = appConfig.GetUserManager();
             mgr.ApplicationNameProvider = new BamApplicationNameProvider(appConfig);
             AddAppService(appConfig.Name, mgr);
         }
         catch (Exception ex)
         {
             MainLogger.AddEntry("An error occurred initializing user manager for app ({0}): {1}", ex, appConfig.Name, ex.Message);
         }
     });
 }
Пример #11
0
        public void SetConf(BamConf conf)
        {
            OnSettingConf(conf);

            this.MainLogger = Log.Default = conf.GetMainLogger(out Type loggerType);
            this.MainLogger.RestartLoggingThread();
            if (!loggerType.Name.Equals(conf.MainLoggerName))
            {
                MainLogger.AddEntry("Configured MainLogger was ({0}) but the Logger found was ({1})", LogEventType.Warning, conf.MainLoggerName, loggerType.Name);
            }
            this.TryAddAdditionalLoggers(conf);
            conf.Server = this;

            DefaultConfiguration.CopyProperties(conf, this);
            SetWorkspace();

            OnSettedConf(conf);
        }