public void CanSerializeThenDeserializeLanguageElement() { var languageElement = new LanguageElement { IsoCode = "en-GB", Name = "English (United Kingdom)", Fallbacks = new FallbackCollection { new FallbackElement {IsoCode = "en-US"} } }; var result = SerializationService.ToStream(languageElement); Assert.That(result.Success, Is.True); Assert.That(result.ResultStream, Is.Not.Null); var resultJson = result.ResultStream.ToJsonString(); var reHydrated = SerializationService.FromJson<LanguageElement>(resultJson); Assert.That(reHydrated, Is.Not.Null); }
protected ActionResult ProcessSubmit(LanguageEditorModel model, LanguageElement entity) { Mandate.ParameterNotNull(model, "model"); //bind it's data model.BindModel(this); // Check to see if a language already exists with the given ISO code if (model.Id.IsNullValueOrEmpty() || model.Id.Value.ToString() != model.IsoCode) { if (BackOfficeRequestContext.Application.Settings.Languages.Any(x => x.IsoCode == model.IsoCode)) { ModelState.AddModelError("DuplicateLanguage", "A language with the ISO code '" + model.IsoCode + "' already exists."); } } //if there's model errors, return the view if (!ModelState.IsValid) { AddValidationErrorsNotification(); return View("Edit", model); } // Map the language if (entity == null) { entity = BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map<LanguageEditorModel, LanguageElement>(model); } else { //map to existing entity BackOfficeRequestContext.Application.FrameworkContext.TypeMappers.Map(model, entity); } // Persist the entity var configFile = Path.Combine(HttpContext.Server.MapPath("~/App_Data/Umbraco/Config"), "umbraco.cms.languages.config"); var configXml = XDocument.Load(configFile); // Remove previous entry configXml.Descendants("language").Where(x => x.Attribute("isoCode").Value == model.Id.Value.ToString()).Remove(); // Add new entry configXml.Element("languages").Add(XElement.Parse(entity.ToXmlString())); //TODO: When updating and name changes, should we reassign any fallbacks linked to old iso code? or orphan them? Or just prevent language from being changed? configXml.Save(configFile); Notifications.Add(new NotificationMessage( "Language.Save.Message".Localize(this), "Language.Save.Title".Localize(this), NotificationType.Success)); var id = new HiveId(entity.IsoCode); //add path for entity for SupportsPathGeneration (tree syncing) to work, //we need to manually contruct the path because of the static root node id. GeneratePathsForCurrentEntity(new EntityPathCollection(id, new[]{ new EntityPath(new[] { new HiveId(FixedSchemaTypes.SystemRoot, null, new HiveIdValue(new Guid(CorePluginConstants.LanguageTreeRootNodeId))), id }) })); return RedirectToAction("Edit", new { id }); }