static public void AllTranslate(Story s) { main.AddProcessBackground($"Translate story name: {s.Name}"); int end = 0; do { lock (saveSafe) { try { var swords = s.Story_Word.Where(sw => (sw.Word.Translate == null || sw.Word.Translate == "") && (sw.Word.TypeID != 3 || sw.Word.TypeID == 4)); end = swords.Count(); if (end > 250) { swords.Take(100).AsParallel().ForAll(sw => sw.Word.Translate = TranslateYandex.Translate(sw.Word.Text)); } else { swords.AsParallel().ForAll(sw => sw.Word.Translate = TranslateYandex.Translate(sw.Word.Text)); } } catch { } Save(); } }while (end > 0); main.DelProcessBackground($"Translate story name: {s.Name}"); }
static public void AllTranslate() { main.AddProcessBackground("Translate all stories"); int end = 0; int translateWordTime = 10; do { lock (saveSafe) { try { var words = bd.Words.Where(w => (w.Translate == null || w.Translate == "") && (w.TypeID != 3 || w.TypeID == 4)); end = words.Count() - translateWordTime; words.Take(translateWordTime).AsParallel().ForAll(w => w.Translate = TranslateYandex.Translate(w.Text)); } catch { end += translateWordTime; } Save(); } }while (end > 0); main.DelProcessBackground("Translate all stories"); }