1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
3
using System . Runtime . InteropServices ;
4
+ using Serilog ;
5
5
using SoundSwitch . Audio . Manager . Interop . Client . ClientException ;
6
6
using SoundSwitch . Audio . Manager . Interop . Com . Base ;
7
7
using SoundSwitch . Audio . Manager . Interop . Enum ;
@@ -12,11 +12,17 @@ namespace SoundSwitch.Audio.Manager.Interop.Client
12
12
{
13
13
internal class ExtendedPolicyClient
14
14
{
15
- private const string DEVINTERFACE_AUDIO_RENDER = "#{e6327cad-dcec-4949-ae8a-991e976a79d2}" ;
15
+ private const string DEVINTERFACE_AUDIO_RENDER = "#{e6327cad-dcec-4949-ae8a-991e976a79d2}" ;
16
16
private const string DEVINTERFACE_AUDIO_CAPTURE = "#{2eef81be-33fa-4800-9670-1cd474972c3f}" ;
17
- private const string MMDEVAPI_TOKEN = @"\\?\SWD#MMDEVAPI#" ;
17
+ private const string MMDEVAPI_TOKEN = @"\\?\SWD#MMDEVAPI#" ;
18
18
19
19
private IAudioPolicyConfigFactory _sharedPolicyConfig ;
20
+ private readonly ILogger _log ;
21
+
22
+ public ExtendedPolicyClient ( )
23
+ {
24
+ _log = Log . ForContext ( GetType ( ) ) ;
25
+ }
20
26
21
27
private IAudioPolicyConfigFactory PolicyConfig
22
28
{
@@ -38,18 +44,17 @@ private static string GenerateDeviceId(string deviceId, EDataFlow flow)
38
44
39
45
private static string UnpackDeviceId ( string deviceId )
40
46
{
41
- if ( deviceId . StartsWith ( MMDEVAPI_TOKEN ) ) deviceId = deviceId . Remove ( 0 , MMDEVAPI_TOKEN . Length ) ;
42
- if ( deviceId . EndsWith ( DEVINTERFACE_AUDIO_RENDER ) ) deviceId = deviceId . Remove ( deviceId . Length - DEVINTERFACE_AUDIO_RENDER . Length ) ;
47
+ if ( deviceId . StartsWith ( MMDEVAPI_TOKEN ) ) deviceId = deviceId . Remove ( 0 , MMDEVAPI_TOKEN . Length ) ;
48
+ if ( deviceId . EndsWith ( DEVINTERFACE_AUDIO_RENDER ) ) deviceId = deviceId . Remove ( deviceId . Length - DEVINTERFACE_AUDIO_RENDER . Length ) ;
43
49
if ( deviceId . EndsWith ( DEVINTERFACE_AUDIO_CAPTURE ) ) deviceId = deviceId . Remove ( deviceId . Length - DEVINTERFACE_AUDIO_CAPTURE . Length ) ;
44
50
return deviceId ;
45
51
}
46
52
47
53
public void SetDefaultEndPoint ( string deviceId , EDataFlow flow , IEnumerable < ERole > roles , uint processId )
48
54
{
49
- Trace . WriteLine ( $ "ExtendedPolicyClient SetDefaultEndPoint { deviceId } [{ flow } ] { processId } " ) ;
55
+ _log . Information ( "ExtendedPolicyClient SetDefaultEndPoint {DeviceId } [{Flow }] {ProcessId}" , deviceId , flow , processId ) ;
50
56
try
51
57
{
52
-
53
58
if ( string . IsNullOrEmpty ( deviceId ) )
54
59
{
55
60
return ;
@@ -67,7 +72,7 @@ public void SetDefaultEndPoint(string deviceId, EDataFlow flow, IEnumerable<ERol
67
72
}
68
73
catch ( Exception ex )
69
74
{
70
- Trace . WriteLine ( $ " { ex } ") ;
75
+ _log . Error ( ex , "Can't set the default endpoint ") ;
71
76
}
72
77
}
73
78
@@ -85,7 +90,7 @@ public string GetDefaultEndPoint(EDataFlow flow, ERole role, uint processId)
85
90
}
86
91
catch ( Exception ex )
87
92
{
88
- Trace . WriteLine ( $ " { ex } ") ;
93
+ _log . Error ( ex , "Can't get the default enpoint ") ;
89
94
}
90
95
91
96
return null ;
@@ -99,7 +104,7 @@ public void ResetAllSetEndpoint()
99
104
}
100
105
catch ( Exception ex )
101
106
{
102
- Trace . WriteLine ( $ " { ex } ") ;
107
+ _log . Error ( ex , "Can't reset all endpoints ") ;
103
108
}
104
109
}
105
110
}
0 commit comments