Ejemplo n.º 1
0
 protected void UpdateClientsList()
 {
     lvClients.BeginUpdate();
     try
     {
         lvClients.Items.Clear();
         IClientManager clientManager           = ServiceRegistration.Get <IClientManager>();
         ICollection <ClientConnection> clients = clientManager.ConnectedClients;
         ICollection <string>           connectedClientSystemIDs = new List <string>(clients.Count);
         int countRemoteSystems = 0;
         foreach (ClientConnection clientConnection in clients)
         {
             string mpFrontendServerUUID = clientConnection.Descriptor.MPFrontendServerUUID;
             connectedClientSystemIDs.Add(mpFrontendServerUUID);
             if (!ServiceRegistration.Get <ISystemResolver>().GetSystemNameForSystemId(mpFrontendServerUUID).IsLocalSystem())
             {
                 countRemoteSystems++;
             }
         }
         foreach (MPClientMetadata attachedClientData in clientManager.AttachedClients.Values)
         {
             ListViewItem lvi = CreateClientItem(attachedClientData.LastClientName,
                                                 attachedClientData.LastSystem == null ? null : attachedClientData.LastSystem.HostName,
                                                 connectedClientSystemIDs.Contains(attachedClientData.SystemId));
             lvClients.Items.Add(lvi);
         }
         // Avoid suspend as long as remote clients are connected. A local client prevents suspend using its own logic.
         ApplicationSuspendLevel = countRemoteSystems > 0 ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
     }
     finally
     {
         lvClients.EndUpdate();
     }
 }
Ejemplo n.º 2
0
 public MainForm()
 {
   InitializeComponent();
   UpdateClientsList();
   ISettingsManager settingsManager = ServiceRegistration.Get<ISettingsManager>();
   AppSettings settings = settingsManager.Load<AppSettings>();
   _applicationSuspendLevel = settings.SuspendLevel;
   UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet
   cbAvoidShutdown.Checked = ApplicationSuspendLevel > SuspendLevel.None;
 }
        public override void Load()
        {
            _suspendLevels = Enum.GetValues(typeof(SuspendLevel)).Cast <SuspendLevel>().ToList();
            SuspendLevel selectedSuspendLevel = SettingsManager.Load <AppSettings>().SuspendLevel;

            Selected = _suspendLevels.IndexOf(selectedSuspendLevel);

            // Fill items
            _items = _suspendLevels.Select(level => LocalizationHelper.CreateResourceString(
                                               '[' + RES_SUSPEND_LEVEL_PREFIX + '.' + level.ToString() + ']')).ToList();
        }
Ejemplo n.º 4
0
        public MainForm()
        {
            InitializeComponent();
            UpdateClientsList();
            ISettingsManager settingsManager = ServiceRegistration.Get <ISettingsManager>();
            AppSettings      settings        = settingsManager.Load <AppSettings>();

            _applicationSuspendLevel = settings.SuspendLevel;
            UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet
            cbAvoidShutdown.Checked = ApplicationSuspendLevel > SuspendLevel.None;
        }
Ejemplo n.º 5
0
        public MainForm(ScreenManager screenManager)
        {
            _adaptToSizeEnabled = false;
            _screenManager      = screenManager;

            ServiceRegistration.Get <ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
            ServiceRegistration.Set <IScreenControl>(this);

            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;

            AppSettings settings = ServiceRegistration.Get <ISettingsManager>().Load <AppSettings>();

            _previousMousePosition = new Point(-1, -1);

            Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

            _previousWindowLocation   = Location;
            _previousWindowClientSize = desiredWindowedSize;
            _previousWindowState      = FormWindowState.Normal;

            if (settings.FullScreen)
            {
                SwitchToFullscreen(settings.FSScreenNum);
            }
            else
            {
                SwitchToWindowedSize(Location, desiredWindowedSize, false);
            }

            SkinContext.WindowSize = ClientSize;

            // GraphicsDevice has to be initialized after the form was sized correctly
            ServiceRegistration.Get <ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
            GraphicsDevice.Initialize_MainThread(this);

            // Read and apply ScreenSaver settings
            _screenSaverTimeOut   = TimeSpan.FromMinutes(settings.ScreenSaverTimeoutMin);
            _isScreenSaverEnabled = settings.ScreenSaverEnabled;

            _applicationSuspendLevel = settings.SuspendLevel;
            UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

            Application.Idle   += OnApplicationIdle;
            _adaptToSizeEnabled = true;

            _messageQueue = new AsynchronousMessageQueue(this, new string[]
            {
                PlayerManagerMessaging.CHANNEL,
            });
            _messageQueue.MessageReceived += OnMessageReceived;
            _messageQueue.Start();
        }
