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; }
public override bool SetPropertyValue(string propertyName, string value, IWritableLaunchSettings launchSettings) { var activeProfile = launchSettings.ActiveProfile; if (activeProfile == null) { return(false); } UpdateActiveLaunchProfile(activeProfile, propertyName, value); return(true); }
public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null) { ILaunchSettings launchSettings = await _launchSettingsProvider.WaitForFirstSnapshot(); IWritableLaunchSettings writableLaunchSettings = launchSettings.ToWritableLaunchSettings(); if (SetPropertyValue(propertyName, unevaluatedPropertyValue, writableLaunchSettings)) { await _launchSettingsProvider.UpdateAndSaveSettingsAsync(writableLaunchSettings.ToLaunchSettings()); } // We've intercepted the "set" operation and redirected it to the launch settings. // Return "null" to indicate that the value should _not_ be set in the project file // as well. return(null); }
public override bool SetPropertyValue(string propertyName, string value, IWritableLaunchSettings launchSettings) { if (propertyName != EnvironmentVariablesPropertyName) { throw new InvalidOperationException($"{nameof(ActiveLaunchProfileEnvironmentVariableValueProvider)} does not handle property '{propertyName}'."); } var activeProfile = launchSettings.ActiveProfile; if (activeProfile == null) { return(false); } ParseStringIntoDictionary(value, activeProfile.EnvironmentVariables); return(true); }
public override async Task <string?> OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string>?dimensionalConditions = null) { ConfiguredProject?configuredProject = await _project.GetSuggestedConfiguredProjectAsync(); IPropertyPagesCatalogProvider?catalogProvider = configuredProject?.Services.PropertyPagesCatalog; if (catalogProvider == null) { return(null); } IPropertyPagesCatalog catalog = await catalogProvider.GetCatalogAsync(PropertyPageContexts.Project); Rule?rule = catalog.GetSchema(unevaluatedPropertyValue); if (rule == null) { return(null); } if (rule.Metadata.TryGetValue("CommandName", out object pageCommandNameObj) && pageCommandNameObj is string pageCommandName) { _projectThreadingService.RunAndForget(async() => { // Infinite timeout means this will not actually be null. ILaunchSettings?launchSettings = await _launchSettingsProvider.WaitForFirstSnapshot(Timeout.Infinite); Assumes.NotNull(launchSettings); IWritableLaunchSettings writableLaunchSettings = launchSettings.ToWritableLaunchSettings(); IWritableLaunchProfile?activeProfile = writableLaunchSettings.ActiveProfile; if (activeProfile != null) { activeProfile.CommandName = pageCommandName; await _launchSettingsProvider.UpdateAndSaveSettingsAsync(writableLaunchSettings.ToLaunchSettings()); } }, options: ForkOptions.HideLocks, unconfiguredProject: _project); } return(null); }
public static bool SettingsDiffer(this IWritableLaunchSettings launchSettings, IWritableLaunchSettings settingsToCompare) { if (launchSettings.Profiles.Count != settingsToCompare.Profiles.Count) { return(true); } // Now compare each item. We can compare in order. If the lists are different then the settings are different even // if they contain the same items for (int i = 0; i < launchSettings.Profiles.Count; i++) { if (!ProfilesAreEqual(launchSettings.Profiles[i], settingsToCompare.Profiles[i])) { return(true); } } // Check the global settings return(!DictionaryEqualityComparer <string, object> .Instance.Equals(launchSettings.GlobalSettings, settingsToCompare.GlobalSettings));
internal virtual void InitializeDebugTargetsCore(ILaunchSettings profiles) { IWritableLaunchSettings newSettings = profiles.ToWritableLaunchSettings(); // Since this get's reentered if the user saves or the user switches active profiles. if (CurrentLaunchSettings != null && !CurrentLaunchSettings.SettingsDiffer(newSettings)) { return; } try { // This should never change the dirty state when loading the dialog PushIgnoreEvents(); // Remember the current selection string curProfileName = SelectedDebugProfile?.Name; // Update the set of settings and generate a property change so the list of profiles gets updated. Note that we always // clear the active profile on the CurrentLaunchSettings so that when we do set one and property changed event is set CurrentLaunchSettings = newSettings; CurrentLaunchSettings.ActiveProfile = null; // Reload the launch profiles collection LaunchProfiles.Clear(); foreach (IWritableLaunchProfile profile in CurrentLaunchSettings.Profiles) { LaunchProfiles.Add(profile); } // When loading new profiles we need to clear the launch type. This is so the external changes cause the current // active provider to be refreshed _selectedLaunchType = null; NotifyProfileCollectionChanged(); // If we have a selection, we want to leave it as is if (curProfileName == null || newSettings.Profiles.Find(p => LaunchProfile.IsSameProfileName(p.Name, curProfileName)) == null) { // Note that we have to be careful since the collection can be empty. if (profiles.ActiveProfile != null && !string.IsNullOrEmpty(profiles.ActiveProfile.Name)) { SelectedDebugProfile = LaunchProfiles.Single(p => LaunchProfile.IsSameProfileName(p.Name, profiles.ActiveProfile.Name)); } else { if (LaunchProfiles.Count > 0) { SelectedDebugProfile = LaunchProfiles[0]; } else { SetEnvironmentGrid(null); } } } else { SelectedDebugProfile = LaunchProfiles.Single(p => LaunchProfile.IsSameProfileName(p.Name, curProfileName)); } } finally { PopIgnoreEvents(); _firstSnapshotCompleteSource?.TrySetResult(); _debugTargetsCoreInitialized = true; } }
/// <summary> /// Sets the property specified by <paramref name="propertyName"/> to <paramref name="value"/> /// in the given <see cref="IWritableLaunchSettings"/>. /// </summary> /// <returns><c>true</c> if the <paramref name="launchSettings"/> were updated; /// otherwise <c>false</c>.</returns> /// <exception cref="InvalidOperationException"> /// Thrown if the given <paramref name="propertyName"/> is not known (that is, it is /// not declared in the implementor's <see cref="ExportInterceptingPropertyValueProviderAttribute"/>). /// </exception> public abstract bool SetPropertyValue(string propertyName, string value, IWritableLaunchSettings launchSettings);
public void ProfileSelected(IWritableLaunchSettings curSettings) { }
public void ProfileSelected(IWritableLaunchSettings curSettings) => _bootableDebugSettingsViewModel.SetLaunchSettings(curSettings);