Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 2673f06

Browse files
Rodrigo Moyarodrmoya
authored andcommitted
[AspNetCore] Some launchSettings implementation code improvements
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/965797
1 parent 7965de4 commit 2673f06

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

main/src/addins/MonoDevelop.AspNetCore/MonoDevelop.AspNetCore/LaunchProfileProvider.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System;
2727
using System.Collections.Concurrent;
2828
using System.Collections.Generic;
29+
using System.Diagnostics;
2930
using System.IO;
3031
using System.Linq;
3132
using System.Net;
@@ -46,7 +47,7 @@ internal class LaunchProfileProvider
4647
readonly object fileLocker = new object ();
4748
public IDictionary<string, JToken> GlobalSettings { get; private set; }
4849
internal JObject ProfilesObject { get; private set; }
49-
public ConcurrentDictionary<string, LaunchProfileData> Profiles { get; set; }
50+
public ConcurrentDictionary<string, LaunchProfileData> Profiles { get; private set; }
5051
internal string LaunchSettingsJsonPath => Path.Combine (baseDirectory, "Properties", "launchSettings.json");
5152
const string DefaultGlobalSettings = @"{
5253
""windowsAuthentication"": false,
@@ -58,12 +59,11 @@ internal class LaunchProfileProvider
5859

5960
public LaunchProfileData DefaultProfile {
6061
get {
61-
if (!Profiles.ContainsKey (defaultNamespace)) {
62-
var defaultProfile = CreateDefaultProfile ();
62+
if (!Profiles.TryGetValue (defaultNamespace, out var defaultProfile)) {
63+
defaultProfile = CreateDefaultProfile ();
6364
Profiles [defaultNamespace] = defaultProfile;
64-
return defaultProfile;
6565
}
66-
return Profiles [defaultNamespace];
66+
return defaultProfile;
6767
}
6868
}
6969

@@ -242,9 +242,7 @@ public LaunchProfileData AddNewProfile (string name)
242242
if (Profiles == null)
243243
Profiles = new ConcurrentDictionary<string, LaunchProfileData> ();
244244

245-
var newProfile = CreateProfile (name);
246-
Profiles [name] = newProfile;
247-
return newProfile;
245+
return Profiles [name] = CreateProfile (name);
248246
}
249247

250248
public LaunchProfileData CreateDefaultProfile () => CreateProfile (defaultNamespace);
@@ -285,10 +283,8 @@ LaunchProfileData CreateProfile (string name)
285283
void CreateAndAddDefaultLaunchSettings ()
286284
{
287285
GlobalSettings.Add ("iisSettings", JToken.Parse (DefaultGlobalSettings));
288-
var profiles = new Dictionary<string, LaunchProfileData> {
289-
{ defaultNamespace, CreateDefaultProfile () }
290-
};
291-
Profiles = new ConcurrentDictionary<string, LaunchProfileData> (profiles);
286+
Profiles = new ConcurrentDictionary<string, LaunchProfileData> ();
287+
Profiles.TryAdd (defaultNamespace, CreateDefaultProfile ());
292288
SaveLaunchSettings ();
293289
}
294290

@@ -320,7 +316,11 @@ internal void SyncRunConfigurations ()
320316
} else if (runConfig is AspNetCoreRunConfiguration aspNetCoreRunConfiguration) {
321317
var index = project.RunConfigurations.IndexOf (runConfig);
322318
aspNetCoreRunConfiguration.UpdateProfile (profile.Value);
323-
project.RunConfigurations [index] = runConfig;
319+
if (index >= 0) {
320+
project.RunConfigurations [index] = runConfig;
321+
}
322+
323+
Debug.Assert (index >= 0, "Didn't find expected run configuration");
324324
}
325325
}
326326

@@ -333,7 +333,7 @@ internal void SyncRunConfigurations ()
333333
key = project.DefaultNamespace;
334334
}
335335

336-
if (Profiles.TryGetValue (key, out var _))
336+
if (Profiles.TryGetValue (key, out _))
337337
continue;
338338

339339
itemsRemoved.Add (config);

0 commit comments

Comments
 (0)