Пример #1
0
        public bool Connect()
        {
            try
            {
                stateService = new SystemStateService();
                ServiceRegistration.Set <ISystemStateService>(stateService);

                stateService.SwitchSystemState(SystemState.Initializing, false);

                logger.Info("Initialising core services");
                ApplicationCore.RegisterVitalCoreServices(false);
                ApplicationCore.RegisterCoreServices();

                logger.Info("Starting localization");
                ServiceRegistration.Set <ILocalization>(new NoLocalization());

                logger.Info("Initialising system resolver");
                ServiceRegistration.Set <ISystemResolver>(new SystemResolver());

                ServerConnectionReceiver reciever = new ServerConnectionReceiver();

                ServiceRegistration.Get <IMessageBroker>().RegisterMessageReceiver(ServerConnectionMessaging.CHANNEL, reciever);

                logger.Info("Initialising server connection manger");
                connectionManager = new ServerConnectionManager();
                ServiceRegistration.Set <IServerConnectionManager>(connectionManager);

                logger.Info("Starting up server connection manger");
                connectionManager.Startup();

                bool connected = reciever.Connect();

                if (connected)
                {
                    logger.Info("Initialising media item aspect type registration");
                    ServiceRegistration.Set <IMediaItemAspectTypeRegistration>(new MediaItemAspectTypeRegistration());

                    ICollection <Guid> types = GetAllManagedMediaItemAspectTypes();
                    foreach (Guid type in types)
                    {
                        MediaItemAspectMetadata metadata = GetMediaItemAspectMetadata(type);
                        logger.Info("Registering media item {0}...", metadata.Name);
                        ServiceRegistration.Get <IMediaItemAspectTypeRegistration>().RegisterLocallyKnownMediaItemAspectTypeAsync(metadata).Wait();
                    }
                }

                Connected = connected;

                return(connected);
            }
            catch (Exception e)
            {
                logger.Error("Cannot connect", e);
                return(false);
            }
        }
Пример #2
0
        static void Main(params string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "Manager";
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Parse Command Line options
            CommandLineOptions mpArgs = new CommandLineOptions();

            try
            {
                CommandLine.Parse(args, mpArgs);
            }
            catch (ArgumentException)
            {
                mpArgs.DisplayOptions();
                return;
            }

            using (new ServiceScope(true)) //This is the first servicescope
            {
                ApplicationCore.RegisterCoreServices();

                IPathManager pathManager = ServiceScope.Get <IPathManager>();
                // Check if user wants to override the default Application Data location.
                if (mpArgs.IsOption(CommandLineOptions.Option.Data))
                {
                    pathManager.ReplacePath("DATA", (string)mpArgs.GetOption(CommandLineOptions.Option.Data));
                }

                //Check whether the user wants to log method names in the logger
                //This adds an extra 10 to 40 milliseconds to the log call, depending on the length of the stack trace
                bool     logMethods = mpArgs.IsOption(CommandLineOptions.Option.LogMethods);
                LogLevel level      = LogLevel.All;
                if (mpArgs.IsOption(CommandLineOptions.Option.LogLevel))
                {
                    level = (LogLevel)mpArgs.GetOption(CommandLineOptions.Option.LogLevel);
                }
                ILogger logger = ServiceScope.Get <ILogger>();
                logger.Level          = level;
                logger.LogMethodNames = logMethods;

                logger.Debug("Manager: Registering Strings Manager");
                ServiceScope.Add <ILocalisation>(new StringManager());

#if !DEBUG
                // Not in Debug mode (ie Release) then catch all Exceptions
                // In Debug mode these will be left unhandled.
                try
                {
#endif
                // Start the system
                logger.Debug("ApplicationLauncher: Starting MediaPortal manager");

                IPluginManager pluginManager = ServiceScope.Get <IPluginManager>();
                pluginManager.Initialize();
                pluginManager.Startup(true);
                Application.Run(new MainWindow());
                pluginManager.Shutdown();

#if !DEBUG
            }
            catch (Exception ex)
            {
                CrashLogger crash = new CrashLogger(pathManager.GetPath("<LOG>"));
                crash.CreateLog(ex);
                //Form frm =
                //  new YesNoDialogScreen("MediaPortal 2", "Unrecoverable Error",
                //                        "MediaPortal has encountered an unrecoverable error\r\nDetails have been logged\r\n\r\nRestart?",
                //                        BaseScreen.Image.bug);
                //restart = frm.ShowDialog() == DialogResult.Yes;
            }
#endif
            }
        }