Ejemplo n.º 6
0
        protected void UpdateSystemSuspendLevel_MainThread()
        {
            // We'll use the maximum suspend level from main suspend level and player suspend level
            SuspendLevel value = _applicationSuspendLevel;

            _applicationSuspendLevel = value;
            if (_playerSuspendLevel > value)
            {
                value = _playerSuspendLevel;
            }
            ServiceRegistration.Get <ISystemStateService>().SetCurrentSuspendLevel(value, true);
        }
Ejemplo n.º 7
0
        protected void UpdateSystemSuspendLevel_MainThread()
        {
            // We'll use the maximum suspend level from main suspend level and player suspend level
            SuspendLevel value = _applicationSuspendLevel;

            _applicationSuspendLevel = value;
            if (_playerSuspendLevel > value)
            {
                value = _playerSuspendLevel;
            }
            EnergySavingConfig.SetCurrentSuspendLevel(value);
        }
Ejemplo n.º 8
0
 public static void SetCurrentSuspendLevel(SuspendLevel level)
 {
   WindowsAPI.EXECUTION_STATE requestedState = 0;
   switch (level)
   {
     case SuspendLevel.AvoidSuspend:
       requestedState = WindowsAPI.EXECUTION_STATE.ES_SYSTEM_REQUIRED;
       break;
     case SuspendLevel.DisplayRequired:
       requestedState = WindowsAPI.EXECUTION_STATE.ES_DISPLAY_REQUIRED;
       break;
   }
   WindowsAPI.SetThreadExecutionState(WindowsAPI.EXECUTION_STATE.ES_CONTINUOUS | requestedState);
 }
Ejemplo n.º 9
0
        public static void SetCurrentSuspendLevel(SuspendLevel level)
        {
            WindowsAPI.EXECUTION_STATE requestedState = 0;
            switch (level)
            {
            case SuspendLevel.AvoidSuspend:
                requestedState = WindowsAPI.EXECUTION_STATE.ES_SYSTEM_REQUIRED;
                break;

            case SuspendLevel.DisplayRequired:
                requestedState = WindowsAPI.EXECUTION_STATE.ES_DISPLAY_REQUIRED;
                break;
            }
            WindowsAPI.SetThreadExecutionState(WindowsAPI.EXECUTION_STATE.ES_CONTINUOUS | requestedState);
        }
Ejemplo n.º 10
0
        protected void UpdatePowerState()
        {
            IClientManager clientManager = ServiceRegistration.Get <IClientManager>(false);

            if (clientManager == null)
            {
                return;
            }

            int countRemoteSystems = clientManager.ConnectedClients.
                                     Select(clientConnection => clientConnection.Descriptor.MPFrontendServerUUID).
                                     Count(mpFrontendServerUUID => !ServiceRegistration.Get <ISystemResolver>().GetSystemNameForSystemId(mpFrontendServerUUID).IsLocalSystem());

            // Avoid suspend as long as remote clients are connected. A local client prevents suspend using its own logic.
            // Set a continous state for current thread (which is the AMQ thread, not the "MainThread").
            _suspendLevel = countRemoteSystems > 0 ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
            ServiceRegistration.Get <ILogger>().Debug("UpdatePowerState: Setting continuous suspend level to {0}", _suspendLevel);
            ServiceRegistration.Get <ISystemStateService>().SetCurrentSuspendLevel(_suspendLevel, true);
        }
        public void SetCurrentSuspendLevel(SuspendLevel level, bool continuous = false)
        {
            WindowsAPI.EXECUTION_STATE requestedState = 0;
            switch (level)
            {
            case SuspendLevel.AvoidSuspend:
                requestedState = WindowsAPI.EXECUTION_STATE.ES_SYSTEM_REQUIRED;
                break;

            case SuspendLevel.DisplayRequired:
                requestedState = WindowsAPI.EXECUTION_STATE.ES_DISPLAY_REQUIRED;
                break;
            }

            if (continuous)
            {
                _lastContinuousSuspendLevel = level; // Remember the value to handle OnQuerySuspend properly
                requestedState |= WindowsAPI.EXECUTION_STATE.ES_CONTINUOUS;
            }

            WindowsAPI.SetThreadExecutionState(requestedState);
        }
