Esempio n. 1
0
        public void TestNS()
        {
            EntryDictionary dict = GetTestClass();

            Assert.IsNotNull(dict);
            Assert.IsNull(dict.NS);
            dict.NS = "http://www.namespace.example.org/";
            Assert.AreEqual("http://www.namespace.example.org/", dict.NS);
        }
Esempio n. 2
0
        private static EntryDictionary ReadDictionary(string databaseLocator, string type, Dictionary <string, EntryDictionary> cache)
        {
            EntryDictionary dictionary;

            // to distinguish between OWL: QSAR & REACT
            if (type.Contains("_React"))
            {
                databaseLocator += "." + type.Substring(0, type.Length - 6);
            }
            else
            {
                databaseLocator += "." + type;
            }
            if (cache.ContainsKey(databaseLocator))
            {
                return(cache[databaseLocator]);
            }
            else
            {
                Trace.TraceInformation($"Reading dictionary from {databaseLocator}");
                try
                {
                    var reader = new StreamReader(ResourceLoader.GetAsStream(databaseLocator));
                    switch (type)
                    {
                    case "owl":
                        dictionary = OWLFile.Unmarshal(reader);
                        break;

                    case "owl_React":
                        dictionary = OWLReact.Unmarshal(reader);
                        break;

                    default:
                        // assume XML using Castor
                        dictionary = EntryDictionary.Unmarshal(reader);
                        break;
                    }
                }
                catch (Exception exception)
                {
                    dictionary = null;
                    Trace.TraceError($"Could not read dictionary {databaseLocator}");
                    Debug.WriteLine(exception);
                }
                cache[databaseLocator] = dictionary;
                return(dictionary);
            }
        }
Esempio n. 3
0
        public void TestAddEntry()
        {
            EntryDictionary dict = GetTestClass();

            Assert.IsNotNull(dict);
            Assert.AreEqual(0, dict.Count);
            Assert.IsFalse(dict.ContainsKey("someidentifier"));
            Entry entry = new Entry();

            entry.Id = "someidentifier";
            dict.AddEntry(entry);
            Assert.AreEqual(1, dict.Count);
            Assert.IsTrue(dict.ContainsKey("someidentifier"));
            Assert.AreEqual(entry, dict["someidentifier"]);
        }
Esempio n. 4
0
 /// <summary>
 /// Reads a custom dictionary into the database.
 /// </summary>
 /// <param name="reader">The reader from which the dictionary data will be read</param>
 /// <param name="name">The name of the dictionary</param>
 public void ReadDictionary(TextReader reader, string name)
 {
     name = name.ToLowerInvariant();
     Debug.WriteLine($"Reading dictionary: {name}");
     if (!dictionaries.ContainsKey(name))
     {
         try
         {
             var dictionary = EntryDictionary.Unmarshal(reader);
             dictionaries.Add(name, dictionary);
             Debug.WriteLine("  ... loaded and stored");
         }
         catch (Exception exception)
         {
             Trace.TraceError($"Could not read dictionary: {name}");
             Debug.WriteLine(exception);
         }
     }
     else
     {
         Trace.TraceError($"Dictionary already loaded: {name}");
     }
 }
Esempio n. 5
0
 public override void StartDocument()
 {
     Dictionary = new EntryDictionary();
 }
Esempio n. 6
0
 protected void SetTestClass(EntryDictionary testClass)
 {
     this.testClass = testClass;
 }