Пример #3
0
        public void Start()
        {
            Thread.CurrentThread.Name = "Main";

#if !DEBUG
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-Server\Log");
#endif

            _systemStateService = new SystemStateService();
            ServiceRegistration.Set <ISystemStateService>(_systemStateService);
            _systemStateService.SwitchSystemState(SystemState.Initializing, false);

            try
            {
                ILogger logger = null;
                try
                {
                    // Check if user wants to override the default Application Data location.
                    ApplicationCore.RegisterVitalCoreServices(_dataDirectory);
                    ApplicationCore.RegisterCoreServices();
                    logger = ServiceRegistration.Get <ILogger>();

#if !DEBUG
                    IPathManager pathManager = ServiceRegistration.Get <IPathManager>();
                    logPath = pathManager.GetPath("<LOG>");
#endif

                    BackendExtension.RegisterBackendServices();
                }
                catch (Exception e)
                {
                    if (logger != null)
                    {
                        logger.Critical("Error starting application", e);
                    }
                    _systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;

                    BackendExtension.DisposeBackendServices();
                    ApplicationCore.DisposeCoreServices();

                    throw;
                }

                // Start the core
                logger.Debug("ApplicationLauncher: Starting core");

                try
                {
                    var mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
                    var pluginManager = ServiceRegistration.Get <IPluginManager>();
                    pluginManager.Initialize();
                    pluginManager.Startup(false);
                    ApplicationCore.StartCoreServices();

                    BackendExtension.StartupBackendServices();
                    ApplicationCore.RegisterDefaultMediaItemAspectTypes(); // To be done after backend services are running

                    mediaAccessor.Initialize();

                    _systemStateService.SwitchSystemState(SystemState.Running, true);
                    BackendExtension.ActivateImporterWorker();
                    // To be done after default media item aspect types are present and when the system is running (other plugins might also install media item aspect types)
                }
                catch (Exception e)
                {
                    logger.Critical("Error starting application", e);
                    _systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;
                    BackendExtension.DisposeBackendServices();
                    ApplicationCore.DisposeCoreServices();
                    _systemStateService.SwitchSystemState(SystemState.Ending, false);
                    throw; // needed to cancel OnStart of the Service
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                ConsoleLogger log = new ConsoleLogger(LogLevel.All, false);
                log.Error(ex);
#else
                ServerCrashLogger crash = new ServerCrashLogger(logPath);
                crash.CreateLog(ex);
#endif
                _systemStateService.SwitchSystemState(SystemState.Ending, false);
                throw; // needed to cancel OnStart of the Service
            }
        }
Пример #4
0
        /// <summary>
        /// The main entry point for the MP 2 server application.
        /// </summary>
        private static void Main(params string[] args)
        {
            Thread.CurrentThread.Name = "Main";

            // Parse Command Line options
            CommandLineOptions mpArgs = new CommandLineOptions();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));

            if (!parser.ParseArguments(args, mpArgs, Console.Out))
            {
                Environment.Exit(1);
            }