Ejemplo n.º 12
0
        public MainForm(ScreenManager screenManager)
        {
            _adaptToSizeEnabled = false;
            _screenManager      = screenManager;

            ServiceRegistration.Get <ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
            ServiceRegistration.Set <IScreenControl>(this);

            InitializeComponent();

            // Use the native method because the Icon.ExtractAssociatedIcon throws an exception when running from UNC paths
            ushort uicon;
            IntPtr handle = NativeMethods.ExtractAssociatedIcon(Handle, ServiceRegistration.Get <IPathManager>().GetPath("<APPLICATION_PATH>"), out uicon);

            Icon = Icon.FromHandle(handle);

            CheckForIllegalCrossThreadCalls = false;

            StartupSettings startupSettings = ServiceRegistration.Get <ISettingsManager>().Load <StartupSettings>();
            AppSettings     appSettings     = ServiceRegistration.Get <ISettingsManager>().Load <AppSettings>();

            _previousMousePosition = new Point(-1, -1);

            // Default screen for splashscreen is the one from where MP2 was started.
            System.Windows.Forms.Screen preferredScreen = System.Windows.Forms.Screen.FromControl(this);
            int numberOfScreens = System.Windows.Forms.Screen.AllScreens.Length;
            int validScreenNum  = GetScreenNum();

            // Force the splashscreen to be displayed on a specific screen.
            if (startupSettings.StartupScreenNum >= 0 && startupSettings.StartupScreenNum < numberOfScreens)
            {
                validScreenNum  = startupSettings.StartupScreenNum;
                preferredScreen = System.Windows.Forms.Screen.AllScreens[validScreenNum];
                StartPosition   = FormStartPosition.Manual;
            }

            // Store original desktop size
            _screenSize = preferredScreen.Bounds.Size;
            _screenBpp  = preferredScreen.BitsPerPixel;

            Size desiredWindowedSize;

            if (appSettings.WindowPosition.HasValue && appSettings.WindowSize.HasValue)
            {
                desiredWindowedSize = appSettings.WindowSize.Value;
                Location            = ValidatePosition(appSettings.WindowPosition.Value, preferredScreen.WorkingArea.Size, ref desiredWindowedSize);
            }
            else
            {
                Location            = new Point(preferredScreen.WorkingArea.X, preferredScreen.WorkingArea.Y);
                desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);
            }

            _previousWindowLocation   = Location;
            _previousWindowClientSize = desiredWindowedSize;
            _previousWindowState      = FormWindowState.Normal;
            _previousMode             = ScreenMode.NormalWindowed;

            if (appSettings.ScreenMode == ScreenMode.FullScreen)
            {
                SwitchToFullscreen(validScreenNum);
            }
            else
            {
                SwitchToWindowedSize(appSettings.ScreenMode, Location, desiredWindowedSize, false);
            }

            SkinContext.WindowSize = ClientSize;

            // GraphicsDevice has to be initialized after the form was sized correctly
            ServiceRegistration.Get <ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
            GraphicsDevice.Initialize_MainThread(this);

            // Read and apply ScreenSaver settings
            _screenSaverTimeOut   = TimeSpan.FromMinutes(appSettings.ScreenSaverTimeoutMin);
            _isScreenSaverEnabled = appSettings.ScreenSaverEnabled;

            _applicationSuspendLevel = appSettings.SuspendLevel;
            UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

            Application.Idle   += OnApplicationIdle;
            _adaptToSizeEnabled = true;

            VideoPlayerSynchronizationStrategy = new SynchronizeToPrimaryPlayer();

            // Register touch events
            TouchDown += MainForm_OnTouchDown;
            TouchMove += MainForm_OnTouchMove;
            TouchUp   += MainForm_OnTouchUp;
        }
Ejemplo n.º 13
0
    protected void UpdatePowerState()
    {
      IClientManager clientManager = ServiceRegistration.Get<IClientManager>(false);
      if (clientManager == null)
        return;

      int countRemoteSystems = clientManager.ConnectedClients.
        Select(clientConnection => clientConnection.Descriptor.MPFrontendServerUUID).
        Count(mpFrontendServerUUID => !ServiceRegistration.Get<ISystemResolver>().GetSystemNameForSystemId(mpFrontendServerUUID).IsLocalSystem());

      // Avoid suspend as long as remote clients are connected. A local client prevents suspend using its own logic.
      // Set a continous state for current thread (which is the AMQ thread, not the "MainThread").
      _suspendLevel = countRemoteSystems > 0 ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
      ServiceRegistration.Get<ILogger>().Debug("UpdatePowerState: Setting continuous suspend level to {0}", _suspendLevel);
      ServiceRegistration.Get<ISystemStateService>().SetCurrentSuspendLevel(_suspendLevel, true);
    }
