diff --git a/.gitignore b/.gitignore index 79b7233..a608ac4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ src/DotNetClient/DotNetClient/bin src/DotNetClient/DotNetClient/obj src/DotNetClient/TestWondeClient/bin src/DotNetClient/TestWondeClient/obj +src/DotNetClient/Tests/bin +src/DotNetClient/Tests/obj +src/DotNetClient/packages +src/DotNetClient/.vs +src/DotNetClient/.idea diff --git a/src/DotNetClient/DotNetClient/Properties/AssemblyInfo.cs b/src/DotNetClient/DotNetClient/Properties/AssemblyInfo.cs index 13b1d69..eaaf89c 100644 --- a/src/DotNetClient/DotNetClient/Properties/AssemblyInfo.cs +++ b/src/DotNetClient/DotNetClient/Properties/AssemblyInfo.cs @@ -5,12 +5,6 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("Wonde.NET")] -[assembly: AssemblyDescription("Wonde Schools API .Net Client Library 1.0.3")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Wonde Ltd")] -[assembly: AssemblyProduct("Wonde.NET")] -[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible @@ -20,16 +14,3 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("14ef1cdd-1d99-4078-ab11-1207e859c63c")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.3.0")] -[assembly: AssemblyFileVersion("1.0.3.0")] diff --git a/src/DotNetClient/DotNetClient/Wonde.NET.csproj b/src/DotNetClient/DotNetClient/Wonde.NET.csproj index f9d22ac..ef0a4d8 100644 --- a/src/DotNetClient/DotNetClient/Wonde.NET.csproj +++ b/src/DotNetClient/DotNetClient/Wonde.NET.csproj @@ -1,113 +1,19 @@  - - + + - Debug - AnyCPU - {14EF1CDD-1D99-4078-AB11-1207E859C63C} + netstandard2.0 Library - Properties Wonde Wonde.NET - v4.6.1 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - false + 8 + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - \ No newline at end of file + + diff --git a/src/DotNetClient/DotNetClient/Wonde/EndPoints/BootstrapEndpoint.cs b/src/DotNetClient/DotNetClient/Wonde/EndPoints/BootstrapEndpoint.cs index 6007301..a41b082 100644 --- a/src/DotNetClient/DotNetClient/Wonde/EndPoints/BootstrapEndpoint.cs +++ b/src/DotNetClient/DotNetClient/Wonde/EndPoints/BootstrapEndpoint.cs @@ -1,14 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; - -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; using Wonde.Exceptions; using Wonde.Helpers; using Wonde.Helpers.Exceptions; diff --git a/src/DotNetClient/DotNetClient/Wonde/EndPoints/Schools.cs b/src/DotNetClient/DotNetClient/Wonde/EndPoints/Schools.cs index 64e716d..71910e6 100644 --- a/src/DotNetClient/DotNetClient/Wonde/EndPoints/Schools.cs +++ b/src/DotNetClient/DotNetClient/Wonde/EndPoints/Schools.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Wonde.EndPoints { diff --git a/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonDictionaryConverter.cs b/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonDictionaryConverter.cs new file mode 100644 index 0000000..3fd5c1a --- /dev/null +++ b/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonDictionaryConverter.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Wonde.Helpers +{ + internal class JsonDictionaryConverter : JsonConverter> + { + public override Dictionary Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var dict = new Dictionary(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndObject) + { + return dict; + } + + string key = reader.GetString(); + reader.Read(); // Move to value + + object value; + + // Handle different JSON value types + if (reader.TokenType == JsonTokenType.StartObject) + { + // Recursively handle nested objects + value = Read(ref reader, typeToConvert, options); + } + else if (reader.TokenType == JsonTokenType.StartArray) + { + // Handle arrays + value = ReadArray(ref reader, options); + } + else + { + // Read primitive values and convert them to appropriate types + value = ReadPrimitive(ref reader); + } + + dict[key] = value; + } + + return dict; + } + + private object ReadPrimitive(ref Utf8JsonReader reader) + { + // Handle primitive types + return reader.TokenType switch + { + JsonTokenType.String => reader.GetString(), + JsonTokenType.Number => reader.GetDouble(), // Use GetInt32 or GetInt64 as needed + JsonTokenType.True => true, + JsonTokenType.False => false, + JsonTokenType.Null => null, + _ => throw new JsonException($"Unexpected token type: {reader.TokenType}") + }; + } + + private List ReadArray(ref Utf8JsonReader reader, JsonSerializerOptions options) + { + var list = new List(); + + while (reader.Read()) + { + if (reader.TokenType == JsonTokenType.EndArray) + { + return list; + } + + if (reader.TokenType == JsonTokenType.StartObject) + { + list.Add(Read(ref reader, typeof(Dictionary), options)); + } + else + { + list.Add(ReadPrimitive(ref reader)); + } + } + + return list; + } + + public override void Write(Utf8JsonWriter writer, Dictionary value, JsonSerializerOptions options) + { + writer.WriteStartObject(); + foreach (var kvp in value) + { + writer.WritePropertyName(kvp.Key); + JsonSerializer.Serialize(writer, kvp.Value, options); + } + writer.WriteEndObject(); + } + } +} \ No newline at end of file diff --git a/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonSerializeHelper.cs b/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonSerializeHelper.cs index 508f2e1..357d22b 100644 --- a/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonSerializeHelper.cs +++ b/src/DotNetClient/DotNetClient/Wonde/Helpers/JsonSerializeHelper.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Web.Script.Serialization; +using System.Collections.Generic; +using System.Text.Json; using System.Web; @@ -14,6 +10,9 @@ namespace Wonde.Helpers /// internal class StringHelper { + private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions + { Converters = { new JsonDictionaryConverter() } }; + /// /// Converts a Json string into Key/Value pair representation of Dictionary object /// @@ -21,11 +20,10 @@ internal class StringHelper /// Json data decoded as Key/Value pair representation of Dictionary object internal static Dictionary getJsonAsDictionary(string jsonString) { - JavaScriptSerializer ser = new JavaScriptSerializer(); - ser.MaxJsonLength = Int32.MaxValue; if (jsonString.Trim().Length == 0) return null; - return ser.Deserialize>(jsonString); + + return JsonSerializer.Deserialize>(jsonString, JsonSerializerOptions); } /// @@ -35,12 +33,10 @@ internal static Dictionary getJsonAsDictionary(string jsonString /// Json formated string internal static string formatObjectAsJson(object arrayObj) { - JavaScriptSerializer ser = new JavaScriptSerializer(); - ser.MaxJsonLength = Int32.MaxValue; if (arrayObj == null) return "{}"; - return ser.Serialize(arrayObj); + return JsonSerializer.Serialize(arrayObj); } internal static string buildHttpQueryString(Dictionary data, string delimeter = "&") diff --git a/src/DotNetClient/DotNetClient/Wonde/ResultIterator.cs b/src/DotNetClient/DotNetClient/Wonde/ResultIterator.cs index ce23e4a..2c7d1cd 100644 --- a/src/DotNetClient/DotNetClient/Wonde/ResultIterator.cs +++ b/src/DotNetClient/DotNetClient/Wonde/ResultIterator.cs @@ -170,7 +170,7 @@ private bool processUrl(string url) return false; MetaData = (Dictionary)res["meta"]; - ArrayData = (ArrayList)res["data"]; + ArrayData = (List)res["data"]; Reset(); arrEnum = ArrayData.GetEnumerator(); return true; diff --git a/src/DotNetClient/TestWondeClient/App.config b/src/DotNetClient/TestWondeClient/App.config index 8221c26..5b080c8 100644 --- a/src/DotNetClient/TestWondeClient/App.config +++ b/src/DotNetClient/TestWondeClient/App.config @@ -1,10 +1,26 @@ - + - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DotNetClient/TestWondeClient/TestWondeConsole.csproj b/src/DotNetClient/TestWondeClient/TestWondeConsole.csproj index fc3dcec..8744042 100644 --- a/src/DotNetClient/TestWondeClient/TestWondeConsole.csproj +++ b/src/DotNetClient/TestWondeClient/TestWondeConsole.csproj @@ -33,9 +33,35 @@ 4 + + ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.8.0.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.8.0.5\lib\netstandard2.0\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + @@ -49,6 +75,7 @@ + diff --git a/src/DotNetClient/TestWondeClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/src/DotNetClient/TestWondeClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 38b7818..e7c3f15 100644 Binary files a/src/DotNetClient/TestWondeClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/src/DotNetClient/TestWondeClient/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/src/DotNetClient/TestWondeClient/packages.config b/src/DotNetClient/TestWondeClient/packages.config new file mode 100644 index 0000000..73ce5f2 --- /dev/null +++ b/src/DotNetClient/TestWondeClient/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/DotNetClient/Tests/App.config b/src/DotNetClient/Tests/App.config index 5bcb9fd..e5c6838 100644 --- a/src/DotNetClient/Tests/App.config +++ b/src/DotNetClient/Tests/App.config @@ -1,7 +1,23 @@ - + - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/DotNetClient/Tests/Tests.csproj b/src/DotNetClient/Tests/Tests.csproj index a6de430..2c05aab 100644 --- a/src/DotNetClient/Tests/Tests.csproj +++ b/src/DotNetClient/Tests/Tests.csproj @@ -35,8 +35,34 @@ 4 + + ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\netstandard2.0\Microsoft.Bcl.AsyncInterfaces.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.8.0.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.8.0.5\lib\netstandard2.0\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + @@ -60,6 +86,7 @@ + diff --git a/src/DotNetClient/Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/src/DotNetClient/Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 7a3ccad..9a26ec4 100644 Binary files a/src/DotNetClient/Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/src/DotNetClient/Tests/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/src/DotNetClient/Tests/packages.config b/src/DotNetClient/Tests/packages.config new file mode 100644 index 0000000..73ce5f2 --- /dev/null +++ b/src/DotNetClient/Tests/packages.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file