From cd94cf7201dd64f2326f002258a8c7615a41e5af Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Wed, 7 Aug 2019 23:01:10 +0200 Subject: [PATCH] Remove deprecated Newtonsoft JSON References --- JSONConverters.cs | 1 - json/IJsonConvert.cs | 21 ---- json/JSONConvert.cs | 105 -------------------- json/converter/JSONDateTimeConverter.cs | 58 ----------- json/converter/JSONGuidConverter.cs | 40 -------- json/converter/JSONIPv4Converter.cs | 40 -------- json/converter/JSONNetwork4Converter.cs | 40 -------- json/converter/JSONNumberConverter.cs | 123 ------------------------ json/converter/JSONStringConverter.cs | 50 ---------- json/converter/JSONTimeSpanConverter.cs | 48 --------- json/rpc/RPCError.cs | 26 ----- json/rpc/RPCMessage.cs | 44 --------- ln.types.csproj | 23 +---- net/IPv4.cs | 23 ----- net/Network4.cs | 29 ------ packages.config | 4 - rpc/RPCCall.cs | 5 +- rpc/RPCResult.cs | 5 +- stream/CharStream.cs | 66 +++++++++++++ sync/Syncable.cs | 1 + test/testODB.cs | 3 - threads/PoolJob.cs | 3 - 22 files changed, 73 insertions(+), 685 deletions(-) delete mode 100644 json/IJsonConvert.cs delete mode 100644 json/JSONConvert.cs delete mode 100644 json/converter/JSONDateTimeConverter.cs delete mode 100644 json/converter/JSONGuidConverter.cs delete mode 100644 json/converter/JSONIPv4Converter.cs delete mode 100644 json/converter/JSONNetwork4Converter.cs delete mode 100644 json/converter/JSONNumberConverter.cs delete mode 100644 json/converter/JSONStringConverter.cs delete mode 100644 json/converter/JSONTimeSpanConverter.cs delete mode 100644 json/rpc/RPCError.cs delete mode 100644 json/rpc/RPCMessage.cs delete mode 100644 packages.config create mode 100644 stream/CharStream.cs diff --git a/JSONConverters.cs b/JSONConverters.cs index 27a2562..b693f6a 100644 --- a/JSONConverters.cs +++ b/JSONConverters.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Newtonsoft.Json; namespace ln.types { public static class JSONConverters diff --git a/json/IJsonConvert.cs b/json/IJsonConvert.cs deleted file mode 100644 index 1e0ab62..0000000 --- a/json/IJsonConvert.cs +++ /dev/null @@ -1,21 +0,0 @@ -// /** -// * File: IJsonConvert.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using Newtonsoft.Json.Linq; -namespace ln.types.json -{ - public interface IJsonConvert - { - string GetSkyType(Type nativeType); - - bool JSON2Value(Type targetType, JToken jToken,ref object value); - bool Value2JSON(object value, ref JToken jToken); - } -} diff --git a/json/JSONConvert.cs b/json/JSONConvert.cs deleted file mode 100644 index 2d3d03d..0000000 --- a/json/JSONConvert.cs +++ /dev/null @@ -1,105 +0,0 @@ -// /** -// * File: Convert.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using System.Collections.Generic; -using ln.types.json.converter; -using Newtonsoft.Json.Linq; -namespace ln.types.json -{ - public class JSONConvert - { - public JSONConvert Fallback { get; private set; } - - List converters = new List(); - - public JSONConvert() - { - Fallback = DefaultInstance; - if (Fallback == null) - { - converters.Add(new JSONStringConverter()); - converters.Add(new JSONNumberConverter()); - converters.Add(new JSONDateTimeConverter()); - converters.Add(new JSONTimeSpanConverter()); - converters.Add(new JSONGuidConverter()); - converters.Add(new JSONIPv4Converter()); - converters.Add(new JSONNetwork4Converter()); - } - } - public JSONConvert(IEnumerable converters) - { - this.converters.AddRange(converters); - } - public JSONConvert(JSONConvert fallBack, IEnumerable converters) - :this(converters) - { - Fallback = fallBack; - } - - public string GetSkyType(Type targetType) - { - foreach (IJsonConvert convert in converters) - { - string skyType = convert.GetSkyType(targetType); - if (skyType != null) - return skyType; - } - if (Fallback != null) - return Fallback.GetSkyType(targetType); - return null; - } - - public T JSON2Value(JToken jToken) - { - object v = null; - if (JSON2Value(typeof(T),jToken,ref v)) - { - if (v is T) - { - return (T)v; - } - } - throw new FormatException(String.Format("JSON2Value could not convert {0} to Type {1}",jToken.ToString(),typeof(T).FullName)); - } - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - foreach (IJsonConvert convert in converters) - { - if (convert.JSON2Value(targetType, jToken, ref value)) - return true; - } - - if (Fallback != null) - return Fallback.JSON2Value(targetType, jToken, ref value); - - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - foreach (IJsonConvert convert in converters) - { - if (convert.Value2JSON(value, ref jToken)) - return true; - } - - if (Fallback != null) - return Fallback.Value2JSON(value, ref jToken); - - return false; - } - - public static JSONConvert DefaultInstance { get; } = new JSONConvert(); - - public static bool ToValue(Type targetType, JToken jToken, ref object value) => DefaultInstance.JSON2Value(targetType, jToken, ref value); - public static bool ToJSON(object value, ref JToken jToken) => DefaultInstance.Value2JSON(value, ref jToken); - - } -} diff --git a/json/converter/JSONDateTimeConverter.cs b/json/converter/JSONDateTimeConverter.cs deleted file mode 100644 index dd92f00..0000000 --- a/json/converter/JSONDateTimeConverter.cs +++ /dev/null @@ -1,58 +0,0 @@ -// /** -// * File: JSONDateTimeConverter.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using Newtonsoft.Json.Linq; - -namespace ln.types.json.converter -{ - public class JSONDateTimeConverter : IJsonConvert - { - public JSONDateTimeConverter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(DateTime).Equals(nativeType) || typeof(DateTimeOffset).Equals(nativeType)) - return "datetime"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(DateTime).Equals(targetType)) - { - value = DateTimeOffset.FromUnixTimeSeconds(jToken.Value()).DateTime; - return true; - } - else if (typeof(DateTimeOffset).Equals(targetType)) - { - value = DateTimeOffset.FromUnixTimeSeconds(jToken.Value()); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (value is DateTime) - { - jToken = JToken.FromObject(new DateTimeOffset((DateTime)value).ToUnixTimeSeconds()); - return true; - } - else if (value is DateTimeOffset) - { - jToken = JToken.FromObject(((DateTimeOffset)value).ToUnixTimeSeconds()); - return true; - } - return false; - } - } -} diff --git a/json/converter/JSONGuidConverter.cs b/json/converter/JSONGuidConverter.cs deleted file mode 100644 index cc61f71..0000000 --- a/json/converter/JSONGuidConverter.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; - -namespace ln.types.json.converter -{ - public class JSONGuidConverter : IJsonConvert - { - public JSONGuidConverter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(Guid).Equals(nativeType)) - return "guid"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(Guid).Equals(targetType)) - { - String src = jToken.ToObject(); - value = Guid.Parse(src); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (typeof(Guid).Equals(value.GetType())) - { - jToken = JToken.FromObject(((Guid)value).ToString()); - return true; - } - return false; - } - } -} diff --git a/json/converter/JSONIPv4Converter.cs b/json/converter/JSONIPv4Converter.cs deleted file mode 100644 index 3e0d35c..0000000 --- a/json/converter/JSONIPv4Converter.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ln.types.net; - -namespace ln.types.json.converter -{ - public class JSONIPv4Converter : IJsonConvert - { - public JSONIPv4Converter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(IPv4).Equals(nativeType)) - return "ipv4"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(IPv4).Equals(targetType)) - { - value = IPv4.Parse(jToken.ToObject()); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (value is IPv4) - { - jToken = JToken.FromObject((value as IPv4).ToString()); - return true; - } - return false; - } - } -} diff --git a/json/converter/JSONNetwork4Converter.cs b/json/converter/JSONNetwork4Converter.cs deleted file mode 100644 index d66f06f..0000000 --- a/json/converter/JSONNetwork4Converter.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using ln.types.net; - -namespace ln.types.json.converter -{ - public class JSONNetwork4Converter : IJsonConvert - { - public JSONNetwork4Converter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(Network4).Equals(nativeType)) - return "network4"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(Network4).Equals(targetType)) - { - value = Network4.Parse(jToken.ToObject()); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (value is Network4) - { - jToken = JToken.FromObject((value as Network4).ToString()); - return true; - } - return false; - } - } -} diff --git a/json/converter/JSONNumberConverter.cs b/json/converter/JSONNumberConverter.cs deleted file mode 100644 index 3c7ae9f..0000000 --- a/json/converter/JSONNumberConverter.cs +++ /dev/null @@ -1,123 +0,0 @@ -// /** -// * File: JSONNumberConverter.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using Newtonsoft.Json.Linq; - -namespace ln.types.json.converter -{ - public class JSONNumberConverter : IJsonConvert - { - public JSONNumberConverter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(short).Equals(nativeType)) - { - return "int"; - } - else if (typeof(ushort).Equals(nativeType)) - { - return "int"; - } - else if (typeof(int).Equals(nativeType)) - { - return "int"; - } - else if (typeof(uint).Equals(nativeType)) - { - return "int"; - } - else if (typeof(long).Equals(nativeType)) - { - return "int"; - } - else if (typeof(ulong).Equals(nativeType)) - { - return "int"; - } - else if (typeof(float).Equals(nativeType)) - { - return "float"; - } - else if (typeof(double).Equals(nativeType)) - { - return "float"; - } - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(short).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(ushort).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(int).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(uint).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(long).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(ulong).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(float).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - else if (typeof(double).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - Type sourceType = value.GetType(); - if (typeof(short).Equals(sourceType) - || typeof(ushort).Equals(sourceType) - || typeof(int).Equals(sourceType) - || typeof(uint).Equals(sourceType) - || typeof(long).Equals(sourceType) - || typeof(ulong).Equals(sourceType) - || typeof(float).Equals(sourceType) - || typeof(double).Equals(sourceType) - ) - { - jToken = JToken.FromObject(value); - return true; - } - return false; - - } - } -} diff --git a/json/converter/JSONStringConverter.cs b/json/converter/JSONStringConverter.cs deleted file mode 100644 index bb2886b..0000000 --- a/json/converter/JSONStringConverter.cs +++ /dev/null @@ -1,50 +0,0 @@ -// /** -// * File: JSONStringConverter.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using Newtonsoft.Json.Linq; - -namespace ln.types.json.converter -{ - public class JSONStringConverter : IJsonConvert - { - public JSONStringConverter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(string).Equals(nativeType)) - return "string"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(string).Equals(targetType)) - { - value = jToken.Value(); - return true; - } - value = null; - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (value is string) - { - jToken = JToken.FromObject(value); - return true; - } - jToken = null; - return false; - } - } -} diff --git a/json/converter/JSONTimeSpanConverter.cs b/json/converter/JSONTimeSpanConverter.cs deleted file mode 100644 index 92b1bb5..0000000 --- a/json/converter/JSONTimeSpanConverter.cs +++ /dev/null @@ -1,48 +0,0 @@ -// /** -// * File: JSONTimeSpanConverter.cs -// * Author: haraldwolff -// * -// * This file and it's content is copyrighted by the Author and / or copyright holder. -// * Any use wihtout proper permission is illegal and may lead to legal actions. -// * -// * -// **/ -using System; -using Newtonsoft.Json.Linq; - -namespace ln.types.json.converter -{ - public class JSONTimeSpanConverter :IJsonConvert - { - public JSONTimeSpanConverter() - { - } - - public string GetSkyType(Type nativeType) - { - if (typeof(TimeSpan).Equals(nativeType)) - return "timespan"; - return null; - } - - public bool JSON2Value(Type targetType, JToken jToken, ref object value) - { - if (typeof(TimeSpan).Equals(targetType)) - { - value = TimeSpan.FromSeconds(jToken.Value()); - return true; - } - return false; - } - - public bool Value2JSON(object value, ref JToken jToken) - { - if (value is TimeSpan) - { - jToken = JToken.FromObject(((TimeSpan)value).TotalSeconds); - return true; - } - return false; - } - } -} diff --git a/json/rpc/RPCError.cs b/json/rpc/RPCError.cs deleted file mode 100644 index 3286875..0000000 --- a/json/rpc/RPCError.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -namespace ln.types.json.rpc -{ - public class RPCError - { - public int Code { get; set; } - public string Message { get; set; } - - public object Data { get; set; } - - public RPCError() - { - } - public RPCError(Exception e) - { - Code = 500; - Message = e.ToString(); - } - public RPCError(int code,String message) - { - Code = code; - Message = message; - } - - } -} diff --git a/json/rpc/RPCMessage.cs b/json/rpc/RPCMessage.cs deleted file mode 100644 index 7df0bbc..0000000 --- a/json/rpc/RPCMessage.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; -namespace ln.types.json.rpc -{ - public class RPCMessage - { - public String Version { get; set; } - public String Method { get; set; } - public object[] Parameters { get; set; } - - public object Result { get; set; } - public RPCError Error { get; set; } - - public JToken Identifier { get; set; } - - public RPCMessage() - { - Version = "2.0"; - Parameters = new object[0]; - } - public RPCMessage(JObject source) - { - Version = source["jsonrpc"].ToObject(); - if (source.ContainsKey("method")) - Method = source["method"].ToObject(); - if (source.ContainsKey("params")) - Parameters = source["params"].ToObject(); - - if (source.ContainsKey("result")) - Result = source["result"]; - - if (source.ContainsKey("error")) - - if (source.ContainsKey("id")) - Identifier = source["id"]; - else - Identifier = null; - } - - - - } -} diff --git a/ln.types.csproj b/ln.types.csproj index 1105559..9ecbe53 100644 --- a/ln.types.csproj +++ b/ln.types.csproj @@ -31,9 +31,6 @@ - - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll - nunit @@ -85,7 +82,6 @@ - @@ -106,20 +102,9 @@ - - - - - - - - - - - @@ -132,6 +117,7 @@ + @@ -147,13 +133,11 @@ - - - + @@ -161,8 +145,5 @@ ln.logging - - - \ No newline at end of file diff --git a/net/IPv4.cs b/net/IPv4.cs index 4db4c70..f5fa2d6 100644 --- a/net/IPv4.cs +++ b/net/IPv4.cs @@ -2,7 +2,6 @@ using System.Linq; using System.Net; using ln.types.odb; -using Newtonsoft.Json; using System.Collections.Generic; using ln.types.odb.values; namespace ln.types.net @@ -126,28 +125,6 @@ namespace ln.types.net (mapper, value) => new ODBTypedValue(typeof(IPv4), value._ip), (mapper, oval) => new IPv4(oval.AsTypedValue.ODBValue.AsUInt) ); - - JSONConverters.converters.Add(new IPv4JsonConverter()); } - - public class IPv4JsonConverter : JsonConverter - { - public override bool CanConvert(Type objectType) - { - return (objectType == typeof(IPv4)); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return IPv4.Parse(reader.ReadAsString()); - } - - public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - writer.WriteValue((value as IPv4).ToString()); - } - - } - } } diff --git a/net/Network4.cs b/net/Network4.cs index b59f349..1623ccf 100644 --- a/net/Network4.cs +++ b/net/Network4.cs @@ -11,8 +11,6 @@ using System; using System.Linq; using System.Collections.Generic; using System.Collections; -using Newtonsoft.Json; -using ln.types.net; namespace ln.types.net { @@ -214,32 +212,5 @@ namespace ln.types.net currentIP = null; } } - - - static Network4() - { - JSONConverters.converters.Add( new Network4JsonConverter()); - } - } - - public class Network4JsonConverter: JsonConverter - { - public override bool CanConvert(Type objectType) - { - return (objectType == typeof(Network4)); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) - { - return Network4.Parse(reader.ReadAsString()); - } - - public override void WriteJson(JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) - { - writer.WriteValue((value as Network4).ToString()); - } - - } - } diff --git a/packages.config b/packages.config deleted file mode 100644 index 39d1cce..0000000 --- a/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/rpc/RPCCall.cs b/rpc/RPCCall.cs index e116b8d..da70b74 100644 --- a/rpc/RPCCall.cs +++ b/rpc/RPCCall.cs @@ -1,6 +1,4 @@ using System; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json; namespace ln.types.rpc { public class RPCCall @@ -16,6 +14,7 @@ namespace ln.types.rpc { Identifier = Guid.NewGuid(); } + /* public RPCCall(JObject json) { if (json.ContainsKey("id")) @@ -51,6 +50,6 @@ namespace ln.types.rpc else Parameters = new object[0]; } - + */ } } diff --git a/rpc/RPCResult.cs b/rpc/RPCResult.cs index 8877242..454f547 100644 --- a/rpc/RPCResult.cs +++ b/rpc/RPCResult.cs @@ -1,5 +1,4 @@ using System; -using Newtonsoft.Json.Linq; namespace ln.types.rpc { public class RPCResult @@ -26,7 +25,7 @@ namespace ln.types.rpc Exception = e; ErrorText = e.ToString(); } - + /* public JObject ToJSON() { JObject result = new JObject(); @@ -45,6 +44,6 @@ namespace ln.types.rpc return result; } - + */ } } diff --git a/stream/CharStream.cs b/stream/CharStream.cs new file mode 100644 index 0000000..3f1c3ac --- /dev/null +++ b/stream/CharStream.cs @@ -0,0 +1,66 @@ +// /** +// * File: CharStream.cs +// * Author: haraldwolff +// * +// * This file and it's content is copyrighted by the Author and / or copyright holder. +// * Any use wihtout proper permission is illegal and may lead to legal actions. +// * +// * +// **/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +namespace ln.types.stream +{ + public class CharStream + { + public char Current => characters[position]; + public int Position => position; + + char[] characters; + int position; + + public CharStream(IEnumerable characters) + : this(characters.ToArray()) { } + + public CharStream(char[] characters) + { + this.characters = characters; + } + + public bool TryNext() + { + position++; + return (position < this.characters.Length); + } + public void MoveNext() + { + position++; + if (position >= this.characters.Length) + throw new IOException("Unexpected end of characters"); + } + + public void Skip(Func test) + { + if (position < this.characters.Length) + while (test(Current) && TryNext()) + { + } + } + public char[] Read(Func test) + { + List chars = new List(); + + while (test(Current)) + { + chars.Add(Current); + MoveNext(); + } + + return chars.ToArray(); + } + + + } +} diff --git a/sync/Syncable.cs b/sync/Syncable.cs index 7f8b10f..9c96560 100644 --- a/sync/Syncable.cs +++ b/sync/Syncable.cs @@ -18,6 +18,7 @@ using System.Text; using ln.types.serialize; namespace ln.types.sync { + public class Synced : Attribute { } diff --git a/test/testODB.cs b/test/testODB.cs index f39a0d4..ef98c33 100644 --- a/test/testODB.cs +++ b/test/testODB.cs @@ -11,11 +11,8 @@ using NUnit.Framework; using System; using System.IO; using ln.types.odb; -using Newtonsoft.Json; using System.Diagnostics; using ln.types.threads; -using System.Threading; -using ln.logging; using ln.types.odb.attributes; using ln.types.odb.mapped; using System.Linq; diff --git a/threads/PoolJob.cs b/threads/PoolJob.cs index 9de2737..5b2e69f 100644 --- a/threads/PoolJob.cs +++ b/threads/PoolJob.cs @@ -1,6 +1,5 @@ using System; using ln.logging; -using Newtonsoft.Json; using System.Threading; namespace ln.types.threads { @@ -13,9 +12,7 @@ namespace ln.types.threads { public string Name { get; set; } - [JsonIgnore] public JobDelegate Job { get; } - [JsonIgnore] public ExtendedJobDelegate ExtendedJob { get; } public double Progress { get; set; }