示例#1
0
        protected static HomeServerData GetHomeServerData(string serverApplicationPath)
        {
            PathManager pathManager = new PathManager(); // Fake path manager to inject the settings path to SettingsManager and StringManager

            pathManager.InitializeDefaults(serverApplicationPath);
            ServiceRegistration.Set <IPathManager>(pathManager);
            ISettingsManager settingsManager = new SettingsManager();

            ServiceRegistration.Set <ISettingsManager>(settingsManager);
            ServiceRegistration.Set <IRegistry>(new MediaPortal.Common.Services.Registry.Registry());
            ServiceRegistration.Set <IPluginManager>(new PluginManager());

            StringManager stringManager = new StringManager();

            stringManager.Startup();
            ServiceRegistration.Set <ILocalization>(stringManager);

            ISystemResolver backendSystemResolver = new SystemResolver();

            HomeServerData result = new HomeServerData
            {
                HomeServerName     = new LocalizedUPnPDeviceInformation().GetFriendlyName(CultureInfo.InvariantCulture),
                HomeServerSystemId = backendSystemResolver.LocalSystemId
            };

            ServiceRegistration.RemoveAndDispose <ILocalization>();
            ServiceRegistration.RemoveAndDispose <IPluginManager>();
            ServiceRegistration.RemoveAndDispose <IRegistry>();
            ServiceRegistration.RemoveAndDispose <ISettingsManager>();
            ServiceRegistration.RemoveAndDispose <IPathManager>();

            return(result);
        }
示例#2
0
        protected static void AttachClientToServer(string clientApplicationPath, HomeServerData homeServerData)
        {
            PathManager pathManager = new PathManager(); // Fake path manager to inject the settings path to SettingsManager and StringManager

            pathManager.InitializeDefaults(clientApplicationPath);
            ServiceRegistration.Set <IPathManager>(pathManager);
            ISettingsManager settingsManager = new SettingsManager();

            ServiceRegistration.Set <ISettingsManager>(settingsManager);
            ServiceRegistration.Set <IRegistry>(new MediaPortal.Common.Services.Registry.Registry());
            ServiceRegistration.Set <IPluginManager>(new PluginManager());

            StringManager stringManager = new StringManager();

            stringManager.Startup();
            ServiceRegistration.Set <ILocalization>(stringManager);

            ServerConnectionSettings serverConnectionSettings = settingsManager.Load <ServerConnectionSettings>();

            if (serverConnectionSettings.HomeServerSystemId == null)
            {
                ServiceRegistration.Get <ILogger>().Info("Client is not attached, auto-attaching to local server '{0}', system id '{1}'", homeServerData.HomeServerName, homeServerData.HomeServerSystemId);

                serverConnectionSettings.HomeServerSystemId   = homeServerData.HomeServerSystemId;
                serverConnectionSettings.LastHomeServerSystem = SystemName.Loopback();
                serverConnectionSettings.LastHomeServerName   = homeServerData.HomeServerName;
                settingsManager.Save(serverConnectionSettings);
            }
            else
            {
                ServiceRegistration.Get <ILogger>().Info("Client is already attached to server with system ID '{0}'", serverConnectionSettings.HomeServerSystemId);
            }

            ServiceRegistration.RemoveAndDispose <ILocalization>();
            ServiceRegistration.RemoveAndDispose <IPluginManager>();
            ServiceRegistration.RemoveAndDispose <IRegistry>();
            ServiceRegistration.RemoveAndDispose <ISettingsManager>();
            ServiceRegistration.RemoveAndDispose <IPathManager>();
        }
示例#3
0
        protected static HomeServerData GetHomeServerData(string serverApplicationPath)
        {
            PathManager pathManager = new PathManager(); // Fake path manager to inject the settings path to SettingsManager and StringManager

            pathManager.InitializeDefaults(serverApplicationPath);
            ServiceRegistration.Set <IPathManager>(pathManager);
            ISettingsManager settingsManager = new SettingsManager();

            ServiceRegistration.Set <ISettingsManager>(settingsManager);
            ServiceRegistration.Set <IRegistry>(new MediaPortal.Common.Services.Registry.Registry());
            ServiceRegistration.Set <IMessageBroker>(new MessageBroker());
            PluginManager pluginManager = new PluginManager();

            ServiceRegistration.Set <IPluginManager>(pluginManager);
            // Required to load language resource registration from plugins, so ILocalization is able to use them.
            pluginManager.Initialize();
            pluginManager.Startup(true); // Use "maintenance" mode here, this won't activate plugins as they are not needed here.

            StringManager stringManager = new StringManager();

            stringManager.Startup();
            ServiceRegistration.Set <ILocalization>(stringManager);

            ISystemResolver backendSystemResolver = new SystemResolver();

            HomeServerData result = new HomeServerData
            {
                HomeServerName     = new LocalizedUPnPDeviceInformation().GetFriendlyName(CultureInfo.InvariantCulture),
                HomeServerSystemId = backendSystemResolver.LocalSystemId
            };

            pluginManager.Shutdown();
            ServiceRegistration.RemoveAndDispose <ILocalization>();
            ServiceRegistration.RemoveAndDispose <IPluginManager>();
            ServiceRegistration.RemoveAndDispose <IRegistry>();
            ServiceRegistration.RemoveAndDispose <ISettingsManager>();
            ServiceRegistration.RemoveAndDispose <IPathManager>();
            return(result);
        }
示例#4
0
        public static ActionResult AttachClientToServer(Session session)
        {
            session.Log("ClientRequestState : {0}", session.Features["Client"].RequestState);
            session.Log("ServerRequestState : {0}", session.Features["Server"].RequestState);

            if (session.Features["Client"].RequestState == InstallState.Local &&
                session.Features["Server"].RequestState == InstallState.Local)
            {
                string clientApplicationPath = Path.Combine(session["INSTALLDIR_CLIENT"], "MP2-Client.exe");
                string serverApplicationPath = Path.Combine(session["INSTALLDIR_SERVER"], "MP2-Server.exe");

                ServiceRegistration.Set <ILogger>(new DefaultLogger(new SessionLogWriter(session), LogLevel.All, false, false)); // Logger for called services

                HomeServerData homeServerData = GetHomeServerData(serverApplicationPath);
                AttachClientToServer(clientApplicationPath, homeServerData);
                ServiceRegistration.RemoveAndDispose <ILogger>();
            }
            else
            {
                session.Log("Installation mode is not SingleSeat. Skipping auto-attach step.");
            }

            return(ActionResult.Success);
        }