#if !DEBUG
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-Server\Log");
#endif

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);


            SystemStateService systemStateService = new SystemStateService();
            ServiceRegistration.Set <ISystemStateService>(systemStateService);
            systemStateService.SwitchSystemState(SystemState.Initializing, false);

            try
            {
                ILogger logger = null;
                try
                {
                    // Check if user wants to override the default Application Data location.
                    ApplicationCore.RegisterCoreServices(mpArgs.DataDirectory);
                    logger = ServiceRegistration.Get <ILogger>();

#if !DEBUG
                    IPathManager pathManager = ServiceRegistration.Get <IPathManager>();
                    logPath = pathManager.GetPath("<LOG>");
#endif

                    BackendExtension.RegisterBackendServices();
                }
                catch (Exception e)
                {
                    if (logger != null)
                    {
                        logger.Critical("Error starting application", e);
                    }
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;

                    BackendExtension.DisposeBackendServices();
                    ApplicationCore.DisposeCoreServices();

                    throw;
                }

                // Start the core
                logger.Debug("ApplicationLauncher: Starting core");

                try
                {
                    IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>();
                    IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();
                    pluginManager.Initialize();
                    pluginManager.Startup(false);
                    ApplicationCore.StartCoreServices();

                    BackendExtension.StartupBackendServices();
                    ApplicationCore.RegisterDefaultMediaItemAspectTypes(); // To be done after backend services are running

                    mediaAccessor.Initialize();

                    systemStateService.SwitchSystemState(SystemState.Running, true);
                    BackendExtension.ActivateImporterWorker(); // To be done after default media item aspect types are present and when the system is running (other plugins might also install media item aspect types)

                    Application.Run(new MainForm());

                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true; // Block ServiceRegistration from trying to load new services in shutdown phase

                    mediaAccessor.Shutdown();

                    pluginManager.Shutdown();

                    BackendExtension.ShutdownBackendServices();
                    ApplicationCore.StopCoreServices();
                }
                catch (Exception e)
                {
                    logger.Critical("Error executing application", e);
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;
                }
                finally
                {
                    BackendExtension.DisposeBackendServices();
                    ApplicationCore.DisposeCoreServices();
                    systemStateService.SwitchSystemState(SystemState.Ending, false);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                ConsoleLogger log = new ConsoleLogger(LogLevel.All, false);
                log.Error(ex);
#else
                ServerCrashLogger crash = new ServerCrashLogger(logPath);
                crash.CreateLog(ex);
#endif
                systemStateService.SwitchSystemState(SystemState.Ending, false);
                Application.Exit();
            }
        }
Пример #5
0
        /// <summary>
        /// The main entry point for the MP2 client application.
        /// </summary>
        private static void Main(params string[] args)
        {
            Thread.CurrentThread.Name = "Main";

            // Parse command line options
            var mpOptions = new CommandLineOptions();
            var parser    = new CommandLine.Parser(with => with.HelpWriter = Console.Out);

            parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));

            // Check if another instance is already running
            if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex))
            {
                _mutex = null;
                // Set focus on previously running app
                SingleInstanceHelper.SwitchToCurrentInstance(SingleInstanceHelper.SHOW_MP2_CLIENT_MESSAGE);
                // Stop current instance
                Console.Out.WriteLine("Application already running.");
                Environment.Exit(2);
            }

