diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:56:09 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-01 10:56:09 -0700 |
| commit | 69b15d96cebdbb7201b1849b4f62786633d70b8d (patch) | |
| tree | 4b65de8679e4b4ab81b69edcccbac1ae9f55a16d /src/WixToolset.Data/IntermediateSection.cs | |
| parent | a8656a87887d6cb2c54f4bbeacee37f7074f1032 (diff) | |
| download | wix-69b15d96cebdbb7201b1849b4f62786633d70b8d.tar.gz wix-69b15d96cebdbb7201b1849b4f62786633d70b8d.tar.bz2 wix-69b15d96cebdbb7201b1849b4f62786633d70b8d.zip | |
Introduce WiX Intermediate Representation
Diffstat (limited to 'src/WixToolset.Data/IntermediateSection.cs')
| -rw-r--r-- | src/WixToolset.Data/IntermediateSection.cs | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/WixToolset.Data/IntermediateSection.cs b/src/WixToolset.Data/IntermediateSection.cs new file mode 100644 index 00000000..2b1f7375 --- /dev/null +++ b/src/WixToolset.Data/IntermediateSection.cs | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixToolset.Data | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using SimpleJson; | ||
| 8 | |||
| 9 | /// <summary> | ||
| 10 | /// Section in an intermediate file. | ||
| 11 | /// </summary> | ||
| 12 | public class IntermediateSection | ||
| 13 | { | ||
| 14 | /// <summary> | ||
| 15 | /// Creates a new section as part of an intermediate. | ||
| 16 | /// </summary> | ||
| 17 | /// <param name="id">Identifier for section.</param> | ||
| 18 | /// <param name="type">Type of section.</param> | ||
| 19 | /// <param name="codepage">Codepage for resulting database.</param> | ||
| 20 | public IntermediateSection(string id, SectionType type, int codepage) | ||
| 21 | { | ||
| 22 | this.Id = id; | ||
| 23 | this.Type = type; | ||
| 24 | this.Codepage = codepage; | ||
| 25 | this.Tuples = new List<IntermediateTuple>(); | ||
| 26 | } | ||
| 27 | |||
| 28 | /// <summary> | ||
| 29 | /// Gets the identifier for the section. | ||
| 30 | /// </summary> | ||
| 31 | /// <value>Section identifier.</value> | ||
| 32 | public string Id { get; } | ||
| 33 | |||
| 34 | /// <summary> | ||
| 35 | /// Gets the type of the section. | ||
| 36 | /// </summary> | ||
| 37 | /// <value>Type of section.</value> | ||
| 38 | public SectionType Type { get; } | ||
| 39 | |||
| 40 | /// <summary> | ||
| 41 | /// Gets the codepage for the section. | ||
| 42 | /// </summary> | ||
| 43 | /// <value>Codepage for the section.</value> | ||
| 44 | public int Codepage { get; set; } | ||
| 45 | |||
| 46 | /// <summary> | ||
| 47 | /// Gets and sets the identifier of the compilation of the source file containing the section. | ||
| 48 | /// </summary> | ||
| 49 | public string CompilationId { get; set; } | ||
| 50 | |||
| 51 | /// <summary> | ||
| 52 | /// Gets and sets the identifier of the library that combined the section. | ||
| 53 | /// </summary> | ||
| 54 | public string LibraryId { get; set; } | ||
| 55 | |||
| 56 | /// <summary> | ||
| 57 | /// Tuples in the section. | ||
| 58 | /// </summary> | ||
| 59 | public IList<IntermediateTuple> Tuples { get; } | ||
| 60 | |||
| 61 | /// <summary> | ||
| 62 | /// Parse a section from the JSON data. | ||
| 63 | /// </summary> | ||
| 64 | internal static IntermediateSection Deserialize(ITupleDefinitionCreator creator, JsonObject jsonObject) | ||
| 65 | { | ||
| 66 | var codepage = jsonObject.GetValueOrDefault("codepage", 0); | ||
| 67 | var id = jsonObject.GetValueOrDefault<string>("id"); | ||
| 68 | var type = jsonObject.GetEnumOrDefault("type", SectionType.Unknown); | ||
| 69 | var tuplesJson = jsonObject.GetValueOrDefault<JsonArray>("tuples"); | ||
| 70 | |||
| 71 | if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type)) | ||
| 72 | { | ||
| 73 | throw new ArgumentException("JSON object is not a valid section"); | ||
| 74 | } | ||
| 75 | |||
| 76 | if (SectionType.Unknown == type) | ||
| 77 | { | ||
| 78 | throw new ArgumentException("JSON object is not a valid section", nameof(type)); | ||
| 79 | } | ||
| 80 | |||
| 81 | var section = new IntermediateSection(id, type, codepage); | ||
| 82 | |||
| 83 | foreach (JsonObject tupleJson in tuplesJson) | ||
| 84 | { | ||
| 85 | var tuple = IntermediateTuple.Deserialize(creator, tupleJson); | ||
| 86 | section.Tuples.Add(tuple); | ||
| 87 | } | ||
| 88 | |||
| 89 | return section; | ||
| 90 | } | ||
| 91 | |||
| 92 | internal JsonObject Serialize() | ||
| 93 | { | ||
| 94 | var jsonObject = new JsonObject | ||
| 95 | { | ||
| 96 | { "type", this.Type.ToString().ToLowerInvariant() }, | ||
| 97 | { "codepage", this.Codepage } | ||
| 98 | }; | ||
| 99 | |||
| 100 | if (!String.IsNullOrEmpty(this.Id)) | ||
| 101 | { | ||
| 102 | jsonObject.Add("id", this.Id); | ||
| 103 | } | ||
| 104 | |||
| 105 | var tuplesJson = new JsonArray(this.Tuples.Count); | ||
| 106 | |||
| 107 | foreach (var tuple in this.Tuples) | ||
| 108 | { | ||
| 109 | var tupleJson = tuple.Serialize(); | ||
| 110 | tuplesJson.Add(tupleJson); | ||
| 111 | } | ||
| 112 | |||
| 113 | jsonObject.Add("tuples", tuplesJson); | ||
| 114 | |||
| 115 | return jsonObject; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
