public void ReloadSkippedFragments() { INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0]; INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1]; // Creates a dummy dictionnary and writes it. SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2); // Creates a second dictionnary to load previous data (with skippedFragments) string path = TestBase.GetTestFilePath("SharedDic", "ReloadSkippedFragments"); SharedDicTestContext.Write("Test", path, dic, this); IList <ReadElementObjectInfo> errors; ISharedDictionary dic2 = SharedDicTestContext.Read("Test", path, this, d => d.Ensure(uid1), out errors); SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2; Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty."); Assert.That(errors.Count, Is.EqualTo(0)); Assert.That(implDic2.Fragments.Count, Is.EqualTo(1)); Assert.That(dic2[this, uid2, "key1"], Is.Null); Assert.That(dic2[this, uid2, "key2"], Is.Null); // Now we have skippedFragments. Let's try to reload it. dic2.Ensure(uid2); Assert.That(dic2[this, uid2, "key1"], Is.EqualTo("value1")); Assert.That(dic2[this, uid2, "key2"], Is.EqualTo("value2")); Assert.That(implDic2.Fragments.Count, Is.EqualTo(0)); }
public ConfigManagerImpl(ISharedDictionary dic) { _dic = dic; _dic.Changed += new EventHandler <ConfigChangedEventArgs>(ObjectConfigurationChanged); _systemConfiguration = new SystemConfiguration(this); _userConfiguration = new UserConfiguration(this); _solvedPluginConfiguration = new SolvedPluginConfiguration(this); }
public ConfigManagerImpl( ISharedDictionary dic ) { _dic = dic; _dic.Changed += new EventHandler<ConfigChangedEventArgs>( ObjectConfigurationChanged ); _systemConfiguration = new SystemConfiguration( this ); _userConfiguration = new UserConfiguration( this ); _solvedPluginConfiguration = new SolvedPluginConfiguration( this ); }
public ISharedDictionary WriteAndReadWithTests(Action <XmlDocument> afterWrite, Action <ISharedDictionary> beforeRead) { SharedDicTestContext.Write(_testName, _path, _dic, _o, afterWrite); _dicRead = SharedDicTestContext.Read(_testName, _path, _o, beforeRead, out _errors); if (_dicRead.Contains(_uid1)) { CheckRandomProperties(_dicRead, _o, _uid1, 10, _seed); CheckRandomProperties(_dicRead, _o, _uid1, 10, _seed2); } if (_dicRead.Contains(_uid2)) { CheckRandomProperties(_dicRead, _o, _uid2, 20, _seed3); } return(_dicRead); }
protected override void OnLinkedTo(RuntimeHost runtimeHost, params object[] args) { if (args == null || args.Length == 0) { m_dic = SharedDictionary.Create <TKey, TValue>(runtimeHost.Runtime); } else if (args.Length == 1 && args[0] is IEqualityComparer <TKey> comparer) { m_dic = SharedDictionary.Create <TKey, TValue>(comparer, runtimeHost.Runtime); } else { throw new ArgumentOutOfRangeException(nameof(args), "The value needs to translate in null, empty or the array that has just one element as IEqualityComparer<TKey>."); } }
public SharedDictionaryTester(string testName, string path, object o, INamedVersionedUniqueId uid1, INamedVersionedUniqueId uid2, Action <ISharedDictionary, object, INamedVersionedUniqueId> f) { _errors = new List <ReadElementObjectInfo>(); _testName = testName; _path = path; _seed = Environment.TickCount; _o = o; _uid1 = uid1; _uid2 = uid2; _dic = SharedDictionary.Create(null); _seed2 = GenerateRandomProperties(_dic, _o, _uid1, 10, _seed); f(_dic, _o, _uid1); _seed3 = GenerateRandomProperties(_dic, _o, _uid1, 10, _seed2); GenerateRandomProperties(_dic, _o, _uid2, 20, _seed3); }
private int GenerateRandomProperties(ISharedDictionary dic, object o, INamedVersionedUniqueId g, int count, int seed) { Random r = new Random(seed); StringBuilder b = new StringBuilder(10); while (--count > 0) { b.Length = 0; for (int j = 0; j < 10; ++j) { b.Append((char)(r.Next(26) + 'A')); } dic[o, g, b.ToString()] = count; } return(r.Next()); }
public void Import(ISharedDictionary source, MergeMode mergeMode) { SharedDictionaryImpl dicSource = (SharedDictionaryImpl)source; if (dicSource != null && dicSource != this && dicSource._values.Count > 0) { ImportFragments(dicSource._fragments, mergeMode); if (mergeMode == MergeMode.None) { ClearAll(); } foreach (SharedDictionaryEntry s in dicSource._values.Values) { ImportValue(new SharedDictionaryEntry(s.Obj, s.PluginId, s.Key, s.Value), mergeMode); } } }
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); } }
private ISharedDictionary BuggyReader <T>(int expectedErrorCount) where T : BuggyObjectBase, new() { INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0]; INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1]; string path = TestBase.GetTestFilePath("SharedDic", typeof(T).Name); SharedDictionaryTester checker = new SharedDictionaryTester(typeof(T).Name, path, this, uid1, uid2, (d, o, id) => { Assert.That(id == uid1); d[o, id, "AnotherValue"] = 13; d[o, id, "Obj"] = new T() { Name = "No Bug for this one!" }; d[o, id, "Obj2"] = new T() { BugWhileReading = BugRead.SkipTag, Name = "This name will not be read back. (But the object exists.)" }; d[o, id, "Obj3"] = new T() { BugWhileReading = BugRead.MoveToEndTag, Name = "This name will not be read back. (But the object exists.)" }; d[o, id, "Obj4"] = new T() { BugWhileReading = BugRead.Throw, Name = "This object should not exist at all..." }; d[o, id, "YetAnotherValue"] = 87; }); ISharedDictionary d2 = checker.WriteAndReadWithTests(null, dic => { dic.Ensure(uid1); dic.Ensure(uid2); }); TestBase.DumpFileToConsole(path); Assert.That(checker.Errors.Count, Is.EqualTo(expectedErrorCount)); Assert.That(checker.Errors.All(e => e.HasError)); Assert.That(d2[this, uid1, "AnotherValue"], Is.EqualTo(13)); Assert.That(((BuggyObjectBase)d2[this, uid1, "Obj"]).Name, Is.EqualTo("No Bug for this one!")); Assert.That(((BuggyObjectBase)d2[this, uid1, "Obj2"]).Name, Is.EqualTo("Default Name")); Assert.That(((BuggyObjectBase)d2[this, uid1, "Obj3"]).Name, Is.EqualTo("Default Name")); Assert.That(d2[this, uid1, "Obj4"], Is.Null); return(d2); }
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)); } }
public static void Write(string testName, string path, ISharedDictionary dic, object o, Action <XmlDocument> afterWrite) { using (Stream wrt = new FileStream(path, FileMode.Create)) { using (IStructuredWriter sw = SimpleStructuredWriter.CreateWriter(wrt, ServiceProvider)) { using (ISharedDictionaryWriter w = dic.RegisterWriter(sw)) { w.WritePluginsDataElement(testName, o); } } } if (afterWrite != null) { XmlDocument d = new XmlDocument(); d.Load(path); afterWrite(d); d.Save(path); } }
public void ImportReloadedSkippedFragments() { INamedVersionedUniqueId uid1 = SharedDicTestContext.Plugins[0]; INamedVersionedUniqueId uid2 = SharedDicTestContext.Plugins[1]; string path = TestBase.GetTestFilePath("SharedDic", "ImportReloadedSkippedFragments"); #region Creates actual fragments // Creates a dummy dictionnary and writes it. SharedDictionaryImpl dic = CreateDummySharedDic(this, uid1, uid2); SharedDicTestContext.Write("Test", path, dic, this); // Creates a second dictionnary to load previous data (with skippedFragments). IList <ReadElementObjectInfo> errors; SharedDictionaryImpl dicFrag = (SharedDictionaryImpl)SharedDicTestContext.Read("Test", path, this, out errors); Assert.IsTrue(new FileInfo(path).Length > 0, "File must exist and be not empty."); Assert.That(errors.Count, Is.EqualTo(0)); Assert.That(dicFrag.GetSkippedFragments(this).Count == 2); Assert.That(dicFrag[this, uid1, "key1"], Is.Null); Assert.That(dicFrag[this, uid2, "key2"], Is.Null); #endregion ISharedDictionary dic2 = SharedDictionary.Create(SharedDicTestContext.ServiceProvider); dic2[this, uid1, "key1"] = "value1"; dic2[this, uid1, "key2"] = "value2"; Assert.That(dic2[this, uid2, "key1"], Is.Null); Assert.That(dic2[this, uid2, "key2"], Is.Null); dic2.Ensure(uid2); SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2; implDic2.ImportFragments(dicFrag.Fragments, MergeMode.None); Assert.That(implDic2.GetSkippedFragments(this) == null); Assert.That(dic2[this, uid2, "key1"], Is.EqualTo("value1")); Assert.That(dic2[this, uid2, "key2"], Is.EqualTo("value2")); }
public static ISharedDictionary Read(string testName, string path, object o, Action <ISharedDictionary> beforeRead, out IList <ReadElementObjectInfo> errors) { ISharedDictionary dicRead = SharedDictionary.Create(ServiceProvider); if (beforeRead != null) { beforeRead(dicRead); } using (Stream str = new FileStream(path, FileMode.Open)) { using (IStructuredReader sr = SimpleStructuredReader.CreateReader(str, ServiceProvider)) { using (ISharedDictionaryReader r = dicRead.RegisterReader(sr, MergeMode.None)) { r.ReadPluginsDataElement(testName, o); errors = r.ErrorCollector; } } } return(dicRead); }
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); }
public E(ISharedDictionary <int, string> counter) { this.counter = counter; }
public E2(ISharedDictionary <int, string> counter, bool flag) { this.Counter = counter; this.Flag = flag; }
public void Start() { _windowManager = new CustomWindowManager(); _appViewModel = new AppViewModel( this ); _windowManager.ShowWindow( _appViewModel, null, null ); _mainWindow = _appViewModel.GetView( null ) as Window; //_interopHelper = new WindowInteropHelper( _mainWindow ); //RegisterHotKeys(); _contextSaver = Context.ServiceContainer.GetService<IContextSaver>(); _sharedDictionary = Context.ServiceContainer.GetService<ISharedDictionary>(); _mainWindow.Closing += OnWindowClosing; }
public static void Write(string testName, string path, ISharedDictionary dic, object o) { Write(testName, path, dic, o, null); }
public static void Write( string testName, string path, ISharedDictionary dic, object o ) { Write( testName, path, dic, o, null ); }
public E(ISharedDictionary <int, string> counter, TaskCompletionSource <bool> tcs) { this.Counter = counter; this.Tcs = tcs; }
static public IConfigManagerExtended Create(ISharedDictionary dic) { return(new ConfigManagerImpl(dic)); }
public void SimpleConfig() { INamedVersionedUniqueId id1 = SharedDicTestContext.Plugins[0]; INamedVersionedUniqueId id2 = SharedDicTestContext.Plugins[1]; SharedDictionaryImpl dic1 = new SharedDictionaryImpl(SharedDicTestContext.ServiceProvider); // 1 - Writes the data to the file without any skipped fragments since we do not have any yet. dic1[this, id1, "AnIntParam"] = 1; dic1[this, id1, "ABoolParam"] = true; dic1[this, id1, "AStringParam"] = "This marvellous API works!"; dic1[this, id1, "ANullObject"] = null; dic1[this, id2, "AnIntParam"] = 1; dic1[this, id2, "ABoolParam"] = true; dic1[this, id2, "AStringParam"] = "This must not be reloaded since the plugin is not runnable for dic2."; Assert.That(dic1.Contains(id1) && dic1.Contains(id2)); string path1 = TestBase.GetTestFilePath("SharedDic", "SimpleConfig"); SharedDicTestContext.Write("Test", path1, dic1, this); Assert.IsTrue(new FileInfo(path1).Length > 0, "File must exist and be not empty."); // 2 - Reloads the file in another dictionary: fragments are now updated with data from the not runnable plugin. IList <ReadElementObjectInfo> errors; ISharedDictionary dic2 = SharedDicTestContext.Read("Test", path1, this, d => d.Ensure(id1), out errors); Assert.AreEqual(0, errors.Count, "This file has no errors in it."); Assert.That(dic1[this, id1, "AnIntParam"], Is.EqualTo(dic2[this, id1, "AnIntParam"])); Assert.That(dic1[this, id1, "ABoolParam"], Is.EqualTo(dic2[this, id1, "ABoolParam"])); Assert.That(dic1[this, id1, "AStringParam"], Is.EqualTo(dic2[this, id1, "AStringParam"])); Assert.That(dic1[this, id1, "ANullObject"], Is.EqualTo(dic2[this, id1, "ANullObject"])); Assert.That(dic1.Contains(this, id1, "ANullObject") && dic2.Contains(this, id1, "ANullObject"), "The null value has a key."); Assert.That(dic2.Contains(this, id2, "AnUnexistingKey"), Is.False, "Any other key is not defined."); // _notRunnables data are not loaded... Assert.That(dic2[this, id2, "AnIntParam"], Is.Null); Assert.That(dic2.Contains(this, id2, "AnIntParam"), Is.False); Assert.That(dic2[this, id2, "ABoolParam"], Is.Null); Assert.That(dic2.Contains(this, id2, "ABoolParam"), Is.False); Assert.That(dic2[this, id2, "AStringParam"], Is.Null); Assert.That(dic2.Contains(this, id2, "AStringParam"), Is.False); Assert.That(dic2.Contains(this, id2, "ANullObject"), Is.False); // 3 - Rewrites the file n°2 from dic2 with the skipped fragments. string path2 = TestBase.GetTestFilePath("SharedDic", "SimpleConfig2"); SharedDicTestContext.Write("Test", path2, dic2, this); Assert.IsTrue(new FileInfo(path2).Length > 0, "File must exist and be not empty."); // Files are not equal due to whitespace handling and node reordering. // To compare them we should reload the 2 documents and to be independant of the element ordering // we need to ensure that every element of d1 exists with the same attributes in d2 and vice-versa. // 4 - In fragments, we have the NotRunnables[0] plugin fragment. SharedDictionaryImpl implDic2 = (SharedDictionaryImpl)dic2; Assert.That(implDic2.GetSkippedFragments(this).Count == 1); Assert.That(implDic2.GetSkippedFragments(this)[0].PluginId == id2.UniqueId); // Activate the previously not runnable plugin. dic2.Ensure(id2); Assert.That(implDic2.GetSkippedFragments(this), Is.Null, "Fragment has been read (no more fragments)."); Assert.AreEqual(dic1[this, id2, "AnIntParam"], dic2[this, id1, "AnIntParam"]); Assert.AreEqual(dic1[this, id2, "ABoolParam"], dic2[this, id1, "ABoolParam"]); Assert.AreEqual(dic1[this, id2, "AStringParam"], "This must not be reloaded since the plugin is not runnable for dic2."); Assert.AreEqual(dic1[this, id1, "AStringParam"], "This marvellous API works!"); }
public void Start() { _sharedDictionary = Context.ServiceContainer.GetService<ISharedDictionary>(); _vm = new ImportKeyboardViewModel( this, KeyboardContext.Service.Keyboards ); _view = new ImportKeyboardView() { DataContext = _vm }; _view.Closing += OnClosing; _view.Show(); }
public E(ISharedDictionary <int, string> dictionary, ISharedCounter counter, TaskCompletionSource <bool> tcs) { this.dictionary = dictionary; this.counter = counter; this.tcs = tcs; }
public static void Write( string testName, string path, ISharedDictionary dic, object o, Action<XmlDocument> afterWrite ) { using( Stream wrt = new FileStream( path, FileMode.Create ) ) { using( IStructuredWriter sw = SimpleStructuredWriter.CreateWriter( wrt, ServiceProvider ) ) { using( ISharedDictionaryWriter w = dic.RegisterWriter( sw ) ) { w.WritePluginsDataElement( testName, o ); } } } if( afterWrite != null ) { XmlDocument d = new XmlDocument(); d.Load( path ); afterWrite( d ); d.Save( path ); } }