//--------------------------------------- // getEntry //--------------------------------------- public QueryDictResult getEntry(string inText) { QueryDictResult result = new QueryDictResult(""); try { using (var streamdb = Eviroment.getR_W_fromResource(localBaseFileName)) using (var db = new LiteDatabase(streamdb)) { var dictionary = db.GetCollection <DictEntry>("Dictionary"); var dictSqlReg = new DictEntry(); dictionary.EnsureIndex(x => x.EntryData.sourceText); var entries = dictionary.Find(x => x.EntryData.sourceText == inText); if (entries.OfType <DictEntry>().Count() > 0) { result = entries.First().EntryData; } } } catch (Exception ex) { log.Debug(ex.StackTrace); log.Debug("Setting result to empty object"); result = new QueryDictResult(inText); } return(result); }
public void saveEntry(QueryDictResult inDictData) { try { using (var streamdb = Eviroment.getR_W_fromResource(localBaseFileName)) using (var db = new LiteDatabase(streamdb)) { var dictionary = db.GetCollection <DictEntry>("Dictionary"); if (!inDictData.IsEmpty && !dictionary.Exists(x => x.EntryData.sourceText == inDictData.sourceText)) { var dictSqlReg = new DictEntry(); dictSqlReg.EntryData = inDictData; dictionary.EnsureIndex(x => x.EntryData.sourceText); dictionary.Insert(dictSqlReg); } } } catch (Exception ex) { log.Debug(ex.StackTrace); } }
private DictionaryConfig getDictConfig() { log.Debug(">>Loading web dictionary config..."); DictionaryConfig result = new DictionaryConfig(); try { XmlSerializer serializer = new XmlSerializer(typeof(DictionaryConfig)); /* If the XML document has been altered with unknown * nodes or attributes, handle them with the * UnknownNode and UnknownAttribute events.*/ serializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute); // A FileStream is needed to read the XML document. using (StreamReader fs = Eviroment.getR_fromAsset(DICT_CONF_FILE)) { result = (DictionaryConfig)serializer.Deserialize(fs); } // Declare an object variable of the type to be deserialized. /* Use the Deserialize method to restore the object's state with * data from the XML document. */ // Read the order date. } catch (Exception ex) { log.Debug(ex.StackTrace); log.Debug("Creating empty dictionary config"); result = new DictionaryConfig(); } return(result); }
public int totalEntries() { int result = -1; try { using (var streamdb = Eviroment.getR_W_fromResource(localBaseFileName)) using (var db = new LiteDatabase(streamdb)) { var dictionary = db.GetCollection <DictEntry>("Dictionary"); dictionary.EnsureIndex(x => x.EntryData.sourceText); int count = dictionary.FindAll().ToList <DictEntry>().Count; result = count; } } catch (Exception ex) { log.Debug(ex.StackTrace); log.Debug("Setting result to -1"); result = -1; } return(result); }