public async Task<TranslateRequestResult> GetTranslationResult(string originalText, TranslateDirection direction) { var result = await request(translaterTranslateSrv, originalText); if (result.TranslatedData.Definitions.Count > 0) saveResultToLocalCache(result, direction); return result; }
public int GetCountDifferenceSources(TranslateDirection direction) { throw new NotImplementedException(); /*return (from item in db.Table<SourceExpression>() where item.DeleteMark == 0 && item.DirectionID == direction.GetCurrentDirectionId() select item.ID).Count();*/ }
public List<string> GetIncorrectVariants(int excludeCorrectSourceId, int countOfIncorrectWords, TranslateDirection direction) { throw new NotImplementedException(); /*var srcDefView = from item in db.Table<SourceExpression>() join sourceDefItem in db.Table<SourceDefinition>() on item.ID equals sourceDefItem.SourceExpressionID into sources from subSources in sources.DefaultIfEmpty() where (item.ID != excludeCorrectSourceId)&&(item.DirectionID == direction.GetCurrentDirectionId()) select subSources.ID; var view = from item in db.Table<Favorites>() join trExprItem in db.Table<TranslatedExpression>() on item.TranslatedExpressionID equals trExprItem.ID into expressions from subExpressions in expressions.DefaultIfEmpty() where srcDefView.Contains(subExpressions.SourceDefinitionID) select subExpressions.TranslatedText; return view.Take(countOfIncorrectWords).ToList<string>();*/ }
public TranslateRequest(TypeTranslateServices typeSrv, TranslateDirection direction) { this.direction = direction; //ToDo:Отказаться от свитча. Пока непонятно как. switch (typeSrv) { case TypeTranslateServices.YandexTranslate: { translater = new YandexTranslateJSON(); }; break; case TypeTranslateServices.YandexDictionary: { translater = new YandexDictionaryJSON(); }; break; default: { }; break; } }
public List<FavoriteItem> GetRandomFavorites(int countOfWords, TranslateDirection direction) { IEnumerable<int> srcDefView = getSourceDefinitionByTranslateDirection(direction); IEnumerable<FavoriteItem> favView = getFavoritesBySourceDefinition(srcDefView); IEnumerable<FavoriteItem> favDistinctView = getFavoritesDistinct(favView); var favElements = favDistinctView.Distinct(); int countOfRecords = favElements.Count(); FavoritesManager favManager = new FavoritesManager(db); Random rnd = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); int maxCountOfWords = countOfWords <= countOfRecords ? countOfWords : countOfRecords; List<FavoriteItem> items = new List<FavoriteItem>(); List<int> usedIdList = new List<int>(); for(int i=0;i< maxCountOfWords;i++) { int indexOfRecord = rnd.Next(0, maxCountOfWords - 1); if (usedIdList.Contains(indexOfRecord)) indexOfRecord = rnd.Next(0, maxCountOfWords - 1); //ToDo:нужна проверка в цикле, может быть ситуация с повторными ид items.Add(favElements.ElementAt(indexOfRecord)); usedIdList.Add(indexOfRecord); } return items; }
private void saveResultToLocalCache(TranslateRequestResult result, TranslateDirection direction) { CachedResultWriter localDBWriter = new CachedResultWriter(direction, db, new SourceExpressionManager(db)); localDBWriter.SaveResultToLocalCacheIfNotExist(result); }
public CachedResultWriter(TranslateDirection direction, ISQLiteTesting db, ISourceExpressionManager sourceExpressionManager) { this.direction = direction; this.db = db; this.sourceExpressionManager = sourceExpressionManager; }
private TranslateRequestRunner getRequestRunner(TranslateDirection translateDirection) { TranslateRequestRunner reqRunner = new TranslateRequestRunner( SqlLiteInstance.DB, new CachedResultReader(translateDirection, SqlLiteInstance.DB), new TranslateRequest(TypeTranslateServices.YandexDictionary, translateDirection), new TranslateRequest(TypeTranslateServices.YandexTranslate, translateDirection)); return reqRunner; }
private IEnumerable<int> getSourceDefinitionByTranslateDirection(TranslateDirection direction) { throw new NotImplementedException(); /*return from item in db.Table<SourceExpression>() join sourceDefItem in db.Table<SourceDefinition>() on item.ID equals sourceDefItem.SourceExpressionID into sources from subSources in sources.DefaultIfEmpty(new SourceDefinition()) where item.DirectionID == direction.GetCurrentDirectionId() select subSources != null ? subSources.ID : 0;*/ }
public CachedResultReader(TranslateDirection direction, ISQLiteTesting dbHelper) { this.direction = direction; db = dbHelper; }