Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to dotnet standard #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 0 additions & 19 deletions src/DotNetClient/DotNetClient/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")]
jamesr981 marked this conversation as resolved.
Show resolved Hide resolved
114 changes: 10 additions & 104 deletions src/DotNetClient/DotNetClient/Wonde.NET.csproj
Original file line number Diff line number Diff line change
@@ -1,113 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{14EF1CDD-1D99-4078-AB11-1207E859C63C}</ProjectGuid>
<TargetFramework>netstandard2.0</TargetFramework> <!-- Change this to the desired .NET Standard version -->
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wonde</RootNamespace>
<AssemblyName>Wonde.NET</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
<LangVersion>8</LangVersion>
</PropertyGroup>

<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Wonde\Client.cs" />
<Compile Include="Wonde\EndPoints\AttendanceSumaries.cs" />
<Compile Include="Wonde\EndPoints\Achievements.cs" />
<Compile Include="Wonde\EndPoints\Assessment.cs" />
<Compile Include="Wonde\EndPoints\Assessments\Aspects.cs" />
<Compile Include="Wonde\EndPoints\Assessments\MarkSheets.cs" />
<Compile Include="Wonde\EndPoints\Assessments\Results.cs" />
<Compile Include="Wonde\EndPoints\Assessments\ResultSets.cs" />
<Compile Include="Wonde\EndPoints\Assessments\Templates.cs" />
<Compile Include="Wonde\EndPoints\Attendance.cs" />
<Compile Include="Wonde\EndPoints\AttendanceCodes.cs" />
<Compile Include="Wonde\EndPoints\Behaviours.cs" />
<Compile Include="Wonde\EndPoints\BootstrapEndpoint.cs" />
<Compile Include="Wonde\EndPoints\Classes.cs" />
<Compile Include="Wonde\EndPoints\Contacts.cs" />
<Compile Include="Wonde\EndPoints\Counts.cs" />
<Compile Include="Wonde\EndPoints\Deletions.cs" />
<Compile Include="Wonde\EndPoints\Doctors.cs" />
<Compile Include="Wonde\EndPoints\EmployeeAbsences.cs" />
<Compile Include="Wonde\EndPoints\Employees.cs" />
<Compile Include="Wonde\EndPoints\Events.cs" />
<Compile Include="Wonde\EndPoints\Exclusions.cs" />
<Compile Include="Wonde\EndPoints\Groups.cs" />
<Compile Include="Wonde\EndPoints\Lessons.cs" />
<Compile Include="Wonde\EndPoints\LessonAttendance.cs" />
<Compile Include="Wonde\EndPoints\MedicalConditions.cs" />
<Compile Include="Wonde\EndPoints\MedicalNotes.cs" />
<Compile Include="Wonde\EndPoints\MedicalEvents.cs" />
<Compile Include="Wonde\EndPoints\Periods.cs" />
<Compile Include="Wonde\EndPoints\Photos.cs" />
<Compile Include="Wonde\EndPoints\PreAdmissionStudents.cs" />
<Compile Include="Wonde\EndPoints\Rooms.cs" />
<Compile Include="Wonde\EndPoints\Schools.cs" />
<Compile Include="Wonde\EndPoints\Students.cs" />
<Compile Include="Wonde\EndPoints\Subjects.cs" />
<Compile Include="Wonde\EndPoints\Writebacks.cs" />
<Compile Include="Wonde\Exceptions\InvalidStudentsBehavioursException.cs" />
<Compile Include="Wonde\Exceptions\InvalidStudentsAchievementsException.cs" />
<Compile Include="Wonde\Exceptions\ValidationErrorException.cs" />
<Compile Include="Wonde\Exceptions\InvalidTokenException.cs" />
<Compile Include="Wonde\Helpers\JsonSerializeHelper.cs" />
<Compile Include="Wonde\Helpers\RestClient.cs" />
<Compile Include="Wonde\Helpers\Exceptions\RestClientException.cs" />
<Compile Include="Wonde\ResultIterator.cs" />
<Compile Include="Wonde\Exceptions\InvalidLessonAttendanceException.cs" />
<Compile Include="Wonde\Exceptions\InvalidSessionAttendanceException.cs" />
<Compile Include="Wonde\WriteBack\LessionAttendanceRecord.cs" />
<Compile Include="Wonde\WriteBack\LessonRegister.cs" />
<Compile Include="Wonde\WriteBack\SessionAttendanceRecord.cs" />
<Compile Include="Wonde\WriteBack\SessionRegister.cs" />
<Compile Include="Wonde\WriteBack\StudentsAchievementRecord.cs" />
<Compile Include="Wonde\WriteBack\StudentsAchievements.cs" />
<Compile Include="Wonde\WriteBack\StudentsBehaviourRecord.cs" />
<Compile Include="Wonde\WriteBack\StudentsBehaviours.cs" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" /> <!-- Add any other necessary packages here -->
<!-- Include any other NuGet packages needed for .NET Standard -->
</ItemGroup>
<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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

