public ActionResult Dashboard(OnlineTranslationRequest translationRequest, string submit) { ITranslationData data = null; IProjectDataFactory projectDataFactory = new ProjectDataFactory(); ISubTranslationDataFactory subTranslationDataFactory = new SubTranslationDataFactory(); ITranslationDataFactory translationDataFactory = new TranslationDataFactory(projectDataFactory, subTranslationDataFactory); IFileRepository fileRepository = new FileRepository(translationDataFactory); switch (submit) { case "Open": if (Request.Files.Count > 0 && Request.Files[0].FileName.Any()) { var file = Request.Files[0]; if (file != null & file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var fileType = Path.GetExtension(fileName); // Need to treat this at some point var filePath = @"C:\Temp\" + fileName; file.SaveAs(filePath); var openData = fileRepository.OpenFile(fileType, filePath, fileName); data = openData.Item1; } } else { throw new Exception("No requests."); } break; case "Create": if (translationRequest != null) { string fileName = translationRequest.ProjectName; string[] rawData = translationRequest.RawData.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); IProjectData project = projectDataFactory.CreateProjectDataFromArray(fileName, rawData); data = translationDataFactory.CreateTranslationDataFromProject(project); } else { throw new Exception("No requests."); } break; default: break; } System.Web.HttpContext.Current.Session["ProjectData"] = data.GetProjectData(); return(View()); }
/// <summary> /// Saves translation project data to file. /// </summary> /// <param name="data">Translation data to save.</param> /// <param name="path">Path of the file.</param> /// <returns>The result of the save.</returns> public bool SaveProject(ITranslationData data, string path) { try { var json = JObject.Parse(data.GetProjectSaveString()); File.WriteAllText(path, json.ToString()); return(true); } catch (System.Exception) { return(false); } }
private bool CreateTranslationProject(ITranslationData translationData) { if (New.Hub != null) { New.Hub.SetDesk(translationData); New.Close(); New.Hub.OpenDesk(); return(true); } if (New.Desk != null) { New.Desk.ResetTranslationProject(translationData); New.Close(); return(true); } return(false); }
/// <summary> /// Exports translated lines in translation project to file. /// </summary> /// <param name="data">Translation data to save.</param> /// <param name="path">Path of the file.</param> /// <returns>The result of the export.</returns> public bool ExportTranslation(ITranslationData data, string path) { try { using (StreamWriter sw = new StreamWriter(path)) { foreach (var item in data.ProjectLines) { sw.WriteLine(item.Translation); } } return(true); } catch (System.Exception) { return(false); } }
public FrmDesk CreateDeskFromOpenFile(OpenFileDialog dialog) { if (dialog.ShowDialog() == DialogResult.OK) { var fileExt = Path.GetExtension(dialog.FileName); var filePath = dialog.FileName; var fileName = Path.GetFileNameWithoutExtension(dialog.SafeFileName); var openData = fileRepository.OpenFile(fileExt, filePath, fileName); ITranslationData data = openData.Item1; string previousSavePath = openData.Item2; return(new FrmDesk(data, previousSavePath, Hub)); } else { return(null); } }
public bool SetDesk(ITranslationData data) { Hub.Desk = new FrmDesk(data, Hub); return(true); }
public TranslationController(ITranslationData translationRepo) { _translationRepo = translationRepo; }
public void SetDesk(ITranslationData data) { consumer.SetDesk(data); }