internal void OnSetIndex(UriHistory u, int newIndex) { var current = Current; RemoveAt(u.Index); Insert(newIndex, u); UpdateIndices(this); _previous = this.Count > 1 ? this[1] : null; if (current != Current) { FireCurrentChangedEvent(); } }
/// <summary> /// Finds or creates a <see cref="IUriHistory"/> for the current user profile. /// It is first the <see cref="ISystemConfiguration.CurrentUserProfile"/>, if it is null we take the first profile /// among <see cref="ISystemConfiguration.UserProfiles"/> that is a file (disk-based), if there is no such registered profile, /// we take the first one (whathever kind of uri it is). Finally, if there is no profile at all, we create a new one /// with the user name and the return of the virtual <see cref="GetDefaultUserConfigAddress"/> method. /// </summary> /// <param name="saving">True if we are saving the configuration. False if we are loading it.</param> /// <returns>A <see cref="IUriHistory"/> that is the current user profile.</returns> public virtual IUriHistory EnsureCurrentUserProfile(bool saving) { IUriHistory currentProfile = _ctx.ConfigManager.SystemConfiguration.CurrentUserProfile; if (currentProfile == null) { currentProfile = _ctx.ConfigManager.SystemConfiguration.UserProfiles.FirstOrDefault(p => p.Address.IsFile); } if (currentProfile == null) { currentProfile = _ctx.ConfigManager.SystemConfiguration.UserProfiles.FirstOrDefault(); } if (currentProfile == null) { currentProfile = _ctx.ConfigManager.SystemConfiguration.UserProfiles.FindOrCreate(GetDefaultUserConfigAddress(saving)); currentProfile.DisplayName = Environment.UserName; } return(currentProfile); }
public void Remove(IUriHistory profile) { UriHistory p = profile as UriHistory; if (profile != null && p.Holder == this) { bool isCurrent = p.Index == 0; _byAddress.Remove(p.Address); RemoveAt(p.Index); var h = CollectionChanged; if (h != null) { h(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, p)); } if (isCurrent) { FireCurrentChangedEvent(); } } }
public virtual IUriHistory EnsureCurrentContextProfile(bool saving) { IUriHistory currentProfile = _ctx.ConfigManager.UserConfiguration.CurrentContextProfile; if (currentProfile == null) { currentProfile = _ctx.ConfigManager.UserConfiguration.ContextProfiles.FirstOrDefault(p => p.Address.IsFile); } if (currentProfile == null) { currentProfile = _ctx.ConfigManager.UserConfiguration.ContextProfiles.FirstOrDefault(); } if (currentProfile == null) { var p = GetDefaultContextProfile(saving); currentProfile = _ctx.ConfigManager.UserConfiguration.ContextProfiles.Find(p.Value); if (currentProfile == null) { currentProfile = _ctx.ConfigManager.UserConfiguration.ContextProfiles.FindOrCreate(p.Value); currentProfile.DisplayName = p.Key; } } return(currentProfile); }
public ContextViewModel( ContextListViewModel parent, IUriHistory model ) { _parent = parent; _model = model; }
public void ChangeEmptyToFilled() { Guid id1 = Guid.NewGuid(); Guid id2 = Guid.NewGuid(); Guid id3 = Guid.NewGuid(); // Creates empty configuration files. { var host = new TestContextHost("ChangeEmptyToFilled"); var ctx = host.CreateContext(); File.Delete(host.SystemConfigAddress.LocalPath); File.Delete(host.DefaultUserConfigAddress.LocalPath); ctx.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id1, ConfigPluginStatus.AutomaticStart); ctx.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id2, ConfigPluginStatus.Disabled); ctx.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id3, ConfigPluginStatus.Manual); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id1, ConfigPluginStatus.ConfigurationMask), Is.EqualTo(ConfigPluginStatus.AutomaticStart)); host.SaveUserConfig(); host.SaveSystemConfig(); } // Creates second user configuration file { var host = new TestContextHost("ChangeEmptyToFilled"); var ctx = host.CreateContext(); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id1, ConfigPluginStatus.ConfigurationMask), Is.EqualTo(ConfigPluginStatus.AutomaticStart), "Accessing the UserConfiguration triggers the load of last active profile: we find back the good configuration."); // Creates a second profile. var p2 = ctx.ConfigManager.SystemConfiguration.UserProfiles.FindOrCreate(GetTestFileUri("UsrConf2")); Assert.That(ctx.ConfigManager.SystemConfiguration.UserProfiles.Count, Is.EqualTo(2), "Our System configuration MUST now contains 2 profiles."); // Consider it as the last active one: it will be used by SaveUserConfig() without parameter. ctx.ConfigManager.SystemConfiguration.CurrentUserProfile = p2; // Change the plugin configuration. ctx.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id1, ConfigPluginStatus.Manual); host.SaveUserConfig(); // Change the plugin configuration again and use the SaveUserConfig( u ) that creates and // activates a 3rd profile. ctx.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id1, ConfigPluginStatus.Disabled); host.SaveUserConfig(GetTestFileUri("UsrConf3"), true); Assert.That(ctx.ConfigManager.SystemConfiguration.UserProfiles.Count, Is.EqualTo(3), "Our System configuration MUST now contains 3 profiles."); // - The original, default one, where plugin id1 is AutomaticStart. // - The UsrConf2 where plugin id1 is Manual. // - The UsrConf3 where plugin id1 is Disabled. host.SaveSystemConfig(); } // Reloading... { var host = new TestContextHost("ChangeEmptyToFilled"); TestBase.DumpFileToConsole(host.SystemConfigAddress.LocalPath); var ctx = host.CreateContext(); Assert.That(ctx.ConfigManager.SystemConfiguration.UserProfiles.Count, Is.EqualTo(3), "The 3 profiles are here!"); Assert.That(ctx.ConfigManager.SystemConfiguration.CurrentUserProfile.Address, Is.EqualTo(GetTestFileUri("UsrConf3")), "The 3rd one is active."); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id1, ConfigPluginStatus.ConfigurationMask), Is.EqualTo(ConfigPluginStatus.Disabled), "Where id1 is disabled."); // To check that underlying objects instances do not change when we load another profile. int userConfigHashCode = ctx.ConfigManager.UserConfiguration.GetHashCode(); int pluginStatusCollectionHashCode = ctx.ConfigManager.UserConfiguration.PluginsStatus.GetHashCode(); IUriHistory p2 = ctx.ConfigManager.SystemConfiguration.UserProfiles.Find(GetTestFileUri("UsrConf2")); host.LoadUserConfig(p2.Address); Assert.That(ctx.ConfigManager.SystemConfiguration.CurrentUserProfile == p2, "The last active profile has been updated by the Load."); Assert.That(ctx.ConfigManager.UserConfiguration.GetHashCode() == userConfigHashCode && ctx.ConfigManager.UserConfiguration.PluginsStatus.GetHashCode() == pluginStatusCollectionHashCode, "Instances are preserved (their content have changed)."); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.Count, Is.EqualTo(3), "We have 3 plugins configured in profile n°2."); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id1, ConfigPluginStatus.ConfigurationMask) == ConfigPluginStatus.Manual, "Plugin id1 is Manual in profile n°2."); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id2, ConfigPluginStatus.ConfigurationMask) == ConfigPluginStatus.Disabled); Assert.That(ctx.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id3, ConfigPluginStatus.ConfigurationMask) == ConfigPluginStatus.Manual); } }