protected override ProjectRunConfiguration OnCreateRunConfiguration(string name) { InitLaunchSettingsProvider(); if (aspNetCoreRunConfs.TryGetValue(name, out var aspNetCoreRunConfiguration)) { return(aspNetCoreRunConfiguration); } var profile = new LaunchProfileData(); var key = name != "Default" ? name : this.Project.DefaultNamespace; if (!launchProfileProvider.Profiles.TryGetValue(key, out var _)) { profile = launchProfileProvider.AddNewProfile(key); launchProfileProvider.Profiles [key] = profile; } else { profile = launchProfileProvider.Profiles [key]; } var aspnetconf = new AspNetCoreRunConfiguration(name, profile); aspnetconf.LaunchProfileProvider = launchProfileProvider; aspnetconf.SaveRequested += Aspnetconf_Save; aspNetCoreRunConfs.Add(name, aspnetconf); return(aspnetconf); }
internal AspNetCoreRunConfiguration(string name, LaunchProfileData profile) : this(name) { CurrentProfile = profile; InitializeLaunchSettings(); }
public static T TryGetOtherSettings <T> (this LaunchProfileData launchProfile, string otherSetting) { if (launchProfile.OtherSettings != null && launchProfile.OtherSettings.TryGetValue(otherSetting, out var value)) { return((T)value); } return(default);
internal void UpdateProfile(LaunchProfileData launchProfile) { CurrentProfile = launchProfile; if (CurrentProfile.EnvironmentVariables == null) { CurrentProfile.EnvironmentVariables = new Dictionary <string, string> (StringComparer.Ordinal); } LoadEnvVariables(); }
public LaunchProfile(LaunchProfileData data) { Name = data.Name; ExecutablePath = data.ExecutablePath; CommandName = data.CommandName; CommandLineArgs = data.CommandLineArgs; WorkingDirectory = data.WorkingDirectory; LaunchBrowser = data.LaunchBrowser ?? false; LaunchUrl = data.LaunchUrl; EnvironmentVariables = data.EnvironmentVariables?.ToImmutableDictionary(); OtherSettings = data.OtherSettings?.ToImmutableDictionary(); DoNotPersist = data.InMemoryProfile; }
LaunchProfileData CreateProfile(string name) { var defaultProfile = new LaunchProfileData { Name = name, CommandName = "Project", LaunchBrowser = true, EnvironmentVariables = new Dictionary <string, string> (StringComparer.Ordinal), OtherSettings = new Dictionary <string, object> (StringComparer.Ordinal) }; defaultProfile.EnvironmentVariables.Add("ASPNETCORE_ENVIRONMENT", "Development"); defaultProfile.OtherSettings.Add("applicationUrl", "https://localhost:5001;http://localhost:5000"); return(defaultProfile); }
LaunchProfileData CreateProfile(string name) { var defaultProfile = new LaunchProfileData { Name = name, CommandName = "Project", LaunchBrowser = true, EnvironmentVariables = new Dictionary <string, string> (StringComparer.Ordinal), OtherSettings = new Dictionary <string, object> (StringComparer.Ordinal) }; defaultProfile.EnvironmentVariables.Add("ASPNETCORE_ENVIRONMENT", "Development"); var anyConfigurationUsesHttps = false; foreach (var runConfiguration in project.RunConfigurations) { if (AspNetCoreCertificateManager.UsingHttps(runConfiguration)) { anyConfigurationUsesHttps = true; break; } } string applicationUrl; var httpPort = GetNextFreePort(); var httpsPort = GetNextFreePort(); if (anyConfigurationUsesHttps) { applicationUrl = $"https://localhost:{httpsPort};http://localhost:{httpPort}"; } else { applicationUrl = $"http://localhost:{httpPort}"; } defaultProfile.OtherSettings.Add("applicationUrl", applicationUrl); return(defaultProfile); }
protected override ProjectRunConfiguration OnCreateRunConfiguration(string name) { InitLaunchSettingsProvider(); if (aspNetCoreRunConfs.TryGetValue(name, out var aspNetCoreRunConfiguration)) { return(aspNetCoreRunConfiguration); } var profile = new LaunchProfileData(); var key = name != "Default" ? name : this.Project.DefaultNamespace; if (!launchProfileProvider.Profiles.TryGetValue(key, out var _)) { profile = launchProfileProvider.AddNewProfile(key); launchProfileProvider.Profiles [key] = profile; } else { profile = launchProfileProvider.Profiles [key]; } var aspnetconf = new AspNetCoreRunConfiguration(name, profile) { LaunchProfileProvider = launchProfileProvider }; if (aspNetCoreRunConfs.TryGetValue(name, out var existingConf)) { // This can be called a few times with the same config at load time, // so make sure we clean up the previous version existingConf.SaveRequested -= Aspnetconf_Save; } aspnetconf.SaveRequested += Aspnetconf_Save; aspNetCoreRunConfs [name] = aspnetconf; return(aspnetconf); }
internal void InitializeLaunchSettings() { if (launchProfileProvider == null) { return; } Profiles = LaunchProfileData.DeserializeProfiles(launchProfileProvider.ProfilesObject); ActiveProfile = string.Empty; if (CurrentProfile.OtherSettings == null) { CurrentProfile.OtherSettings = new Dictionary <string, object> (StringComparer.Ordinal); } if (CurrentProfile.EnvironmentVariables == null) { CurrentProfile.EnvironmentVariables = new Dictionary <string, string> (StringComparer.Ordinal); } LoadEnvVariables(); }
public void LoadLaunchSettings() { if (!File.Exists(LaunchSettingsJsonPath)) { CreateAndAddDefaultLaunchSettings(); return; } var launchSettingsJson = TryParse(); GlobalSettings.Clear(); foreach (var token in launchSettingsJson) { if (token.Key == "profiles") { ProfilesObject = token.Value as JObject; continue; } GlobalSettings.Add(token.Key, token.Value); } Profiles = new ConcurrentDictionary <string, LaunchProfileData> (LaunchProfileData.DeserializeProfiles(ProfilesObject)); }
/// <summary> /// To handle custom settings, we serialize using LaunchProfileData first and then walk the settings /// to pick up other settings. Currently limited to boolean, integer, string and dictionary of string /// </summary> public static Dictionary <string, LaunchProfileData> DeserializeProfiles(JObject profilesObject) { var profiles = new Dictionary <string, LaunchProfileData> (StringComparer.Ordinal); if (profilesObject == null) { return(profiles); } // We walk the profilesObject and serialize each subobject component as either a string, or a dictionary<string,string> foreach (var profile in profilesObject) { var jToken = profile.Value; var key = profile.Key; // Name of profile is the key, value is it's contents. We have specific serializing of the data based on the // JToken type LaunchProfileData profileData = JsonConvert.DeserializeObject <LaunchProfileData> (jToken.ToString()); // Now pick up any custom properties. Handle string, int, boolean var customSettings = new Dictionary <string, object> (StringComparer.Ordinal); foreach (JToken data in jToken.Children()) { if (!(data is JProperty dataProperty)) { continue; } if (!IsKnownProfileProperty(dataProperty.Name)) { try { switch (dataProperty.Value.Type) { case JTokenType.Boolean: { bool value = bool.Parse(dataProperty.Value.ToString()); customSettings.Add(dataProperty.Name, value); break; } case JTokenType.Integer: { int value = int.Parse(dataProperty.Value.ToString()); customSettings.Add(dataProperty.Name, value); break; } case JTokenType.Object: { Dictionary <string, string> value = JsonConvert.DeserializeObject <Dictionary <string, string> > (dataProperty.Value.ToString()); customSettings.Add(dataProperty.Name, value); break; } case JTokenType.String: { customSettings.Add(dataProperty.Name, dataProperty.Value.ToString()); break; } default: { break; } } } catch (Exception e) { // TODO: should have message indicating the setting is being ignored. Fix as part of issue // https://github.com/dotnet/roslyn-project-system/issues/424 } } } // Only add custom settings if we actually picked some up if (customSettings.Count > 0) { profileData.OtherSettings = customSettings; } profiles.Add(key, profileData); } return(profiles); }