blob: 42ef111b6f9d9724fbeaf6e03bcab5bf4f99d660 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
// 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.
namespace WixToolset.Data
{
using System;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
/// <summary>
/// Field containing data for an object column in a row.
/// </summary>
public sealed class ObjectField : Field
{
/// <summary>
/// Instantiates a new Field.
/// </summary>
/// <param name="columnDefinition">Column definition for this field.</param>
internal ObjectField(ColumnDefinition columnDefinition) :
base(columnDefinition)
{
}
/// <summary>
/// Gets or sets the index of the embedded file in a library.
/// </summary>
/// <value>The index of the embedded file.</value>
public int? EmbeddedFileIndex { get; set; }
/// <summary>
/// Gets or sets the previous index of the embedded file in the library.
/// </summary>
/// <value>The previous index of the embedded file.</value>
public int? PreviousEmbeddedFileIndex { get; set; }
/// <summary>
/// Gets or sets the path to the embedded cabinet of the previous file.
/// </summary>
/// <value>The path of the cabinet containing the previous file.</value>
public Uri PreviousBaseUri { get; set; }
/// <summary>
/// Gets the base URI of the object field.
/// </summary>
/// <value>The base URI of the object field.</value>
public Uri BaseUri { get; private set; }
/// <summary>
/// Gets or sets the unresolved data for this field.
/// </summary>
/// <value>Unresolved Data in the field.</value>
public string UnresolvedData { get; set; }
/// <summary>
/// Gets or sets the unresolved previous data.
/// </summary>
/// <value>The unresolved previous data.</value>
public string UnresolvedPreviousData { get; set; }
/// <summary>
/// Parse a field from the xml.
/// </summary>
/// <param name="reader">XmlReader where the intermediate is persisted.</param>
internal override void Read(XmlReader reader)
{
Debug.Assert("field" == reader.LocalName);
bool empty = reader.IsEmptyElement;
this.BaseUri = new Uri(reader.BaseURI);
while (reader.MoveToNextAttribute())
{
switch (reader.LocalName)
{
case "cabinetFileId":
this.EmbeddedFileIndex = Convert.ToInt32(reader.Value);
break;
case "modified":
this.Modified = reader.Value.Equals("yes");
break;
case "previousData":
this.PreviousData = reader.Value;
break;
case "unresolvedPreviousData":
this.UnresolvedPreviousData = reader.Value;
break;
case "unresolvedData":
this.UnresolvedData = reader.Value;
break;
case "previousCabinetFileId":
this.PreviousEmbeddedFileIndex = Convert.ToInt32(reader.Value);
break;
}
}
if (!empty)
{
bool done = false;
while (!done && reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
throw new XmlException();
case XmlNodeType.CDATA:
case XmlNodeType.Text:
if (0 < reader.Value.Length)
{
this.Data = reader.Value;
}
break;
case XmlNodeType.EndElement:
done = true;
break;
}
}
if (!done)
{
throw new XmlException();
}
}
}
/// <summary>
/// Persists a field in an XML format.
/// </summary>
/// <param name="writer">XmlWriter where the Field should persist itself as XML.</param>
internal override void Write(XmlWriter writer)
{
writer.WriteStartElement("field", Intermediate.XmlNamespaceUri);
if (this.EmbeddedFileIndex.HasValue)
{
writer.WriteStartAttribute("cabinetFileId");
writer.WriteValue(this.EmbeddedFileIndex);
writer.WriteEndAttribute();
}
if (this.Modified)
{
writer.WriteAttributeString("modified", "yes");
}
if (null != this.UnresolvedPreviousData)
{
writer.WriteAttributeString("unresolvedPreviousData", this.UnresolvedPreviousData);
}
if (null != this.PreviousData)
{
writer.WriteAttributeString("previousData", this.PreviousData);
}
if (null != this.UnresolvedData)
{
writer.WriteAttributeString("unresolvedData", this.UnresolvedData);
}
if (this.PreviousEmbeddedFileIndex.HasValue)
{
writer.WriteStartAttribute("previousCabinetFileId");
writer.WriteValue(this.PreviousEmbeddedFileIndex);
writer.WriteEndAttribute();
}
// Convert the data to a string that will persist nicely (nulls as String.Empty).
string text = Convert.ToString(this.Data, CultureInfo.InvariantCulture);
if (this.Column.UseCData)
{
writer.WriteCData(text);
}
else
{
writer.WriteString(text);
}
writer.WriteEndElement();
}
}
}
|