void CreateAndAddDefaultLaunchSettings() { GlobalSettings.Add("iisSettings", JToken.Parse(DefaultGlobalSettings)); Profiles = new ConcurrentDictionary <string, LaunchProfileData> (); Profiles.TryAdd(defaultNamespace, CreateDefaultProfile()); SaveLaunchSettings(); }
public LaunchSettings(IWritableLaunchSettings settings, long version = 0) { Profiles = ImmutableList <ILaunchProfile> .Empty; foreach (IWritableLaunchProfile profile in settings.Profiles) { Profiles = Profiles.Add(new LaunchProfile(profile)); } var jsonSerializerSettings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }; // For global settings we want to make new copies of each entry so that the snapshot remains immutable. If the object implements // ICloneable that is used, otherwise, it is serialized back to json, and a new object rehydrated from that GlobalSettings = ImmutableStringDictionary <object> .EmptyOrdinal; foreach ((string key, object value) in settings.GlobalSettings) { if (value is ICloneable cloneableObject) { GlobalSettings = GlobalSettings.Add(key, cloneableObject.Clone()); } else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); object clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); GlobalSettings = GlobalSettings.Add(key, clonedObject); } } _activeProfileName = settings.ActiveProfile?.Name; Version = version; }
/// <summary> /// Called to define a Setting for the Algorithm that can be used at runtime. /// </summary> /// <param name="setting"></param> public void DefineSetting(AlgorithmSetting setting) { //Active if (setting.TypeOfSetting == SettingType.ActiveAndDead || setting.TypeOfSetting == SettingType.ActiveOnly) { var instanceCopy = setting.Clone(); instanceCopy.InstanceType = SettingInstanceType.Active; ActiveSettings.Add(instanceCopy); } //Dead if (setting.TypeOfSetting == SettingType.ActiveAndDead || setting.TypeOfSetting == SettingType.DeadOnly) { var instanceCopy = setting.Clone(); instanceCopy.InstanceType = SettingInstanceType.Dead; DeadSettings.Add(instanceCopy); } //Global if (setting.TypeOfSetting == SettingType.Global) { var instanceCopy = setting.Clone(); instanceCopy.InstanceType = SettingInstanceType.Global; GlobalSettings.Add(instanceCopy); } }
void CreateAndAddDefaultLaunchSettings() { GlobalSettings.Add("iisSettings", JToken.Parse(DefaultGlobalSettings)); var profilesData = new Dictionary <string, LaunchProfileData> (); profilesData.Add(project.DefaultNamespace, CreateDefaultProfile()); SaveLaunchSettings(profilesData.ToSerializableForm()); }
public WritableLaunchSettings(ILaunchSettings settings) { if (settings.Profiles != null) { foreach (ILaunchProfile profile in settings.Profiles) { Profiles.Add(new WritableLaunchProfile(profile)); } } // For global settings we want to make new copies of each entry so that the snapshot remains immutable. If the object implements // ICloneable that is used, otherwise, it is serialized back to json, and a new object rehydrated from that if (settings.GlobalSettings != null) { var jsonSerializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; foreach ((string key, object value) in settings.GlobalSettings) { if (value is ICloneable cloneableObject) { GlobalSettings.Add(key, cloneableObject.Clone()); } else { string jsonString = JsonConvert.SerializeObject(value, Formatting.Indented, jsonSerializerSettings); object?clonedObject = JsonConvert.DeserializeObject(jsonString, value.GetType()); if (clonedObject is not null) { GlobalSettings.Add(key, clonedObject); } } } } if (settings.ActiveProfile != null) { ActiveProfile = Profiles.Find(profile => LaunchProfile.IsSameProfileName(profile.Name, settings.ActiveProfile.Name)); } }
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); } }
public WritableLaunchSettings(ILaunchSettings settings) { if (settings.Profiles != null) { foreach (ILaunchProfile profile in settings.Profiles) { // Make a mutable/writable copy of each profile Profiles.Add(new WritableLaunchProfile(profile)); } } foreach ((string key, object value) in LaunchSettings.CloneGlobalSettingsValues(settings.GlobalSettings)) { GlobalSettings.Add(key, value); } if (settings.ActiveProfile != null) { ActiveProfile = Profiles.Find(profile => LaunchProfile.IsSameProfileName(profile.Name, settings.ActiveProfile.Name)); } }
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)); }
public WritableLaunchSettings(ILaunchSettings settings) { if (settings.Profiles != null) { foreach (ILaunchProfile profile in settings.Profiles) { Profiles.Add(new WritableLaunchProfile(profile)); } } // For global settings we want to make new copies of each entry so that the snapshot remains immutable. If the object implements // ICloneable that is used, otherwise, it is serialized back to json, and a new object rehydrated from that if (settings.GlobalSettings != null) { foreach (KeyValuePair <string, object> kvp in settings.GlobalSettings) { if (kvp.Value is ICloneable clonableObject) { GlobalSettings.Add(kvp.Key, clonableObject.Clone()); } else { string jsonString = JsonConvert.SerializeObject(kvp.Value, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); object clonedObject = JsonConvert.DeserializeObject(jsonString, kvp.Value.GetType()); GlobalSettings.Add(kvp.Key, clonedObject); } } } if (settings.ActiveProfile != null) { ActiveProfile = Profiles.FirstOrDefault((profile) => LaunchProfile.IsSameProfileName(profile.Name, settings.ActiveProfile.Name)); } }