#if !DEBUG
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-Client\Log");
#endif

            Application.ThreadException += LauncherExceptionHandling.Application_ThreadException;
            AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += LauncherExceptionHandling.TaskScheduler_UnobservedTaskException;

            SystemStateService systemStateService = new SystemStateService();
            ServiceRegistration.Set <ISystemStateService>(systemStateService);
            systemStateService.SwitchSystemState(SystemState.Initializing, false);

            try
            {
#if !DEBUG
                SplashScreen splashScreen = null;
#endif
                ILogger logger = null;
                try
                {
                    // Check if user wants to override the default Application Data location.
                    ApplicationCore.RegisterVitalCoreServices(true, mpOptions.DataDirectory);

#if !DEBUG
                    splashScreen = CreateSplashScreen();
                    splashScreen.ShowSplashScreen();
#endif

                    ApplicationCore.RegisterCoreServices();

                    logger = ServiceRegistration.Get <ILogger>();

#if !DEBUG
                    IPathManager pathManager = ServiceRegistration.Get <IPathManager>();
                    logPath = pathManager.GetPath("<LOG>");
#endif

                    UiExtension.RegisterUiServices();
                }
                catch (Exception e)
                {
                    if (logger != null)
                    {
                        logger.Critical("Error starting application", e);
                    }
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;

                    UiExtension.DisposeUiServices();
                    ApplicationCore.DisposeCoreServices();

                    throw;
                }

                // Start the core
                logger.Debug("ApplicationLauncher: Starting application");

                try
                {
                    IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();
                    pluginManager.Initialize();
                    pluginManager.Startup(false);
                    ApplicationCore.StartCoreServices();

                    ISkinEngine            skinEngine            = ServiceRegistration.Get <ISkinEngine>();
                    IWorkflowManager       workflowManager       = ServiceRegistration.Get <IWorkflowManager>();
                    IMediaAccessor         mediaAccessor         = ServiceRegistration.Get <IMediaAccessor>();
                    ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();

                    // We have to handle some dependencies here in the start order:
                    // 1) After all plugins are loaded, the SkinEngine can initialize (=load all skin resources)
                    // 2) After the skin resources are loaded, the workflow manager can initialize (=load its states and actions)
                    // 3) Before the main window is shown, the splash screen should be hidden
                    // 4) After the workflow states and actions are loaded, the main window can be shown
                    // 5) After the skinengine triggers the first workflow state/startup screen, the default shortcuts can be registered
                    mediaAccessor.Initialize();         // Independent from other services
                    localSharesManagement.Initialize(); // After media accessor was initialized
                    skinEngine.Initialize();            // 1)
                    workflowManager.Initialize();       // 2)

#if !DEBUG
                    splashScreen.CloseSplashScreen(); // 3)
#endif

                    skinEngine.Startup();                                         // 4)
                    UiExtension.Startup();                                        // 5)

                    ApplicationCore.RegisterDefaultMediaItemAspectTypes().Wait(); // To be done after UI services are running

                    _ipcServer = new IpcServer("Client");
                    _ipcServer.CustomShutdownCallback = () =>
                    {
                        ServiceRegistration.Get <IScreenControl>().Shutdown();
                        return(true);
                    };
                    try
                    {
                        _ipcServer.Open();
                    }
                    catch (Exception ipcEx)
                    {
                        logger.Error(ipcEx);
                    }
                    systemStateService.SwitchSystemState(SystemState.Running, true);

                    if (mpOptions.AutoStart)
                    {
                        StartFocusKeeper();
                    }

                    Application.Run();
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true; // Block ServiceRegistration from trying to load new services in shutdown phase

                    // 1) Stop UI extensions (Releases all active players, must be done before shutting down SE)
                    // 2) Shutdown SkinEngine (Closes all screens, uninstalls background manager, stops render thread)
                    // 3) Shutdown WorkflowManager (Disposes all models)
                    // 4) Shutdown ImporterWorker
                    // 5) Shutdown PluginManager (Shuts down all plugins)
                    // 6) Remove all services
                    UiExtension.StopUiServices();
                    skinEngine.Shutdown();
                    workflowManager.Shutdown();
                    ServiceRegistration.Get <IImporterWorker>().Shutdown();
                    pluginManager.Shutdown();
                    mediaAccessor.Shutdown();
                    localSharesManagement.Shutdown();
                    ApplicationCore.StopCoreServices();
                }
                catch (Exception e)
                {
                    logger.Critical("Error executing application", e);
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;
                }
                finally
                {
                    if (_ipcServer != null)
                    {
                        _ipcServer.Close();
                    }
                    UiExtension.DisposeUiServices();
                    ApplicationCore.DisposeCoreServices();

                    systemStateService.SwitchSystemState(SystemState.Ending, false);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                ConsoleLogger log = new ConsoleLogger(LogLevel.All, false);
                log.Error(ex);
#else
                UiCrashLogger crash = new UiCrashLogger(logPath);
                crash.CreateLog(ex);
#endif
                systemStateService.SwitchSystemState(SystemState.Ending, false);

                // Release mutex for single instance
                if (_mutex != null)
                {
                    _mutex.ReleaseMutex();
                }

                Application.Exit();
            }
        }
