- remove process and add executable path instead

master
Simon G 5 years ago
parent 419819b9c7
commit d861f30cee
  1. 16
      Lib.Audio/Controllable.cs
  2. 13
      Lib.Audio/ControllableCollector.cs
  3. 5
      Lib.Audio/Factories/IControllableFactory.cs
  4. 4
      Lib.Audio/Interfaces/IControllable.cs
  5. 3
      Lib.Audio/Interfaces/IControllableCollector.cs
  6. 3
      Lib.Audio/MasterControllable.cs

@ -5,7 +5,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.ProcessManaging.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
namespace Lib.Audio namespace Lib.Audio
@ -14,15 +13,24 @@ namespace Lib.Audio
{ {
private readonly List<AudioSessionControl> _audioSessionControls; private readonly List<AudioSessionControl> _audioSessionControls;
public Controllable(List<AudioSessionControl> audioSessionControls, IObservedProcess? process, string name) public Controllable(List<AudioSessionControl> audioSessionControls, string executablePath, string name)
{ {
_audioSessionControls = audioSessionControls; _audioSessionControls = audioSessionControls;
Process = process; ExecutablePath = executablePath;
Name = name; Name = name;
} }
public Controllable(string executablePath)
{
IsValid = false;
ExecutablePath = executablePath;
Name = "";
_audioSessionControls = new List<AudioSessionControl>();
}
public bool IsValid { get; set; } = true; public bool IsValid { get; set; } = true;
public IObservedProcess? Process { get; } public string ExecutablePath { get; }
public string Name { get; } public string Name { get; }
public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath; //FixMe public string? IconPath => _audioSessionControls.FirstOrDefault(c => !string.IsNullOrEmpty(c.IconPath))?.IconPath; //FixMe

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Lib.Audio.Factories; using Lib.Audio.Factories;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.Logging;
using Lib.ProcessManaging.Interfaces; using Lib.ProcessManaging.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
using NAudio.CoreAudioApi.Interfaces; using NAudio.CoreAudioApi.Interfaces;
@ -26,8 +27,8 @@ namespace Lib.Audio
public List<IControllable> Controllables => CreateControllables(); public List<IControllable> Controllables => CreateControllables();
public IControllable? GetControllableForProcess(IObservedProcess process) => public IControllable? GetControllableForExecutable(string executablePath) =>
Controllables.FirstOrDefault(c => c.Process != null && c.Process.IsSameExecutable(process)); Controllables.FirstOrDefault(c => c.ExecutablePath.Equals(executablePath));
private List<IControllable> CreateControllables() private List<IControllable> CreateControllables()
{ {
@ -75,7 +76,13 @@ namespace Lib.Audio
else else
name = id; name = id;
controllables.Add(_controllableFactory.Create(idSessions, process, name)); if (process == null)
{
Log.Write<ControllableCollector>($"Could not find process for session id {id}.");
continue;
}
controllables.Add(_controllableFactory.Create(idSessions, process.FileName, name));
} }
return controllables; return controllables;

@ -4,14 +4,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.ProcessManaging.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
namespace Lib.Audio.Factories namespace Lib.Audio.Factories
{ {
public interface IControllableFactory public interface IControllableFactory
{ {
IControllable Create(List<AudioSessionControl> audioSessionControls, IObservedProcess? process, string name); IControllable Create(List<AudioSessionControl> audioSessionControls, string executablePath, string name);
IControllable Create(string executablePath);
IMasterControllable Create(AudioEndpointVolume audioEndpointVolume, string name); IMasterControllable Create(AudioEndpointVolume audioEndpointVolume, string name);
} }
} }

@ -2,14 +2,12 @@
// Created: 2021-04-07 // Created: 2021-04-07
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.ProcessManaging.Interfaces;
namespace Lib.Audio.Interfaces namespace Lib.Audio.Interfaces
{ {
public interface IControllable public interface IControllable
{ {
bool IsValid { get; set; } bool IsValid { get; set; }
IObservedProcess? Process { get; } string ExecutablePath { get; }
string Name { get; } string Name { get; }
string? IconPath { get; } string? IconPath { get; }

@ -3,7 +3,6 @@
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using System.Collections.Generic; using System.Collections.Generic;
using Lib.ProcessManaging.Interfaces;
namespace Lib.Audio.Interfaces namespace Lib.Audio.Interfaces
{ {
@ -11,6 +10,6 @@ namespace Lib.Audio.Interfaces
{ {
List<IControllable> Controllables { get; } List<IControllable> Controllables { get; }
IControllable? GetControllableForProcess(IObservedProcess process); IControllable? GetControllableForExecutable(string executablePath);
} }
} }

@ -3,7 +3,6 @@
// Copyright(c) 2021 SimonG. All Rights Reserved. // Copyright(c) 2021 SimonG. All Rights Reserved.
using Lib.Audio.Interfaces; using Lib.Audio.Interfaces;
using Lib.ProcessManaging.Interfaces;
using NAudio.CoreAudioApi; using NAudio.CoreAudioApi;
namespace Lib.Audio namespace Lib.Audio
@ -21,7 +20,7 @@ namespace Lib.Audio
} }
public bool IsValid { get; set; } public bool IsValid { get; set; }
public IObservedProcess? Process { get; } public string ExecutablePath { get; } = "";
public string Name { get; } public string Name { get; }
public string? IconPath => null; public string? IconPath => null;

Loading…
Cancel
Save