private JsonValue ExtractTexts(string propertyName, JsonSchema propertyType) { JsonObject result = new JsonObject(); JsonValue otherData = propertyType.OtherData; if (otherData == null) { return(result); } JsonValue texts = otherData.Object.GetValueOrDefault("texts"); if (texts == null) { // For some unknown reason Manatee sometimes needs to explicit use this method to extract other data texts TextsKeyword texts2 = propertyType.Get <TextsKeyword>(); if (texts2 != null) { texts = texts2.ToJson(new JsonSerializer()); } } if (texts != null) { foreach (string textType in texts.Object.Keys) { JsonValue language = texts.Object.GetValueOrDefault(textType); string textKey = TextTypeFormat(propertyName, textType); result.Add(TextTypeFormat(textType), textKey); Dictionary <string, TextResourceElement> languageWithTextResource = new Dictionary <string, TextResourceElement>(); foreach (string lang in language.Object.Keys) { string textMessage = language.Object.TryGetString(lang); languageWithTextResource.Add(LanguageCode(lang), new TextResourceElement { Id = textKey, Value = textMessage }); } if (!modelTexts.ContainsKey(textKey)) { modelTexts.Add(textKey, languageWithTextResource); } } } return(result); }
private void AddAnnotations(XmlSchemaAnnotated element, JsonSchema jSchema) { XmlSchemaAnnotation annotation = new XmlSchemaAnnotation(); TextsKeyword text = jSchema.Get <TextsKeyword>(); if (text != null) { JsonValue textObject = text.ToJson(new JsonSerializer()); foreach (string textType in textObject.Object.Keys) { JsonValue language = textObject.Object.GetValueOrDefault(textType); foreach (string lang in language.Object.Keys) { string textMessage = language.Object.TryGetString(lang); XmlElement p = xmlDocument.CreateElement("p"); p.AppendChild(xmlDocument.CreateTextNode(textMessage)); XmlElement brregTekst = xmlDocument.CreateElement("brreg", "tekst", BRREG_NS); brregTekst.SetAttribute("lang", BRREG_NS, lang); brregTekst.SetAttribute("teksttype", BRREG_NS, textType); brregTekst.AppendChild(p); XmlNode[] nodes = { brregTekst }; XmlSchemaDocumentation documentation = new XmlSchemaDocumentation { Markup = nodes, }; annotation.Items.Add(documentation); } } } AddTitleAndDescriptionAnnotations(jSchema, annotation); if (annotation.Items.Count > 0) { element.Annotation = annotation; } }
/// <summary> /// Add a category of texts to the <code>texts</code> keyword. /// </summary> /// <param name="schema">Json Schema to add category of texts to</param> /// <param name="category">Category for text</param> /// <param name="name">Name for text</param> /// <param name="text">Actual text</param> /// <returns>schema containing new category and texts</returns> public static JsonSchema Texts(this JsonSchema schema, string category, string name, string text) { var keyword = schema.OfType <TextsKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new TextsKeyword(); schema.Add(keyword); } if (keyword.ContainsKey(category)) { JsonSchema categorySchema = keyword[category]; categorySchema.OtherData.Add(name, text); } else { JsonSchema categorySchema = new JsonSchema(); categorySchema.OtherData.Add(name, text); keyword.Add(category, categorySchema); } return(schema); }