Ejemplo n.º 14
0
    public MainForm(ScreenManager screenManager)
    {
      _adaptToSizeEnabled = false;
      _screenManager = screenManager;

      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
      ServiceRegistration.Set<IScreenControl>(this);

      InitializeComponent();
      CheckForIllegalCrossThreadCalls = false;

      AppSettings settings = ServiceRegistration.Get<ISettingsManager>().Load<AppSettings>();

      _previousMousePosition = new Point(-1, -1);

      Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

      _previousWindowLocation = Location;
      _previousWindowClientSize = desiredWindowedSize;
      _previousWindowState = FormWindowState.Normal;

      if (settings.FullScreen)
        SwitchToFullscreen(settings.FSScreenNum);
      else
        SwitchToWindowedSize(Location, desiredWindowedSize, false);

      SkinContext.WindowSize = ClientSize;

      // GraphicsDevice has to be initialized after the form was sized correctly
      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
      GraphicsDevice.Initialize_MainThread(this);

      // Read and apply ScreenSaver settings
      _screenSaverTimeOut = TimeSpan.FromMinutes(settings.ScreenSaverTimeoutMin);
      _isScreenSaverEnabled = settings.ScreenSaverEnabled;

      _applicationSuspendLevel = settings.SuspendLevel;
      UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

      Application.Idle += OnApplicationIdle;
      _adaptToSizeEnabled = true;

      _messageQueue = new AsynchronousMessageQueue(this, new string[]
        {
            PlayerManagerMessaging.CHANNEL,
        });
      _messageQueue.MessageReceived += OnMessageReceived;
      _messageQueue.Start();
    }
Ejemplo n.º 15
0
 protected void UpdateSystemSuspendLevel_MainThread()
 {
   // We'll use the maximum suspend level from main suspend level and player suspend level
   SuspendLevel value = _applicationSuspendLevel;
   _applicationSuspendLevel = value;
   if (_playerSuspendLevel > value)
     value = _playerSuspendLevel;
   EnergySavingConfig.SetCurrentSuspendLevel(value);
 }
Ejemplo n.º 16
0
 private void OnAvoidShutdownCheckedChanged(object sender, System.EventArgs e)
 {
     ApplicationSuspendLevel = cbAvoidShutdown.Checked ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
 }
Ejemplo n.º 17
0
 protected void UpdateSystemSuspendLevel_MainThread()
 {
   // We'll use the maximum suspend level from main suspend level and player suspend level
   SuspendLevel value = _applicationSuspendLevel;
   _applicationSuspendLevel = value;
   if (_playerSuspendLevel > value)
     value = _playerSuspendLevel;
   ServiceRegistration.Get<ISystemStateService>().SetCurrentSuspendLevel(value, true);
 }
Ejemplo n.º 18
0
 protected void UpdateClientsList()
 {
   lvClients.BeginUpdate();
   try
   {
     lvClients.Items.Clear();
     IClientManager clientManager = ServiceRegistration.Get<IClientManager>();
     ICollection<ClientConnection> clients = clientManager.ConnectedClients;
     ICollection<string> connectedClientSystemIDs = new List<string>(clients.Count);
     int countRemoteSystems = 0;
     foreach (ClientConnection clientConnection in clients)
     {
       string mpFrontendServerUUID = clientConnection.Descriptor.MPFrontendServerUUID;
       connectedClientSystemIDs.Add(mpFrontendServerUUID);
       if (!ServiceRegistration.Get<ISystemResolver>().GetSystemNameForSystemId(mpFrontendServerUUID).IsLocalSystem())
         countRemoteSystems++;
     }
     foreach (MPClientMetadata attachedClientData in clientManager.AttachedClients.Values)
     {
       ListViewItem lvi = CreateClientItem(attachedClientData.LastClientName,
           attachedClientData.LastSystem == null ? null : attachedClientData.LastSystem.HostName,
           connectedClientSystemIDs.Contains(attachedClientData.SystemId));
       lvClients.Items.Add(lvi);
     }
     // Avoid suspend as long as remote clients are connected. A local client prevents suspend using its own logic.
     ApplicationSuspendLevel = countRemoteSystems > 0 ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
   }
   finally
   {
     lvClients.EndUpdate();
   }
 }
