@@ -1,198 +1,196 | |||
|
1 | 1 | <?xml version="1.0" encoding="utf-8"?> |
|
2 | 2 | <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
3 | 3 | <PropertyGroup> |
|
4 | 4 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|
5 | 5 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|
6 | 6 | <ProjectGuid>{F550F1F8-8746-4AD0-9614-855F4C4B7F05}</ProjectGuid> |
|
7 | 7 | <OutputType>Library</OutputType> |
|
8 | 8 | <RootNamespace>Implab</RootNamespace> |
|
9 | 9 | <AssemblyName>Implab</AssemblyName> |
|
10 | <ProductVersion>8.0.30703</ProductVersion> | |
|
11 | <SchemaVersion>2.0</SchemaVersion> | |
|
12 | 10 | </PropertyGroup> |
|
13 | 11 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|
14 | 12 | <DebugSymbols>true</DebugSymbols> |
|
15 | 13 | <DebugType>full</DebugType> |
|
16 | 14 | <Optimize>false</Optimize> |
|
17 | 15 | <OutputPath>bin\Debug</OutputPath> |
|
18 | 16 | <DefineConstants>TRACE;DEBUG;</DefineConstants> |
|
19 | 17 | <ErrorReport>prompt</ErrorReport> |
|
20 | 18 | <WarningLevel>4</WarningLevel> |
|
21 | 19 | <ConsolePause>false</ConsolePause> |
|
22 | 20 | <RunCodeAnalysis>true</RunCodeAnalysis> |
|
23 | 21 | </PropertyGroup> |
|
24 | 22 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|
25 | 23 | <DebugType>full</DebugType> |
|
26 | 24 | <Optimize>true</Optimize> |
|
27 | 25 | <OutputPath>bin\Release</OutputPath> |
|
28 | 26 | <ErrorReport>prompt</ErrorReport> |
|
29 | 27 | <WarningLevel>4</WarningLevel> |
|
30 | 28 | <ConsolePause>false</ConsolePause> |
|
31 | 29 | </PropertyGroup> |
|
32 | 30 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 4.5|AnyCPU' "> |
|
33 | 31 | <DebugSymbols>true</DebugSymbols> |
|
34 | 32 | <DebugType>full</DebugType> |
|
35 | 33 | <Optimize>false</Optimize> |
|
36 | 34 | <OutputPath>bin\Debug</OutputPath> |
|
37 | 35 | <DefineConstants>TRACE;DEBUG;NET_4_5</DefineConstants> |
|
38 | 36 | <ErrorReport>prompt</ErrorReport> |
|
39 | 37 | <WarningLevel>4</WarningLevel> |
|
40 | 38 | <RunCodeAnalysis>true</RunCodeAnalysis> |
|
41 | 39 | <ConsolePause>false</ConsolePause> |
|
42 | 40 | </PropertyGroup> |
|
43 | 41 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release 4.5|AnyCPU' "> |
|
44 | 42 | <Optimize>true</Optimize> |
|
45 | 43 | <OutputPath>bin\Release</OutputPath> |
|
46 | 44 | <ErrorReport>prompt</ErrorReport> |
|
47 | 45 | <WarningLevel>4</WarningLevel> |
|
48 | 46 | <ConsolePause>false</ConsolePause> |
|
49 | 47 | <DefineConstants>NET_4_5</DefineConstants> |
|
50 | 48 | </PropertyGroup> |
|
51 | 49 | <ItemGroup> |
|
52 | 50 | <Reference Include="System" /> |
|
53 | 51 | <Reference Include="System.Xml" /> |
|
54 | 52 | </ItemGroup> |
|
55 | 53 | <ItemGroup> |
|
56 | 54 | <Compile Include="Component.cs" /> |
|
57 | 55 | <Compile Include="CustomEqualityComparer.cs" /> |
|
58 | 56 | <Compile Include="Diagnostics\ConsoleTraceListener.cs" /> |
|
59 | 57 | <Compile Include="Diagnostics\EventText.cs" /> |
|
60 | 58 | <Compile Include="Diagnostics\IEventTextFormatter.cs" /> |
|
61 | 59 | <Compile Include="Diagnostics\LogChannel.cs" /> |
|
62 | 60 | <Compile Include="Diagnostics\LogicalOperation.cs" /> |
|
63 | 61 | <Compile Include="Diagnostics\TextFileListener.cs" /> |
|
64 | 62 | <Compile Include="Diagnostics\TextListenerBase.cs" /> |
|
65 | 63 | <Compile Include="Diagnostics\TraceLog.cs" /> |
|
66 | 64 | <Compile Include="Diagnostics\TraceContext.cs" /> |
|
67 | 65 | <Compile Include="Diagnostics\TraceEvent.cs" /> |
|
68 | 66 | <Compile Include="Diagnostics\TraceEventType.cs" /> |
|
69 | 67 | <Compile Include="Disposable.cs" /> |
|
70 | 68 | <Compile Include="ICancellable.cs" /> |
|
71 | 69 | <Compile Include="IProgressHandler.cs" /> |
|
72 | 70 | <Compile Include="IProgressNotifier.cs" /> |
|
73 | 71 | <Compile Include="IPromiseT.cs" /> |
|
74 | 72 | <Compile Include="IPromise.cs" /> |
|
75 | 73 | <Compile Include="IServiceLocator.cs" /> |
|
76 | 74 | <Compile Include="ITaskController.cs" /> |
|
77 | 75 | <Compile Include="JSON\JSONElementContext.cs" /> |
|
78 | 76 | <Compile Include="JSON\JSONElementType.cs" /> |
|
79 | 77 | <Compile Include="JSON\JSONGrammar.cs" /> |
|
80 | 78 | <Compile Include="JSON\JSONParser.cs" /> |
|
81 | 79 | <Compile Include="JSON\JSONScanner.cs" /> |
|
82 | 80 | <Compile Include="JSON\JsonTokenType.cs" /> |
|
83 | 81 | <Compile Include="JSON\JSONWriter.cs" /> |
|
84 | 82 | <Compile Include="JSON\JSONXmlReader.cs" /> |
|
85 | 83 | <Compile Include="JSON\JSONXmlReaderOptions.cs" /> |
|
86 | 84 | <Compile Include="JSON\StringTranslator.cs" /> |
|
87 | 85 | <Compile Include="Parallels\DispatchPool.cs" /> |
|
88 | 86 | <Compile Include="Parallels\ArrayTraits.cs" /> |
|
89 | 87 | <Compile Include="Parallels\MTQueue.cs" /> |
|
90 | 88 | <Compile Include="Parallels\WorkerPool.cs" /> |
|
91 | 89 | <Compile Include="Parsing\Alphabet.cs" /> |
|
92 | 90 | <Compile Include="Parsing\AlphabetBase.cs" /> |
|
93 | 91 | <Compile Include="Parsing\AltToken.cs" /> |
|
94 | 92 | <Compile Include="Parsing\BinaryToken.cs" /> |
|
95 | 93 | <Compile Include="Parsing\CatToken.cs" /> |
|
96 | 94 | <Compile Include="Parsing\CDFADefinition.cs" /> |
|
97 | 95 | <Compile Include="Parsing\DFABuilder.cs" /> |
|
98 | 96 | <Compile Include="Parsing\DFADefinitionBase.cs" /> |
|
99 | 97 | <Compile Include="Parsing\DFAStateDescriptor.cs" /> |
|
100 | 98 | <Compile Include="Parsing\DFAutomaton.cs" /> |
|
101 | 99 | <Compile Include="Parsing\EDFADefinition.cs" /> |
|
102 | 100 | <Compile Include="Parsing\EmptyToken.cs" /> |
|
103 | 101 | <Compile Include="Parsing\EndToken.cs" /> |
|
104 | 102 | <Compile Include="Parsing\EnumAlphabet.cs" /> |
|
105 | 103 | <Compile Include="Parsing\Grammar.cs" /> |
|
106 | 104 | <Compile Include="Parsing\IAlphabet.cs" /> |
|
107 | 105 | <Compile Include="Parsing\IDFADefinition.cs" /> |
|
108 | 106 | <Compile Include="Parsing\IVisitor.cs" /> |
|
109 | 107 | <Compile Include="Parsing\ParserException.cs" /> |
|
110 | 108 | <Compile Include="Parsing\Scanner.cs" /> |
|
111 | 109 | <Compile Include="Parsing\StarToken.cs" /> |
|
112 | 110 | <Compile Include="Parsing\SymbolToken.cs" /> |
|
113 | 111 | <Compile Include="Parsing\Token.cs" /> |
|
114 | 112 | <Compile Include="SafePool.cs" /> |
|
115 | 113 | <Compile Include="ServiceLocator.cs" /> |
|
116 | 114 | <Compile Include="TaskController.cs" /> |
|
117 | 115 | <Compile Include="ProgressInitEventArgs.cs" /> |
|
118 | 116 | <Compile Include="Properties\AssemblyInfo.cs" /> |
|
119 | 117 | <Compile Include="Promise.cs" /> |
|
120 | 118 | <Compile Include="Parallels\AsyncPool.cs" /> |
|
121 | 119 | <Compile Include="Safe.cs" /> |
|
122 | 120 | <Compile Include="ValueEventArgs.cs" /> |
|
123 | 121 | <Compile Include="PromiseExtensions.cs" /> |
|
124 | 122 | <Compile Include="TransientPromiseException.cs" /> |
|
125 | 123 | <Compile Include="SyncContextPromise.cs" /> |
|
126 | 124 | </ItemGroup> |
|
127 | 125 | <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> |
|
128 | 126 | <ItemGroup /> |
|
129 | 127 | <ProjectExtensions> |
|
130 | 128 | <MonoDevelop> |
|
131 | 129 | <Properties> |
|
132 | 130 | <Policies> |
|
133 | 131 | <CSharpFormattingPolicy IndentSwitchBody="True" NamespaceBraceStyle="EndOfLine" ClassBraceStyle="EndOfLine" InterfaceBraceStyle="EndOfLine" StructBraceStyle="EndOfLine" EnumBraceStyle="EndOfLine" MethodBraceStyle="EndOfLine" ConstructorBraceStyle="EndOfLine" DestructorBraceStyle="EndOfLine" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeIndexerDeclarationBracket="False" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" /> |
|
134 | 132 | <TextStylePolicy FileWidth="120" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" /> |
|
135 | 133 | <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedHierarchical" ResourceNamePolicy="MSBuild" /> |
|
136 | 134 | <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="application/xml" /> |
|
137 | 135 | <XmlFormattingPolicy inheritsSet="Mono" inheritsScope="application/xml" scope="application/xml" /> |
|
138 | 136 | <TextStylePolicy FileWidth="120" TabsToSpaces="False" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/plain" /> |
|
139 | 137 | <NameConventionPolicy> |
|
140 | 138 | <Rules> |
|
141 | 139 | <NamingRule Name="Namespaces" AffectedEntity="Namespace" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
142 | 140 | <NamingRule Name="Types" AffectedEntity="Class, Struct, Enum, Delegate" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
143 | 141 | <NamingRule Name="Interfaces" AffectedEntity="Interface" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True"> |
|
144 | 142 | <RequiredPrefixes> |
|
145 | 143 | <String>I</String> |
|
146 | 144 | </RequiredPrefixes> |
|
147 | 145 | </NamingRule> |
|
148 | 146 | <NamingRule Name="Attributes" AffectedEntity="CustomAttributes" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True"> |
|
149 | 147 | <RequiredSuffixes> |
|
150 | 148 | <String>Attribute</String> |
|
151 | 149 | </RequiredSuffixes> |
|
152 | 150 | </NamingRule> |
|
153 | 151 | <NamingRule Name="Event Arguments" AffectedEntity="CustomEventArgs" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True"> |
|
154 | 152 | <RequiredSuffixes> |
|
155 | 153 | <String>EventArgs</String> |
|
156 | 154 | </RequiredSuffixes> |
|
157 | 155 | </NamingRule> |
|
158 | 156 | <NamingRule Name="Exceptions" AffectedEntity="CustomExceptions" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True"> |
|
159 | 157 | <RequiredSuffixes> |
|
160 | 158 | <String>Exception</String> |
|
161 | 159 | </RequiredSuffixes> |
|
162 | 160 | </NamingRule> |
|
163 | 161 | <NamingRule Name="Methods" AffectedEntity="Methods" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
164 | 162 | <NamingRule Name="Static Readonly Fields" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Protected, Public" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True" /> |
|
165 | 163 | <NamingRule Name="Fields (Non Private)" AffectedEntity="Field" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
166 | 164 | <NamingRule Name="ReadOnly Fields (Non Private)" AffectedEntity="ReadonlyField" VisibilityMask="Internal, Public" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False" /> |
|
167 | 165 | <NamingRule Name="Fields (Private)" AffectedEntity="Field, ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False"> |
|
168 | 166 | <RequiredPrefixes> |
|
169 | 167 | <String>m_</String> |
|
170 | 168 | </RequiredPrefixes> |
|
171 | 169 | </NamingRule> |
|
172 | 170 | <NamingRule Name="Static Fields (Private)" AffectedEntity="Field" VisibilityMask="Private" NamingStyle="CamelCase" IncludeInstanceMembers="False" IncludeStaticEntities="True"> |
|
173 | 171 | <RequiredPrefixes> |
|
174 | 172 | <String>_</String> |
|
175 | 173 | </RequiredPrefixes> |
|
176 | 174 | </NamingRule> |
|
177 | 175 | <NamingRule Name="ReadOnly Fields (Private)" AffectedEntity="ReadonlyField" VisibilityMask="Private, Protected" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="False"> |
|
178 | 176 | <RequiredPrefixes> |
|
179 | 177 | <String>m_</String> |
|
180 | 178 | </RequiredPrefixes> |
|
181 | 179 | </NamingRule> |
|
182 | 180 | <NamingRule Name="Constant Fields" AffectedEntity="ConstantField" VisibilityMask="VisibilityMask" NamingStyle="AllUpper" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
183 | 181 | <NamingRule Name="Properties" AffectedEntity="Property" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
184 | 182 | <NamingRule Name="Events" AffectedEntity="Event" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
185 | 183 | <NamingRule Name="Enum Members" AffectedEntity="EnumMember" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
186 | 184 | <NamingRule Name="Parameters" AffectedEntity="Parameter, LocalVariable" VisibilityMask="VisibilityMask" NamingStyle="CamelCase" IncludeInstanceMembers="True" IncludeStaticEntities="True" /> |
|
187 | 185 | <NamingRule Name="Type Parameters" AffectedEntity="TypeParameter" VisibilityMask="VisibilityMask" NamingStyle="PascalCase" IncludeInstanceMembers="True" IncludeStaticEntities="True"> |
|
188 | 186 | <RequiredPrefixes> |
|
189 | 187 | <String>T</String> |
|
190 | 188 | </RequiredPrefixes> |
|
191 | 189 | </NamingRule> |
|
192 | 190 | </Rules> |
|
193 | 191 | </NameConventionPolicy> |
|
194 | 192 | </Policies> |
|
195 | 193 | </Properties> |
|
196 | 194 | </MonoDevelop> |
|
197 | 195 | </ProjectExtensions> |
|
198 | 196 | </Project> No newline at end of file |
@@ -1,324 +1,324 | |||
|
1 | 1 | using Implab; |
|
2 | 2 | using Implab.Parsing; |
|
3 | 3 | using System; |
|
4 | 4 | using System.Collections.Generic; |
|
5 | 5 | using System.Globalization; |
|
6 | 6 | using System.IO; |
|
7 | 7 | using System.Linq; |
|
8 | 8 | using System.Text; |
|
9 | 9 | using System.Threading.Tasks; |
|
10 | 10 | using System.Xml; |
|
11 | 11 | |
|
12 | 12 | namespace Implab.JSON { |
|
13 | 13 | public class JSONXmlReader : XmlReader { |
|
14 | 14 | |
|
15 | 15 | enum ValueContext { |
|
16 | 16 | Undefined, |
|
17 | 17 | ElementStart, |
|
18 | 18 | ElementValue, |
|
19 | 19 | ElementEnd, |
|
20 | 20 | ElementEmpty |
|
21 | 21 | } |
|
22 | 22 | |
|
23 | 23 | struct LocalNameContext { |
|
24 | 24 | public string localName; |
|
25 | 25 | public bool isArray; |
|
26 | 26 | } |
|
27 | 27 | |
|
28 | 28 | JSONParser m_parser; |
|
29 | 29 | ValueContext m_valueContext; |
|
30 | 30 | ReadState m_state = ReadState.Initial; |
|
31 | 31 | Stack<LocalNameContext> m_localNameStack = new Stack<LocalNameContext>(); |
|
32 | 32 | LocalNameContext m_localName; |
|
33 | 33 | int m_depthCorrection = 0; |
|
34 | 34 | |
|
35 | 35 | readonly string m_rootName; |
|
36 | 36 | readonly string m_prefix; |
|
37 | 37 | readonly string m_namespaceUri; |
|
38 | 38 | readonly bool m_flattenArrays; |
|
39 | 39 | readonly string m_arrayItemName; |
|
40 | 40 | readonly XmlNameTable m_nameTable; |
|
41 | 41 | |
|
42 | 42 | JSONXmlReader(JSONParser parser, JSONXmlReaderOptions options) { |
|
43 | 43 | m_parser = parser; |
|
44 | 44 | |
|
45 | 45 | if (options != null) { |
|
46 | 46 | m_prefix = options.NodesPrefix ?? String.Empty; |
|
47 | 47 | m_namespaceUri = options.NamespaceURI ?? String.Empty; |
|
48 | 48 | m_rootName = options.RootName ?? "json"; |
|
49 | 49 | m_flattenArrays = options.FlattenArrays; |
|
50 | 50 | m_arrayItemName = options.ArrayItemName ?? "item"; |
|
51 | 51 | m_nameTable = options.NameTable ?? new NameTable(); |
|
52 | 52 | } else { |
|
53 | 53 | m_prefix = String.Empty; |
|
54 | 54 | m_namespaceUri = String.Empty; |
|
55 | 55 | m_rootName = "json"; |
|
56 | 56 | m_flattenArrays = false; |
|
57 | 57 | m_arrayItemName = "item"; |
|
58 | 58 | m_nameTable = new NameTable(); |
|
59 | 59 | } |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | 62 | /// <summary> |
|
63 | 63 | /// Always 0, JSON doesn't support attributes |
|
64 | 64 | /// </summary> |
|
65 | 65 | public override int AttributeCount { |
|
66 | 66 | get { return 0; } |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | public override string BaseURI { |
|
70 | 70 | get { return String.Empty; } |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | public override int Depth { |
|
74 | 74 | get { |
|
75 | 75 | return m_localNameStack.Count + m_depthCorrection; |
|
76 | 76 | } |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | public override bool EOF { |
|
80 | 80 | get { return m_parser.EOF; } |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | /// <summary> |
|
84 | 84 | /// Always throws an exception |
|
85 | 85 | /// </summary> |
|
86 | 86 | /// <param name="i"></param> |
|
87 | 87 | /// <returns></returns> |
|
88 | 88 | public override string GetAttribute(int i) { |
|
89 | 89 | throw new ArgumentOutOfRangeException(); |
|
90 | 90 | } |
|
91 | 91 | |
|
92 | 92 | /// <summary> |
|
93 | 93 | /// Always returns empty string |
|
94 | 94 | /// </summary> |
|
95 | 95 | /// <param name="name"></param> |
|
96 | 96 | /// <param name="namespaceURI"></param> |
|
97 | 97 | /// <returns></returns> |
|
98 | 98 | public override string GetAttribute(string name, string namespaceURI) { |
|
99 | 99 | return String.Empty; |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | /// <summary> |
|
103 | 103 | /// Always returns empty string |
|
104 | 104 | /// </summary> |
|
105 | 105 | /// <param name="name"></param> |
|
106 | 106 | /// <returns></returns> |
|
107 | 107 | public override string GetAttribute(string name) { |
|
108 | 108 | return String.Empty; |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | public override bool IsEmptyElement { |
|
112 | 112 | get { return m_parser.ElementType == JSONElementType.Value && m_valueContext == ValueContext.ElementEmpty; } |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | public override string LocalName { |
|
116 | 116 | get { return m_localName.localName; } |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | public override string LookupNamespace(string prefix) { |
|
120 | 120 | if (String.IsNullOrEmpty(prefix) || prefix == m_prefix) |
|
121 | 121 | return m_namespaceUri; |
|
122 | 122 | else |
|
123 | 123 | return String.Empty; |
|
124 | 124 | } |
|
125 | 125 | |
|
126 | 126 | public override bool MoveToAttribute(string name, string ns) { |
|
127 | 127 | return false; |
|
128 | 128 | } |
|
129 | 129 | |
|
130 | 130 | public override bool MoveToAttribute(string name) { |
|
131 | 131 | return false; |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | public override bool MoveToElement() { |
|
135 | 135 | return false; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | public override bool MoveToFirstAttribute() { |
|
139 | 139 | return false; |
|
140 | 140 | } |
|
141 | 141 | |
|
142 | 142 | public override bool MoveToNextAttribute() { |
|
143 | 143 | return false; |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | public override XmlNameTable NameTable { |
|
147 | 147 | get { return m_nameTable; } |
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | public override string NamespaceURI { |
|
151 | 151 | get { return m_namespaceUri; } |
|
152 | 152 | } |
|
153 | 153 | |
|
154 | 154 | public override XmlNodeType NodeType { |
|
155 | 155 | get { |
|
156 | 156 | switch (m_parser.ElementType) { |
|
157 | 157 | case JSONElementType.BeginObject: |
|
158 | 158 | case JSONElementType.BeginArray: |
|
159 | 159 | return XmlNodeType.Element; |
|
160 | 160 | case JSONElementType.EndObject: |
|
161 | 161 | case JSONElementType.EndArray: |
|
162 | 162 | return XmlNodeType.EndElement; |
|
163 | 163 | case JSONElementType.Value: |
|
164 | 164 | switch (m_valueContext) { |
|
165 | 165 | case ValueContext.ElementStart: |
|
166 | 166 | case ValueContext.ElementEmpty: |
|
167 | 167 | return XmlNodeType.Element; |
|
168 | 168 | case ValueContext.ElementValue: |
|
169 | 169 | return XmlNodeType.Text; |
|
170 | 170 | case ValueContext.ElementEnd: |
|
171 | 171 | return XmlNodeType.EndElement; |
|
172 | 172 | default: |
|
173 | 173 | throw new InvalidOperationException(); |
|
174 | 174 | } |
|
175 | 175 | default: |
|
176 | 176 | throw new InvalidOperationException(); |
|
177 | 177 | } |
|
178 | 178 | } |
|
179 | 179 | } |
|
180 | 180 | |
|
181 | 181 | public override string Prefix { |
|
182 | 182 | get { return m_prefix; } |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | public override bool Read() { |
|
186 | 186 | if (m_state != System.Xml.ReadState.Interactive && m_state != System.Xml.ReadState.Initial) |
|
187 | 187 | return false; |
|
188 | 188 | |
|
189 | 189 | if (m_state == ReadState.Initial) |
|
190 | 190 | m_state = System.Xml.ReadState.Interactive; |
|
191 | 191 | |
|
192 | 192 | try { |
|
193 | 193 | switch (m_parser.ElementType) { |
|
194 | 194 | case JSONElementType.Value: |
|
195 | 195 | switch (m_valueContext) { |
|
196 | 196 | case ValueContext.ElementStart: |
|
197 | 197 | SetLocalName(String.Empty); |
|
198 | 198 | m_valueContext = ValueContext.ElementValue; |
|
199 | 199 | return true; |
|
200 | 200 | case ValueContext.ElementValue: |
|
201 | 201 | RestoreLocalName(); |
|
202 | 202 | m_valueContext = ValueContext.ElementEnd; |
|
203 | 203 | return true; |
|
204 | 204 | case ValueContext.ElementEmpty: |
|
205 | 205 | case ValueContext.ElementEnd: |
|
206 | 206 | RestoreLocalName(); |
|
207 | 207 | break; |
|
208 | 208 | } |
|
209 | 209 | break; |
|
210 | 210 | case JSONElementType.EndArray: |
|
211 | 211 | case JSONElementType.EndObject: |
|
212 | 212 | RestoreLocalName(); |
|
213 | 213 | break; |
|
214 | 214 | } |
|
215 | 215 | string itemName = m_parser.ElementType == JSONElementType.None ? m_rootName : m_flattenArrays ? m_localName.localName : m_arrayItemName; |
|
216 | 216 | while (m_parser.Read()) { |
|
217 | 217 | if (!String.IsNullOrEmpty(m_parser.ElementName)) |
|
218 | 218 | itemName = m_parser.ElementName; |
|
219 | 219 | |
|
220 | 220 | switch (m_parser.ElementType) { |
|
221 | 221 | case JSONElementType.BeginArray: |
|
222 | 222 | if (m_flattenArrays && !m_localName.isArray) { |
|
223 | 223 | m_depthCorrection--; |
|
224 | 224 | SetLocalName(itemName, true); |
|
225 | 225 | continue; |
|
226 | 226 | } else { |
|
227 | 227 | SetLocalName(itemName, true); |
|
228 | 228 | } |
|
229 | 229 | break; |
|
230 | 230 | case JSONElementType.BeginObject: |
|
231 | 231 | SetLocalName(itemName); |
|
232 | 232 | break; |
|
233 | 233 | case JSONElementType.EndArray: |
|
234 | 234 | if (m_flattenArrays && !m_localNameStack.Peek().isArray) { |
|
235 | 235 | RestoreLocalName(); |
|
236 | 236 | m_depthCorrection++; |
|
237 | 237 | continue; |
|
238 | 238 | } |
|
239 | 239 | break; |
|
240 | 240 | case JSONElementType.EndObject: |
|
241 | 241 | break; |
|
242 | 242 | case JSONElementType.Value: |
|
243 | 243 | SetLocalName(itemName); |
|
244 | 244 | m_valueContext = m_parser.ElementValue == null ? ValueContext.ElementEmpty : ValueContext.ElementStart; |
|
245 | 245 | break; |
|
246 | 246 | default: |
|
247 | 247 | break; |
|
248 | 248 | } |
|
249 | 249 | return true; |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | m_state = System.Xml.ReadState.EndOfFile; |
|
253 | 253 | return false; |
|
254 | 254 | } catch { |
|
255 | 255 | m_state = System.Xml.ReadState.Error; |
|
256 | 256 | throw; |
|
257 | 257 | } |
|
258 | 258 | } |
|
259 | 259 | |
|
260 | 260 | public override bool ReadAttributeValue() { |
|
261 | 261 | return false; |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | public override ReadState ReadState { |
|
265 | 265 | get { return m_state; } |
|
266 | 266 | } |
|
267 | 267 | |
|
268 | 268 | public override void ResolveEntity() { |
|
269 | 269 | // do nothing |
|
270 | 270 | } |
|
271 | 271 | |
|
272 | 272 | public override string Value { |
|
273 | 273 | get { |
|
274 | 274 | if (m_parser.ElementValue == null) |
|
275 | 275 | return String.Empty; |
|
276 | 276 | if (Convert.GetTypeCode(m_parser.ElementValue) == TypeCode.Double) |
|
277 | 277 | return ((double)m_parser.ElementValue).ToString(CultureInfo.InvariantCulture); |
|
278 | 278 | else |
|
279 |
return |
|
|
279 | return m_parser.ElementValue.ToString(); | |
|
280 | 280 | } |
|
281 | 281 | } |
|
282 | 282 | |
|
283 | 283 | void SetLocalName(string name) { |
|
284 | 284 | m_localNameStack.Push(m_localName); |
|
285 | 285 | m_localName.localName = name; |
|
286 | 286 | m_localName.isArray = false; |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | void SetLocalName(string name, bool isArray) { |
|
290 | 290 | m_localNameStack.Push(m_localName); |
|
291 | 291 | m_localName.localName = name; |
|
292 | 292 | m_localName.isArray = isArray; |
|
293 | 293 | } |
|
294 | 294 | |
|
295 | 295 | void RestoreLocalName() { |
|
296 | 296 | m_localName = m_localNameStack.Pop(); |
|
297 | 297 | } |
|
298 | 298 | |
|
299 | 299 | public override void Close() { |
|
300 | 300 | |
|
301 | 301 | } |
|
302 | 302 | |
|
303 | 303 | protected override void Dispose(bool disposing) { |
|
304 | 304 | if (disposing) { |
|
305 | 305 | m_parser.Dispose(); |
|
306 | 306 | } |
|
307 | 307 | base.Dispose(disposing); |
|
308 | 308 | } |
|
309 | 309 | |
|
310 | 310 | public static JSONXmlReader Create(string file, JSONXmlReaderOptions options) { |
|
311 | 311 | return Create(File.OpenText(file), options); |
|
312 | 312 | } |
|
313 | 313 | |
|
314 | 314 | public static JSONXmlReader Create(TextReader reader, JSONXmlReaderOptions options) { |
|
315 | 315 | return new JSONXmlReader(new JSONParser(reader, true), options); |
|
316 | 316 | } |
|
317 | 317 | |
|
318 | 318 | public static JSONXmlReader Create(Stream stream, JSONXmlReaderOptions options) { |
|
319 | 319 | Safe.ArgumentNotNull(stream, "stream"); |
|
320 | 320 | // HACK don't dispose StreaReader to keep stream opened |
|
321 | 321 | return Create(new StreamReader(stream), options); |
|
322 | 322 | } |
|
323 | 323 | } |
|
324 | 324 | } |
General Comments 0
You need to be logged in to leave comments.
Login now