internal PluginConfigAccessor(INamedVersionedUniqueId idEdited, IConfigManagerExtended cfg, object contextObject) { Debug.Assert(cfg != null); _idEdited = idEdited; _configContainer = cfg.Container; _system = _configContainer.GetObjectPluginConfig(cfg.ConfigManager.SystemConfiguration, _idEdited); _user = _configContainer.GetObjectPluginConfig(cfg.ConfigManager.UserConfiguration, _idEdited); _context = _configContainer.GetObjectPluginConfig(contextObject, _idEdited); }
public void DirtyUserFinalDictionnary() { var ctx = MiniContext.CreateMiniContext("DirtyUserFinalDictionnary"); IConfigManagerExtended config = ctx.ConfigManager.Extended; Assert.IsNotNull(config); Assert.That(config.ConfigManager.UserConfiguration != null); Assert.That(ctx.HostUserConfig != null); Assert.That(!config.IsUserConfigDirty); ctx.HostUserConfig.GetOrSet("key2", "value2"); Assert.That(config.IsUserConfigDirty); Assert.That(ctx.HostUserConfig.Count, Is.EqualTo(1)); }
public void WriteReadUserConfig() { string path = Path.Combine(TestFolder, "UserConfig.xml"); Guid id = new Guid("{6AFBAE01-5CD1-4EDE-BB56-4590C5A253DF}"); // Write ---------------------------------------------------------- { ISharedDictionary dic = SharedDictionary.Create(null); IConfigManagerExtended config = ConfigurationManager.Create(dic); Assert.That(config, Is.Not.Null); Assert.That(config.HostUserConfig, Is.Not.Null); Assert.That(config.ConfigManager.UserConfiguration, Is.Not.Null); config.HostUserConfig["key1"] = "value1"; config.HostUserConfig["key2"] = "value2"; config.HostUserConfig["key3"] = "value3"; config.ConfigManager.UserConfiguration.PluginsStatus.SetStatus(id, ConfigPluginStatus.AutomaticStart); Assert.That(config.IsUserConfigDirty); Assert.That(config.IsSystemConfigDirty, Is.False); using (Stream wrt = new FileStream(path, FileMode.Create)) using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, null)) { config.SaveUserConfig(sw); } } // Read ------------------------------------------------------------ { ISimpleServiceContainer container = new SimpleServiceContainer(); ISharedDictionary dic = SharedDictionary.Create(container); IConfigManagerExtended config = ConfigurationManager.Create(dic); using (Stream str = new FileStream(path, FileMode.Open)) using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, container)) { config.LoadUserConfig(sr); } Assert.That(config.HostUserConfig["key1"], Is.EqualTo("value1")); Assert.That(config.HostUserConfig["key2"], Is.EqualTo("value2")); Assert.That(config.HostUserConfig["key3"], Is.EqualTo("value3")); Assert.That(config.ConfigManager.UserConfiguration.PluginsStatus.GetStatus(id, ConfigPluginStatus.Disabled) == ConfigPluginStatus.AutomaticStart); } }
public void WriteReadSystemConfig() { string path = Path.Combine(TestFolder, "SystemConfig.xml"); // Write ---------------------------------------------------------- { ISharedDictionary dic = SharedDictionary.Create(null); IConfigManagerExtended config = ConfigurationManager.Create(dic); Assert.That(config.ConfigManager.SystemConfiguration != null); config.HostSystemConfig["key1"] = "value1"; config.HostSystemConfig["key2"] = "value2"; config.HostSystemConfig["key3"] = "value3"; config.HostSystemConfig["{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}"] = true; Assert.That(config.IsSystemConfigDirty); Assert.That(config.IsUserConfigDirty, Is.False); using (Stream wrt = new FileStream(path, FileMode.Create)) using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, null)) { config.SaveSystemConfig(sw); } } TestBase.DumpFileToConsole(path); // Read ------------------------------------------------------------ { ISharedDictionary dic = SharedDictionary.Create(null); IConfigManagerExtended config = new ConfigManagerImpl(dic); using (Stream str = new FileStream(path, FileMode.Open)) using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, null)) { config.LoadSystemConfig(sr); } Assert.That(config.HostSystemConfig["key1"], Is.EqualTo("value1")); Assert.That(config.HostSystemConfig["key2"], Is.EqualTo("value2")); Assert.That(config.HostSystemConfig["key3"], Is.EqualTo("value3")); Assert.That(config.HostSystemConfig["{12A9FCC0-ECDC-4049-8DBF-8961E49A9EDE}"], Is.EqualTo(true)); } }
/// <summary> /// Initializes a new <see cref="IContext"/>: one and only one context can be created by a host. /// Context events are associated to the abstract methods <see cref="LoadSystemConfig"/>/<see cref="SaveSystemConfig"/>, /// <see cref="LoadUserConfig"/>/<see cref="SaveUserConfig"/> and <see cref="SaveContext"/>: it is up to this host to provide /// actual System and User configuration. /// </summary> /// <returns>A new context.</returns> public virtual IContext CreateContext() { if (Context != null) { throw new InvalidOperationException(Res.R.HostAlreadyOwnsContext); } _ctx = CK.Context.Context.CreateInstance(); IConfigManagerExtended cfg = _ctx.ConfigManager.Extended; cfg.LoadSystemConfigRequired += (o, e) => LoadSystemConfig(); cfg.LoadUserConfigRequired += (o, e) => LoadUserConfig(); ISimplePluginRunner runner = _ctx.PluginRunner; runner.ServiceHost.DefaultConfiguration.SetAllEventsConfiguration(typeof(IContext), ServiceLogEventOptions.LogErrors | ServiceLogEventOptions.SilentEventError); runner.ServiceHost.ApplyConfiguration(); return(_ctx); }
private Context(bool proxified) { _serviceContainer = new ContextServiceContainer(this); _dic = SharedDictionary.Create(_serviceContainer); _configManager = ConfigurationManager.Create(_dic); _reqLayer = new RequirementLayer("Context"); _pluginRunner = new PluginRunner(_serviceContainer, _configManager.ConfigManager); _serviceContainer.Add(RequirementLayerSerializer.Instance); _serviceContainer.Add(SimpleTypeFinder.Default); if (proxified) { _proxifiedContext = (IContext)_pluginRunner.ServiceHost.InjectExternalService(typeof(IContext), this); } else { _proxifiedContext = this; _serviceContainer.Add <IContext>(this); } _pluginRunner.Initialize(_proxifiedContext); }