-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhidden-data-extended-data.patch
More file actions
218 lines (213 loc) · 8.37 KB
/
hidden-data-extended-data.patch
File metadata and controls
218 lines (213 loc) · 8.37 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
Index: SharpKml.Kmz/SharpKml.Kmz.csproj
===================================================================
--- SharpKml.Kmz/SharpKml.Kmz.csproj (revision 44542)
+++ SharpKml.Kmz/SharpKml.Kmz.csproj (working copy)
@@ -38,9 +38,8 @@
<AssemblyOriginatorKeyFile>../SharpKml.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Ionic.Zip.Reduced, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
+ <Reference Include="Ionic.Zip.Reduced">
<HintPath>..\packages\DotNetZip.Reduced.1.9.1.8\lib\net20\Ionic.Zip.Reduced.dll</HintPath>
- <Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.XML" />
@@ -51,14 +50,14 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
+ <ItemGroup>
<ProjectReference Include="..\SharpKml\SharpKml.Core.csproj">
<Project>{ba1c2e65-51f6-4960-bd72-26e3b95d38d6}</Project>
<Name>SharpKml.Core</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Index: SharpKml/Base/KmlNamespaces.cs
===================================================================
--- SharpKml/Base/KmlNamespaces.cs (revision 44542)
+++ SharpKml/Base/KmlNamespaces.cs (working copy)
@@ -127,6 +127,9 @@
/// <summary>Represents the default XML Schema prefix.</summary>
public const string XsiPrefix = "xsi";
+ public const string SharpKmlPrefix = "sharpkml";
+ public const string SharpKmlNamespace = "http://sharpkml.codeplex.com";
+
private static readonly Dictionary<string, string> Namespaces = GenerateNamespaces();
/// <summary>Searches for the associated XML namespace for the specified prefix.</summary>
Index: SharpKml/Dom/Features/Data.cs
===================================================================
--- SharpKml/Dom/Features/Data.cs (revision 44542)
+++ SharpKml/Dom/Features/Data.cs (working copy)
@@ -30,4 +30,22 @@
[KmlElement("value", 2)]
public string Value { get; set; }
}
+ [KmlElement(KmlNamespaces.SharpKmlPrefix + ":HiddenData", KmlNamespaces.SharpKmlNamespace)]
+ public sealed class HiddenData : KmlObject
+ {
+ /// <summary>Gets or sets an alternate display name.</summary>
+ [KmlElement("displayName", 1)]
+ public string DisplayName { get; set; }
+
+ /// <summary>Gets or sets the name of the data pair.</summary>
+ /// <remarks>
+ /// The value shall be unique within the context of its <see cref="Element.Parent"/>.
+ /// </remarks>
+ [KmlAttribute("name")]
+ public string Name { get; set; }
+
+ /// <summary>Gets or sets the value of the data pair.</summary>
+ [KmlElement("value", 2)]
+ public string Value { get; set; }
+ }
}
Index: SharpKml/Dom/Features/ExtendedData.cs
===================================================================
--- SharpKml/Dom/Features/ExtendedData.cs (revision 44542)
+++ SharpKml/Dom/Features/ExtendedData.cs (working copy)
@@ -25,6 +25,8 @@
{
this.RegisterValidChild<Data>();
this.RegisterValidChild<SchemaData>();
+ this.RegisterValidChild<HiddenData>();
+ this.Namespaces.AddNamespace("sharpkml", "http://sharpkml.codeplex.com");
}
/// <summary>
@@ -43,6 +45,12 @@
get { return this.Children.OfType<SchemaData>(); }
}
+ public IEnumerable<HiddenData> HiddenData
+ {
+ get { return this.Children.OfType<HiddenData>(); }
+ }
+
+
/// <summary>
/// Adds the specified <see cref="Data"/> to this instance.
/// </summary>
@@ -56,17 +64,22 @@
this.AddChild(data);
}
- /// <summary>
- /// Adds the specified <see cref="SchemaData"/> to this instance.
- /// </summary>
- /// <param name="data">The <c>SchemaData</c> to add to this instance.</param>
- /// <exception cref="System.ArgumentNullException">data is null.</exception>
- /// <exception cref="System.InvalidOperationException">
- /// data belongs to another <see cref="Element"/>.
- /// </exception>
- public void AddSchemaData(SchemaData data)
+ public void AddHiddenData(HiddenData data)
{
this.AddChild(data);
}
+
+ /// <summary>
+ /// Adds the specified <see cref="SchemaData"/> to this instance.
+ /// </summary>
+ /// <param name="data">The <c>SchemaData</c> to add to this instance.</param>
+ /// <exception cref="System.ArgumentNullException">data is null.</exception>
+ /// <exception cref="System.InvalidOperationException">
+ /// data belongs to another <see cref="Element"/>.
+ /// </exception>
+ public void AddSchemaData(SchemaData data)
+ {
+ this.AddChild(data);
+ }
}
}
Index: SharpKml/SharpKml.Core.csproj
===================================================================
--- SharpKml/SharpKml.Core.csproj (revision 44542)
+++ SharpKml/SharpKml.Core.csproj (working copy)
@@ -59,6 +59,7 @@
<Compile Include="Base\TypeBrowser.cs" />
<Compile Include="Base\ValueConverter.cs" />
<Compile Include="Base\Vector.cs" />
+ <Compile Include="Base\WebUtility.cs" />
<Compile Include="Base\XmlComponent.cs" />
<Compile Include="Base\XmlExtractor.cs" />
<Compile Include="Dom\Atom\Author.cs" />
@@ -193,6 +194,7 @@
<Compile Include="Engine\FeatureExtensions.cs" />
<Compile Include="Engine\GeometryExtensions.cs" />
<Compile Include="Engine\IFileResolver.cs" />
+ <Compile Include="Engine\IKmlCache.cs" />
<Compile Include="Engine\KmlFile.cs" />
<Compile Include="Engine\LinkResolver.cs" />
<Compile Include="Engine\StyleResolver.cs" />
Index: UnitTests/Engine/HiddenDataTests.cs
===================================================================
--- UnitTests/Engine/HiddenDataTests.cs (nonexistent)
+++ UnitTests/Engine/HiddenDataTests.cs (working copy)
@@ -0,0 +1,49 @@
+using System;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using SharpKml.Dom;
+using SharpKml.Engine;
+
+namespace NUintTests.Engine
+{
+ [TestFixture]
+ public class ExtendedDataTest
+ {
+ [Test]
+ public void CanSaveAndRestoreHiddenData()
+ {
+ var placemark = new Placemark { Name = "TestPlacemark" };
+
+ placemark.ExtendedData = new ExtendedData();
+ placemark.ExtendedData.AddHiddenData(new HiddenData { Name = "HIDDEN_KEY", Value = "A VALUE" });
+
+ var buffer = new byte[2048];
+ using (var ms = new MemoryStream(buffer))
+ {
+ KmlFile.Create(placemark, false).Save(ms);
+ ms.Flush();
+
+ using (var reader = new StreamReader(new MemoryStream(buffer)))
+ {
+ Console.WriteLine(reader.ReadToEnd());
+ }
+
+ using (var ms2 = new MemoryStream(buffer))
+ {
+ var kmlFile = KmlFile.Load(ms2);
+
+ Assert.That(kmlFile.Root, Is.InstanceOf<Placemark>());
+ var placemarkCopy = kmlFile.Root as Placemark;
+
+ Assert.That(placemarkCopy.ExtendedData.HiddenData.Any(), Is.True);
+
+ var hidden = placemarkCopy.ExtendedData.HiddenData.First(h => h.Name == "HIDDEN_KEY");
+
+ Assert.That(hidden, Is.Not.Null);
+ }
+
+ }
+ }
+ }
+}
Index: UnitTests/UnitTests.csproj
===================================================================
--- UnitTests/UnitTests.csproj (revision 44542)
+++ UnitTests/UnitTests.csproj (working copy)
@@ -74,6 +74,7 @@
<Compile Include="Engine\ElementExtensionsTest.cs" />
<Compile Include="Engine\EntityMapperTest.cs" />
<Compile Include="Engine\FeatureExtensionsTest.cs" />
+ <Compile Include="Engine\HiddenDataTests.cs" />
<Compile Include="Engine\KmlFileTest.cs" />
<Compile Include="Engine\KmzFileTest.cs" />
<Compile Include="Engine\LinkResolverTest.cs" />