public ActionResult Translate(SubtitleTranslationViewModel subtitleTranslationViewModel, string email) { _subtitle = (Subtitle)Session["EditableSubtitle"]; ViewBag.Languages = subtitleTranslationViewModel.Translator == Translators.Bing ? new ServicesLanguages().GetBingLanguages() : new ServicesLanguages().GetGoogleLanguages(); ViewBag.Translators = new List<Translators>() { Translators.Bing, Translators.Google }; #region Validations if (string.IsNullOrEmpty(subtitleTranslationViewModel.FromLanguage)) ModelState.AddModelError("FromLanguage", "Select a language"); if (string.IsNullOrEmpty(subtitleTranslationViewModel.ToLanguage)) ModelState.AddModelError("ToLanguage", "Select a language"); if (!ModelState.IsValid) return View("Translate", subtitleTranslationViewModel); #endregion var translationEngine = new TranslationEngine((Subtitle)_subtitle.Clone(), subtitleTranslationViewModel.Translator, subtitleTranslationViewModel.FromLanguage, subtitleTranslationViewModel.ToLanguage, email); var thread = new Thread(new ThreadStart(translationEngine.Translate)); thread.Start(); return View("Translate"); }
public ActionResult LoadSubtitleToSession(HttpPostedFileBase file) { if (file == null || Path.GetExtension(file.FileName) != ".srt") if (Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.AbsoluteUri); else return RedirectToAction("Index", "Home"); var quotes = new SubtitleHandler().ReadSubtitle(file.InputStream); _subtitle = new Subtitle(quotes) { Name = Path.GetFileName((file.FileName)) }; Session["OriginalSubtitle"] = _subtitle; Session["EditableSubtitle"] = _subtitle.Clone(); if (Request.UrlReferrer != null) return Redirect(Request.UrlReferrer.AbsoluteUri); return RedirectToAction("Index", "Home"); }
public ActionResult Synchronize(int milliseconds) { _subtitle = (Subtitle)Session["EditableSubtitle"]; var cloneSubtitle = _subtitle.Clone(); #region Validations if (milliseconds == 0) ModelState.AddModelError("millisseconds", "Must not be 0."); if (!ModelState.IsValid) return View("Synchronize"); #endregion dynamic delay = milliseconds; delay = TimeSpan.FromMilliseconds(delay); try { cloneSubtitle.Quotes = new SynchronizationEngine().SyncSubtitle(cloneSubtitle.Quotes, delay); } catch (InvalidOperationException ex) { ModelState.AddModelError("Delay", ex.Message); return View("Synchronize"); } Session["EditableSubtitle"] = cloneSubtitle; return View(); }