public void ImportCsvNonExistantLanguageCulture() { var report = _localizationService.FromCsv("frFR", new List <string> { "test", "test" }); Assert.AreEqual(report.Errors.Count, 1); Assert.AreEqual(report.Errors[0].ErrorWarningType, CsvErrorWarningType.DoesNotExist); }
private InstallerResult AddOrUpdateTheDefaultLanguageStrings(InstallerResult installerResult) { // Read in CSV and import like it does normally in the admin section using (var unitOfWork = _UnitOfWorkManager.NewUnitOfWork()) { var report = new CsvReport(); try { // Get the base language file var file = System.Web.HttpContext.Current.Server.MapPath(@"~/Installer/en-GB.csv"); // Verify that the user selected a file if (file != null) { // Unpack the data var allLines = new List <string>(); using (var streamReader = new StreamReader(file, Encoding.UTF8, true)) { while (streamReader.Peek() >= 0) { allLines.Add(streamReader.ReadLine()); } } // Read the CSV file and generate a language report = _localizationService.FromCsv("en-GB", allLines); } unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); //Loop through report errors and spit them out in the installer result message? var sb = new StringBuilder(); foreach (var error in report.Errors) { if (error.ErrorWarningType == CsvErrorWarningType.BadDataFormat || error.ErrorWarningType == CsvErrorWarningType.GeneralError) { sb.AppendFormat("{0}<br />", error.Message); } } installerResult.Exception = ex.InnerException; installerResult.Message = "Error creating the initial data >> Language Strings"; if (!string.IsNullOrEmpty(sb.ToString())) { installerResult.Message += string.Concat("<br />", sb.ToString()); } installerResult.Successful = false; } return(installerResult); } }
public WrappedJsonResult ImportLanguage(string languageCulture, HttpPostedFileBase file) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { var report = new CsvReport(); //http://www.dustinhorne.com/post/2011/11/16/AJAX-File-Uploads-with-jQuery-and-MVC-3.aspx try { // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // Unpack the data var allLines = new List <string>(); using (var streamReader = new StreamReader(file.InputStream, System.Text.Encoding.UTF8, true)) { while (streamReader.Peek() >= 0) { allLines.Add(streamReader.ReadLine()); } } // Read the CSV file and generate a language report = _localizationService.FromCsv(languageCulture, allLines); unitOfWork.Commit(); } else { report.Errors.Add(new CsvErrorWarning { ErrorWarningType = CsvErrorWarningType.BadDataFormat, Message = "File does not contain a language." }); } } catch (Exception ex) { unitOfWork.Rollback(); report.Errors.Add(new CsvErrorWarning { ErrorWarningType = CsvErrorWarningType.GeneralError, Message = string.Format("Unable to import language: {0}", ex.Message) }); } return(new WrappedJsonResult { Data = ToJSON(report) }); } }