Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Commit

Permalink
Update the JsonDeserializer
Browse files Browse the repository at this point in the history
1. Update LockFileFormat to use JsonDeserializer
2. Also remove all references to Newtonsoft.Json from Microsoft.Framework.Runtime
3. Accept a TextReader instead of stream;
4. Trim down unnecessary code which includes UTF16 validator, number parsing.
5. Rename JsonContent to JsonBuffer
6. JsonBuffer read word instead of charactor
  • Loading branch information
troydai committed May 11, 2015
1 parent 8e39eb1 commit e0c2629
Show file tree
Hide file tree
Showing 36 changed files with 1,142 additions and 1,644 deletions.
44 changes: 22 additions & 22 deletions DNX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dnx.host.Tests", "test\dnx.
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NuGet.RuntimeModel", "submodules\NuGet.Packaging\src\NuGet.RuntimeModel\NuGet.RuntimeModel.xproj", "{79FA1E82-C09B-4F6E-B4E0-CF0F8AE5D365}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.Logging.Abstractions", "submodules\Logging\src\Microsoft.Framework.Logging.Abstractions\Microsoft.Framework.Logging.Abstractions.xproj", "{1D2CCF13-A935-4017-899C-E3B8A313C3B5}"
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.Logging.Abstractions", "submodules\Logging\src\Microsoft.Framework.Logging.Abstractions\Microsoft.Framework.Logging.Abstractions.xproj", "{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -1092,26 +1092,26 @@ Global
{79FA1E82-C09B-4F6E-B4E0-CF0F8AE5D365}.Release|x64.Build.0 = Release|Any CPU
{79FA1E82-C09B-4F6E-B4E0-CF0F8AE5D365}.Release|x86.ActiveCfg = Release|Any CPU
{79FA1E82-C09B-4F6E-B4E0-CF0F8AE5D365}.Release|x86.Build.0 = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Win32.ActiveCfg = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|Win32.Build.0 = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|x64.ActiveCfg = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|x64.Build.0 = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|x86.ActiveCfg = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Debug|x86.Build.0 = Debug|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Any CPU.Build.0 = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Win32.ActiveCfg = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|Win32.Build.0 = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|x64.ActiveCfg = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|x64.Build.0 = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|x86.ActiveCfg = Release|Any CPU
{1D2CCF13-A935-4017-899C-E3B8A313C3B5}.Release|x86.Build.0 = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Win32.ActiveCfg = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|Win32.Build.0 = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|x64.ActiveCfg = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|x64.Build.0 = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|x86.ActiveCfg = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Debug|x86.Build.0 = Debug|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Any CPU.Build.0 = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Win32.ActiveCfg = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|Win32.Build.0 = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|x64.ActiveCfg = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|x64.Build.0 = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|x86.ActiveCfg = Release|Any CPU
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1178,6 +1178,6 @@ Global
{19D39312-A4A4-449D-B53F-653F951A11F8} = {AF391791-F4B7-41AC-8F08-9485DAC543C5}
{6F59A0B7-745D-4ADA-A913-6A1AD1AB49C2} = {C43EE429-DE10-4906-BB09-54E6A080948A}
{79FA1E82-C09B-4F6E-B4E0-CF0F8AE5D365} = {CAF3AE3C-D013-43E7-9AFD-AC6956B2999F}
{1D2CCF13-A935-4017-899C-E3B8A313C3B5} = {51FFE388-588D-4ED1-8B35-54D0E5852CA8}
{8221FA95-4B1A-44BF-925F-8AC1A317CC7C} = {51FFE388-588D-4ED1-8B35-54D0E5852CA8}
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion src/Microsoft.Framework.PackageManager/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Microsoft.Framework.Runtime": "1.0.0-*",
"Microsoft.Framework.Runtime.Compilation.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.Runtime.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*"
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*",
"Newtonsoft.Json": "6.0.6"
},
"compile": "..\\Microsoft.Framework.ApplicationHost\\Impl\\**\\*.cs",

Expand Down
14 changes: 7 additions & 7 deletions src/Microsoft.Framework.Runtime.Hosting/FileFormatException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal static FileFormatException Create(Exception exception, JsonValue jsonVa
{
var result = new FileFormatException(exception.Message, exception)
.WithFilePath(filePath)
.WithLineInfo(jsonValue.Position);
.WithLineInfo(jsonValue);

return result;
}
Expand All @@ -58,20 +58,20 @@ internal static FileFormatException Create(string message, JsonValue jsonValue,
{
var result = new FileFormatException(message)
.WithFilePath(filePath)
.WithLineInfo(jsonValue.Position);
.WithLineInfo(jsonValue);

return result;
}

private FileFormatException WithLineInfo(JsonPosition position)
private FileFormatException WithLineInfo(JsonValue value)
{
if (position == null)
if (value == null)
{
throw new ArgumentNullException(nameof(position));
throw new ArgumentNullException(nameof(value));
}

Line = position.Line;
Column = position.Column;
Line = value.Line;
Column = value.Column;

return this;
}
Expand Down
13 changes: 5 additions & 8 deletions src/Microsoft.Framework.Runtime.Hosting/FileFormatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Framework.Runtime.Json;

namespace Microsoft.Framework.Runtime
{
Expand All @@ -20,20 +19,18 @@ public FileFormatMessage(string message,
Severity = severity;
}

public FileFormatMessage(string message,
internal FileFormatMessage(string message,
string projectFilePath,
CompilationMessageSeverity severity,
JToken token)
JsonValue jsonValue)
{
Message = message;
SourceFilePath = projectFilePath;
Severity = severity;

var lineInfo = (IJsonLineInfo)token;

StartColumn = lineInfo.LinePosition;
StartColumn = jsonValue.Column;
EndColumn = StartColumn;
StartLine = lineInfo.LineNumber;
StartLine = jsonValue.Line;
EndLine = StartLine;
}

Expand Down
12 changes: 3 additions & 9 deletions src/Microsoft.Framework.Runtime.Hosting/Json/JsonArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;

namespace Microsoft.Framework.Runtime.Json
{
internal class JsonArray : JsonValue
{
private readonly JsonValue[] _array;

public JsonArray(JsonValue[] array, JsonPosition position)
: base(position)
public JsonArray(JsonValue[] array, int line, int column)
: base(line, column)
{
if (array == null)
{
Expand All @@ -21,7 +20,7 @@ public JsonArray(JsonValue[] array, JsonPosition position)
_array = array;
}

public int Count
public int Length
{
get { return _array.Length; }
}
Expand All @@ -30,10 +29,5 @@ public JsonValue this[int index]
{
get { return _array[index]; }
}

public T[] Cast<T>() where T : JsonValue
{
return _array.Select(element => element as T).ToArray();
}
}
}
34 changes: 34 additions & 0 deletions src/Microsoft.Framework.Runtime.Hosting/Json/JsonBoolean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.Framework.Runtime.Json
{
internal class JsonBoolean : JsonValue
{
public JsonBoolean(JsonToken token)
: base(token.Line, token.Column)
{
if (token.Type == JsonTokenType.True)
{
Value = true;
}
else if (token.Type == JsonTokenType.False)
{
Value = false;
}
else
{
throw new ArgumentException("Token value should be either True or False.", nameof(token));
}
}

public bool Value { get; private set; }

public static implicit operator bool (JsonBoolean jsonBoolean)
{
return jsonBoolean.Value;
}
}
}
Loading

0 comments on commit e0c2629

Please sign in to comment.