Ejemplo n.º 19
0
    public void SetCurrentSuspendLevel(SuspendLevel level, bool continuous = false)
    {
      WindowsAPI.EXECUTION_STATE requestedState = 0;
      switch (level)
      {
        case SuspendLevel.AvoidSuspend:
          requestedState = WindowsAPI.EXECUTION_STATE.ES_SYSTEM_REQUIRED;
          break;
        case SuspendLevel.DisplayRequired:
          requestedState = WindowsAPI.EXECUTION_STATE.ES_DISPLAY_REQUIRED;
          break;
      }

      if (continuous)
      {
        _lastContinuousSuspendLevel = level; // Remember the value to handle OnQuerySuspend properly
        requestedState |= WindowsAPI.EXECUTION_STATE.ES_CONTINUOUS;
      }

      WindowsAPI.SetThreadExecutionState(requestedState);
    }
Ejemplo n.º 20
0
    public MainForm(ScreenManager screenManager)
    {
      _adaptToSizeEnabled = false;
      _screenManager = screenManager;

      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Registering DirectX MainForm as IScreenControl service");
      ServiceRegistration.Set<IScreenControl>(this);

      InitializeComponent();

      // Use the native method because the Icon.ExtractAssociatedIcon throws an exception when running from UNC paths
      ushort uicon;
      IntPtr handle = NativeMethods.ExtractAssociatedIcon(Handle, ServiceRegistration.Get<IPathManager>().GetPath("<APPLICATION_PATH>"), out uicon);
      Icon = Icon.FromHandle(handle);

      CheckForIllegalCrossThreadCalls = false;

      StartupSettings startupSettings = ServiceRegistration.Get<ISettingsManager>().Load<StartupSettings>();
      AppSettings appSettings = ServiceRegistration.Get<ISettingsManager>().Load<AppSettings>();

      _previousMousePosition = new Point(-1, -1);

      Size desiredWindowedSize = new Size(SkinContext.SkinResources.SkinWidth, SkinContext.SkinResources.SkinHeight);

      // Default screen for splashscreen is the one from where MP2 was started.
      System.Windows.Forms.Screen preferredScreen = System.Windows.Forms.Screen.FromControl(this);
      int numberOfScreens = System.Windows.Forms.Screen.AllScreens.Length;
      int validScreenNum = GetScreenNum();

      // Force the splashscreen to be displayed on a specific screen.
      if (startupSettings.StartupScreenNum >= 0 && startupSettings.StartupScreenNum < numberOfScreens)
      {
        validScreenNum = startupSettings.StartupScreenNum;
        preferredScreen = System.Windows.Forms.Screen.AllScreens[validScreenNum];
        StartPosition = FormStartPosition.Manual;
      }

      Location = new Point(preferredScreen.WorkingArea.X, preferredScreen.WorkingArea.Y);

      _previousWindowLocation = Location;
      _previousWindowClientSize = desiredWindowedSize;
      _previousWindowState = FormWindowState.Normal;

      if (appSettings.FullScreen)
        SwitchToFullscreen(validScreenNum);
      else
        SwitchToWindowedSize(Location, desiredWindowedSize, false);

      SkinContext.WindowSize = ClientSize;

      // GraphicsDevice has to be initialized after the form was sized correctly
      ServiceRegistration.Get<ILogger>().Debug("SkinEngine MainForm: Initialize DirectX");
      GraphicsDevice.Initialize_MainThread(this);

      // Read and apply ScreenSaver settings
      _screenSaverTimeOut = TimeSpan.FromMinutes(appSettings.ScreenSaverTimeoutMin);
      _isScreenSaverEnabled = appSettings.ScreenSaverEnabled;

      _applicationSuspendLevel = appSettings.SuspendLevel;
      UpdateSystemSuspendLevel_MainThread(); // Don't use UpdateSystemSuspendLevel() here because the window handle was not created yet

      Application.Idle += OnApplicationIdle;
      _adaptToSizeEnabled = true;

      VideoPlayerSynchronizationStrategy = new SynchronizeToPrimaryPlayer();

      // Register touch events
      TouchDown += MainForm_OnTouchDown;
      TouchMove += MainForm_OnTouchMove;
      TouchUp += MainForm_OnTouchUp;
    }
Ejemplo n.º 21
0
 private void OnAvoidShutdownCheckedChanged(object sender, System.EventArgs e)
 {
   ApplicationSuspendLevel = cbAvoidShutdown.Checked ? SuspendLevel.AvoidSuspend : SuspendLevel.None;
 }