From 7b013ac66a36e0f73d480ef28771a65f64b57e19 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 30 Dec 2017 01:31:32 -0800 Subject: Support serializing localization information in Intermediates --- src/WixToolset.Data/Localization.cs | 72 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) (limited to 'src/WixToolset.Data/Localization.cs') diff --git a/src/WixToolset.Data/Localization.cs b/src/WixToolset.Data/Localization.cs index 10eff2e1..4ddef77b 100644 --- a/src/WixToolset.Data/Localization.cs +++ b/src/WixToolset.Data/Localization.cs @@ -7,8 +7,9 @@ namespace WixToolset.Data using System.Diagnostics; using System.Globalization; using System.Xml; + using SimpleJson; using WixToolset.Data.Msi; - using WixToolset.Data.Rows; + using WixToolset.Data.Bind; /// /// Object that represents a localization file. @@ -74,6 +75,75 @@ namespace WixToolset.Data } } + internal JsonObject Serialize() + { + var jsonObject = new JsonObject + { + { "codepage", this.Codepage }, + }; + + jsonObject.AddIsNotNullOrEmpty("culture", this.Culture); + + // Serialize bind variables. + if (this.Variables.Count > 0) + { + var variablesJson = new JsonArray(this.Variables.Count); + + foreach (var variable in this.Variables) + { + var variableJson = variable.Serialize(); + + variablesJson.Add(variableJson); + } + + jsonObject.Add("variables", variablesJson); + } + + // Serialize localized control. + if (this.LocalizedControls.Count > 0) + { + var controlsJson = new JsonObject(); + + foreach (var controlWithKey in this.LocalizedControls) + { + var controlJson = controlWithKey.Value.Serialize(); + + controlsJson.Add(controlWithKey.Key, controlJson); + } + + jsonObject.Add("controls", controlsJson); + } + + return jsonObject; + } + + internal static Localization Deserialize(JsonObject jsonObject) + { + var codepage = jsonObject.GetValueOrDefault("codepage", 0); + var culture = jsonObject.GetValueOrDefault("culture"); + + var variables = new Dictionary(); + var variablesJson = jsonObject.GetValueOrDefault("variables", new JsonArray()); + foreach (JsonObject variableJson in variablesJson) + { + var bindPath = BindVariable.Deserialize(variableJson); + variables.Add(bindPath.Id, bindPath); + } + + var controls = new Dictionary(); + var controlsJson = jsonObject.GetValueOrDefault("controls"); + if (controlsJson != null) + { + foreach (var controlJsonWithKey in controlsJson) + { + var control = LocalizedControl.Deserialize((JsonObject)controlJsonWithKey.Value); + controls.Add(controlJsonWithKey.Key, control); + } + } + + return new Localization(codepage, culture, variables, controls); + } + /// /// Loads a localization file from a stream. /// -- cgit v1.2.3-55-g6feb