5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . IO ;
8
+ using System . Text . Json ;
8
9
using System . Threading ;
9
- using Newtonsoft . Json ;
10
10
using NuGetCredentialProvider . Logging ;
11
11
12
12
namespace NuGetCredentialProvider . Util
@@ -27,7 +27,7 @@ public SessionTokenCache(string cacheFilePath, ILogger logger, CancellationToken
27
27
this . mutexName = @"Global\" + cacheFilePath . Replace ( Path . DirectorySeparatorChar , '_' ) ;
28
28
}
29
29
30
- private Dictionary < Uri , string > Cache
30
+ private Dictionary < string , string > Cache
31
31
{
32
32
get
33
33
{
@@ -49,12 +49,12 @@ private Dictionary<Uri, string> Cache
49
49
if ( index == 1 )
50
50
{
51
51
logger . Verbose ( Resources . CancelMessage ) ;
52
- return new Dictionary < Uri , string > ( ) ;
52
+ return new Dictionary < string , string > ( ) ;
53
53
}
54
54
else if ( index == WaitHandle . WaitTimeout )
55
55
{
56
56
logger . Verbose ( Resources . SessionTokenCacheMutexFail ) ;
57
- return new Dictionary < Uri , string > ( ) ;
57
+ return new Dictionary < string , string > ( ) ;
58
58
}
59
59
}
60
60
}
@@ -80,7 +80,7 @@ private Dictionary<Uri, string> Cache
80
80
81
81
public string this [ Uri key ]
82
82
{
83
- get => Cache [ key ] ;
83
+ get => Cache [ key . ToString ( ) ] ;
84
84
set
85
85
{
86
86
bool mutexHeld = false , dummy ;
@@ -116,7 +116,7 @@ public string this[Uri key]
116
116
mutexHeld = true ;
117
117
118
118
var cache = Cache ;
119
- cache [ key ] = value ;
119
+ cache [ key . ToString ( ) ] = value ;
120
120
WriteFileBytes ( Serialize ( cache ) ) ;
121
121
}
122
122
finally
@@ -132,14 +132,14 @@ public string this[Uri key]
132
132
133
133
public bool ContainsKey ( Uri key )
134
134
{
135
- return Cache . ContainsKey ( key ) ;
135
+ return Cache . ContainsKey ( key . ToString ( ) ) ;
136
136
}
137
137
138
138
public bool TryGetValue ( Uri key , out string value )
139
139
{
140
140
try
141
141
{
142
- return Cache . TryGetValue ( key , out value ) ;
142
+ return Cache . TryGetValue ( key . ToString ( ) , out value ) ;
143
143
}
144
144
catch ( Exception e )
145
145
{
@@ -191,7 +191,7 @@ public void Remove(Uri key)
191
191
mutexHeld = true ;
192
192
193
193
var cache = Cache ;
194
- cache . Remove ( key ) ;
194
+ cache . Remove ( key . ToString ( ) ) ;
195
195
WriteFileBytes ( Serialize ( cache ) ) ;
196
196
}
197
197
finally
@@ -204,21 +204,19 @@ public void Remove(Uri key)
204
204
}
205
205
}
206
206
207
- private Dictionary < Uri , string > Deserialize ( byte [ ] data )
207
+ private Dictionary < string , string > Deserialize ( byte [ ] data )
208
208
{
209
209
if ( data == null )
210
210
{
211
- return new Dictionary < Uri , string > ( ) ;
211
+ return new Dictionary < string , string > ( ) ;
212
212
}
213
213
214
- var serialized = System . Text . Encoding . UTF8 . GetString ( data ) ;
215
- return JsonConvert . DeserializeObject < Dictionary < Uri , string > > ( serialized ) ;
214
+ return JsonSerializer . Deserialize < Dictionary < string , string > > ( data ) ;
216
215
}
217
216
218
- private byte [ ] Serialize ( Dictionary < Uri , string > data )
217
+ private byte [ ] Serialize ( Dictionary < string , string > data )
219
218
{
220
- var serialized = JsonConvert . SerializeObject ( data ) ;
221
- return System . Text . Encoding . UTF8 . GetBytes ( serialized ) ;
219
+ return JsonSerializer . SerializeToUtf8Bytes ( data ) ;
222
220
}
223
221
224
222
private byte [ ] ReadFileBytes ( )
0 commit comments