示例#1
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);
            }
        }
示例#2
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}");
     }
 }