</Project>
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 1 addition & 5 deletions src/DotNetClient/DotNetClient/Wonde/EndPoints/Schools.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Dictionary<string, object>>
jamesr981 marked this conversation as resolved.
Show resolved Hide resolved
{
public override Dictionary<string, object> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var dict = new Dictionary<string, object>();

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<object> ReadArray(ref Utf8JsonReader reader, JsonSerializerOptions options)
{
var list = new List<object>();

while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndArray)
{
return list;
}

if (reader.TokenType == JsonTokenType.StartObject)
{
list.Add(Read(ref reader, typeof(Dictionary<string, object>), options));
}
else
{
list.Add(ReadPrimitive(ref reader));
}
}

return list;
}

public override void Write(Utf8JsonWriter writer, Dictionary<string, object> value, JsonSerializerOptions options)
{
writer.WriteStartObject();
foreach (var kvp in value)
{
writer.WritePropertyName(kvp.Key);
JsonSerializer.Serialize(writer, kvp.Value, options);
}
writer.WriteEndObject();
}
}
}
20 changes: 8 additions & 12 deletions src/DotNetClient/DotNetClient/Wonde/Helpers/JsonSerializeHelper.cs
Original file line number Diff line number Diff line change
@@ -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;


Expand All @@ -14,18 +10,20 @@ namespace Wonde.Helpers
/// </summary>
internal class StringHelper
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions
{ Converters = { new JsonDictionaryConverter() } };

/// <summary>
/// Converts a Json string into Key/Value pair representation of Dictionary object
/// </summary>
/// <param name="jsonString">The Json String to format as Object</param>
/// <returns>Json data decoded as Key/Value pair representation of Dictionary object</returns>
internal static Dictionary<string, object> getJsonAsDictionary(string jsonString)
{
JavaScriptSerializer ser = new JavaScriptSerializer();
ser.MaxJsonLength = Int32.MaxValue;
if (jsonString.Trim().Length == 0)
return null;
return ser.Deserialize<Dictionary<string, object>>(jsonString);

return JsonSerializer.Deserialize<Dictionary<string, object>>(jsonString, JsonSerializerOptions);
}

/// <summary>
Expand All @@ -35,12 +33,10 @@ internal static Dictionary<string, object> getJsonAsDictionary(string jsonString
/// <returns>Json formated string</returns>
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<string, string> data, string delimeter = "&")
Expand Down
2 changes: 1 addition & 1 deletion src/DotNetClient/DotNetClient/Wonde/ResultIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private bool processUrl(string url)
return false;

MetaData = (Dictionary<string, object>)res["meta"];
ArrayData = (ArrayList)res["data"];
ArrayData = (List<object>)res["data"];
Reset();
arrEnum = ArrayData.GetEnumerator();
return true;
Expand Down
22 changes: 19 additions & 3 deletions src/DotNetClient/TestWondeClient/App.config
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="API_TOKEN" value="[Add your API Token]"/>
<add key="SCHOOL_ID" value="A1930499544"/>
<add key="API_TOKEN" value="[Add your API token here]" />
<add key="SCHOOL_ID" value="A1930499544" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Loading