Пример #6
0
        /// <summary>
        /// Either shows the application's main window or inits the application in the system tray.
        /// </summary>
        private void OnStartup(object sender, StartupEventArgs args)
        {
            Thread.CurrentThread.Name = "Main";
            Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

            // Parse command line options
            var mpOptions = new CommandLineOptions();
            var parser    = new CommandLine.Parser(with => with.HelpWriter = Console.Out);

            parser.ParseArgumentsStrict(args.Args, mpOptions, () => Environment.Exit(1));

            // Check if another instance is already running
            // If new instance was created by UacHelper previous one, assume that previous one is already closed.
            if (SingleInstanceHelper.IsAlreadyRunning(MUTEX_ID, out _mutex))
            {
                _mutex = null;
                // Set focus on previously running app
                SingleInstanceHelper.SwitchToCurrentInstance(SingleInstanceHelper.SHOW_MP2_SERVICEMONITOR_MESSAGE);
                // Stop current instance
                Console.Out.WriteLine("Application already running.");
                Environment.Exit(2);
            }

            // Make sure we're properly handling exceptions
            DispatcherUnhandledException += OnUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += LauncherExceptionHandling.CurrentDomain_UnhandledException;

            var systemStateService = new SystemStateService();

            ServiceRegistration.Set <ISystemStateService>(systemStateService);
            systemStateService.SwitchSystemState(SystemState.Initializing, false);

#if !DEBUG
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-ServiceMonitor\Log");
#endif

            try
            {
                ILogger logger = null;
                try
                {
                    ApplicationCore.RegisterVitalCoreServices(true);
                    ApplicationCore.RegisterCoreServices();
                    logger = ServiceRegistration.Get <ILogger>();

                    logger.Debug("Starting Localization");
                    Localization localization = new Localization();
                    ServiceRegistration.Set <ILocalization>(localization);
                    localization.Startup();

                    //ApplicationCore.StartCoreServices();

                    logger.Debug("UiExtension: Registering ISystemResolver service");
                    ServiceRegistration.Set <ISystemResolver>(new SystemResolver());

                    logger.Debug("UiExtension: Registering IServerConnectionManager service");
                    ServiceRegistration.Set <IServerConnectionManager>(new ServerConnectionManager());

#if !DEBUG
                    logPath = ServiceRegistration.Get <IPathManager>().GetPath("<LOG>");
#endif
                }
                catch (Exception e)
                {
                    if (logger != null)
                    {
                        logger.Critical("Error starting application", e);
                    }

                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;

                    ApplicationCore.DisposeCoreServices();

                    throw;
                }

                InitIpc();

                var appController = new AppController();
                ServiceRegistration.Set <IAppController>(appController);

                // Start the application
                logger.Debug("Starting application");
                try
                {
                    ServiceRegistration.Get <IServerConnectionManager>().Startup();
                    appController.StartUp(mpOptions);
                }
                catch (Exception e)
                {
                    logger.Critical("Error executing application", e);
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                var log = new ConsoleLogger(LogLevel.All, false);
                log.Error(ex);
#else
                ServerCrashLogger crash = new ServerCrashLogger(logPath);
                crash.CreateLog(ex);
#endif
                systemStateService.SwitchSystemState(SystemState.Ending, false);
                Current.Shutdown();
            }
        }
Пример #7
0
        /// <summary>
        /// The main entry point for the MP 2 client application.
        /// </summary>
        private static void Main(params string[] args)
        {
            Thread.CurrentThread.Name = "Main";

#if !DEBUG
            SplashScreen splashScreen = CreateSplashScreen();
            splashScreen.ShowSplashScreen();
#endif

            // Parse Command Line options
            CommandLineOptions mpArgs = new CommandLineOptions();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
            if (!parser.ParseArguments(args, mpArgs, Console.Out))
            {
                Environment.Exit(1);
            }

#if !DEBUG
            string logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MP2-Client\Log");
#endif

            SystemStateService systemStateService = new SystemStateService();
            ServiceRegistration.Set <ISystemStateService>(systemStateService);
            systemStateService.SwitchSystemState(SystemState.Initializing, false);

            try
            {
                ILogger logger = null;
                try
                {
                    // Check if user wants to override the default Application Data location.
                    ApplicationCore.RegisterCoreServices(mpArgs.DataDirectory);

                    logger = ServiceRegistration.Get <ILogger>();

#if !DEBUG
                    IPathManager pathManager = ServiceRegistration.Get <IPathManager>();
                    logPath = pathManager.GetPath("<LOG>");
#endif

                    UiExtension.RegisterUiServices();
                }
                catch (Exception e)
                {
                    if (logger != null)
                    {
                        logger.Critical("Error starting application", e);
                    }
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;

                    UiExtension.DisposeUiServices();
                    ApplicationCore.DisposeCoreServices();

                    throw;
                }

                // Start the core
                logger.Debug("ApplicationLauncher: Starting application");

                try
                {
                    IPluginManager pluginManager = ServiceRegistration.Get <IPluginManager>();
                    pluginManager.Initialize();
                    pluginManager.Startup(false);
                    ApplicationCore.StartCoreServices();

                    ISkinEngine            skinEngine            = ServiceRegistration.Get <ISkinEngine>();
                    IWorkflowManager       workflowManager       = ServiceRegistration.Get <IWorkflowManager>();
                    IMediaAccessor         mediaAccessor         = ServiceRegistration.Get <IMediaAccessor>();
                    ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();

                    // We have to handle some dependencies here in the start order:
                    // 1) After all plugins are loaded, the SkinEngine can initialize (=load all skin resources)
                    // 2) After the skin resources are loaded, the workflow manager can initialize (=load its states and actions)
                    // 3) Before the main window is shown, the splash screen should be hidden
                    // 4) After the workflow states and actions are loaded, the main window can be shown
                    // 5) After the skinengine triggers the first workflow state/startup screen, the default shortcuts can be registered
                    mediaAccessor.Initialize();         // Independent from other services
                    localSharesManagement.Initialize(); // After media accessor was initialized
                    skinEngine.Initialize();            // 1)
                    workflowManager.Initialize();       // 2)

#if !DEBUG
                    splashScreen.CloseSplashScreen(); // 3)
#endif

                    skinEngine.Startup();                                  // 4)
                    UiExtension.Startup();                                 // 5)

                    ApplicationCore.RegisterDefaultMediaItemAspectTypes(); // To be done after UI services are running

                    systemStateService.SwitchSystemState(SystemState.Running, true);

                    Application.Run();

                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true; // Block ServiceRegistration from trying to load new services in shutdown phase

                    // 1) Stop UI extensions (Releases all active players, must be done before shutting down SE)
                    // 2) Shutdown SkinEngine (Closes all screens, uninstalls background manager, stops render thread)
                    // 3) Shutdown WorkflowManager (Disposes all models)
                    // 4) Shutdown PluginManager (Shuts down all plugins)
                    // 5) Remove all services
                    UiExtension.StopUiServices();
                    skinEngine.Shutdown();
                    workflowManager.Shutdown();
                    pluginManager.Shutdown();
                    mediaAccessor.Shutdown();
                    localSharesManagement.Shutdown();
                    ApplicationCore.StopCoreServices();
                }
                catch (Exception e)
                {
                    logger.Critical("Error executing application", e);
                    systemStateService.SwitchSystemState(SystemState.ShuttingDown, true);
                    ServiceRegistration.IsShuttingDown = true;
                }
                finally
                {
                    UiExtension.DisposeUiServices();
                    ApplicationCore.DisposeCoreServices();

                    systemStateService.SwitchSystemState(SystemState.Ending, false);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                ConsoleLogger log = new ConsoleLogger(LogLevel.All, false);
                log.Error(ex);
#else
                UiCrashLogger crash = new UiCrashLogger(logPath);
                crash.CreateLog(ex);
#endif
                systemStateService.SwitchSystemState(SystemState.Ending, false);
                Application.Exit();
            }
        }