2020-11-26 18:58:08 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-11-26 19:17:05 +01:00
|
|
|
from sh_edraft.configuration.base import ConfigurationBase
|
2020-11-26 17:57:51 +01:00
|
|
|
from sh_edraft.hosting import ApplicationHost
|
2020-11-26 18:58:08 +01:00
|
|
|
from sh_edraft.hosting.base import ApplicationBase
|
2020-11-26 19:17:05 +01:00
|
|
|
from sh_edraft.hosting.model import EnvironmentName
|
|
|
|
from sh_edraft.logging import Logger
|
|
|
|
from sh_edraft.logging.base import LoggerBase
|
|
|
|
from sh_edraft.logging.model import LoggingSettings
|
|
|
|
from sh_edraft.service.base import ServiceProviderBase
|
|
|
|
from sh_edraft.time.model import TimeFormatSettings
|
2020-11-26 17:57:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Program(ApplicationBase):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
ApplicationBase.__init__(self)
|
|
|
|
|
2020-11-26 18:58:08 +01:00
|
|
|
self._app_host: Optional[ApplicationHost] = None
|
|
|
|
|
2020-11-26 19:17:05 +01:00
|
|
|
self._services: Optional[ServiceProviderBase] = None
|
|
|
|
self._configuration: Optional[ConfigurationBase] = None
|
|
|
|
|
2020-11-26 18:58:08 +01:00
|
|
|
def create_application_host(self):
|
2020-11-26 17:57:51 +01:00
|
|
|
self._app_host = ApplicationHost('CPL_DEV_Test')
|
2020-11-26 19:17:05 +01:00
|
|
|
self._services = self._app_host.services
|
|
|
|
self._configuration = self._app_host.configuration
|
|
|
|
|
|
|
|
self._app_host.environment.name = EnvironmentName.development
|
2020-11-26 17:57:51 +01:00
|
|
|
|
|
|
|
def create_configuration(self):
|
2020-11-26 19:17:05 +01:00
|
|
|
self._configuration.create()
|
|
|
|
|
|
|
|
log_settings = LoggingSettings()
|
|
|
|
log_settings.from_dict({
|
|
|
|
"Path": "logs/",
|
|
|
|
"Filename": "log_$start_time.log",
|
|
|
|
"ConsoleLogLevel": "TRACE",
|
|
|
|
"FileLogLevel": "TRACE"
|
|
|
|
})
|
|
|
|
|
|
|
|
time_format_settings = TimeFormatSettings()
|
|
|
|
time_format_settings.from_dict({
|
|
|
|
"DateFormat": "%Y-%m-%d",
|
|
|
|
"TimeFormat": "%H:%M:%S",
|
|
|
|
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
|
|
|
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
|
|
|
})
|
|
|
|
|
|
|
|
self._configuration.add_config_by_type(LoggingSettings, log_settings)
|
|
|
|
self._configuration.add_config_by_type(TimeFormatSettings, time_format_settings)
|
2020-11-26 17:57:51 +01:00
|
|
|
|
|
|
|
def create_services(self):
|
2020-11-26 19:17:05 +01:00
|
|
|
self._services.create()
|
|
|
|
self._services.add_singleton(LoggerBase, Logger)
|
|
|
|
logger: Logger = self._services.get_service(LoggerBase)
|
|
|
|
logger.create()
|
|
|
|
logger.header(self._app_host.name)
|
2020-11-26 17:57:51 +01:00
|
|
|
|
|
|
|
def main(self):
|
|
|
|
print('RUN')
|