11using System ;
22using System . Collections . Generic ;
3- using System . Globalization ;
4- using System . IO ;
53using System . Linq ;
4+ using System . IO ;
65using System . Reflection ;
6+ using System . Globalization ;
77using Newtonsoft . Json ;
88using Newtonsoft . Json . Linq ;
99
10- namespace PubnubApi . Unity . PubNub . Runtime . Util {
11- public class NewtonsoftJsonUnity : IJsonPluggableLibrary
10+ namespace PubnubApi
11+ {
12+ public class NewtonsoftJsonUnity : IJsonPluggableLibrary
1213 {
1314 private readonly PNConfiguration config ;
14- private readonly IPubnubLog pubnubLog ;
1515 private readonly JsonSerializerSettings defaultJsonSerializerSettings ;
16+ private readonly PubnubLogModule logger ;
1617
17- public NewtonsoftJsonUnity ( PNConfiguration pubnubConfig , IPubnubLog log )
18+ public NewtonsoftJsonUnity ( PNConfiguration pubnubConfig )
1819 {
1920 this . config = pubnubConfig ;
20- this . pubnubLog = log ;
2121 defaultJsonSerializerSettings = new JsonSerializerSettings { MaxDepth = 64 } ;
22+ logger = pubnubConfig . Logger ;
2223 }
2324
2425 #region IJsonPlugableLibrary methods implementation
@@ -139,6 +140,7 @@ public object DeserializeToObject(object rawObject, Type type)
139140 {
140141 try
141142 {
143+ logger ? . Debug ( "JsonNet Deserializing object data." ) ;
142144 if ( rawObject is JObject jObject )
143145 {
144146 return jObject . ToObject ( type ) ;
@@ -150,13 +152,14 @@ public object DeserializeToObject(object rawObject, Type type)
150152 }
151153 catch ( Exception e )
152154 {
153- LoggingMethod . WriteToLog ( pubnubLog , $ "[ { DateTime . Now . ToString ( CultureInfo . InvariantCulture ) } ] Error: DeserializeToObject exception { e } " , config . LogVerbosity ) ;
155+ logger ? . Error ( $ "Deserialize To Object failed with exception { e . Message } , stack trace { e . StackTrace } " ) ;
154156 return rawObject ;
155157 }
156158 }
157159
158160 public object DeserializeToObject ( string jsonString )
159161 {
162+ logger ? . Debug ( "JsonNet Deserializing json string data." ) ;
160163 object result = JsonConvert . DeserializeObject < object > ( jsonString ,
161164 new JsonSerializerSettings { DateParseHandling = DateParseHandling . None , MaxDepth = 64 } ) ;
162165 if ( result . GetType ( ) . ToString ( ) == "Newtonsoft.Json.Linq.JArray" )
@@ -177,7 +180,7 @@ public object DeserializeToObject(string jsonString)
177180 result = objectContainer ;
178181 }
179182 }
180-
183+ logger ? . Debug ( "JsonNet Deserialsed json string data successfully." ) ;
181184 return result ;
182185 }
183186
@@ -207,21 +210,12 @@ private bool IsGenericTypeForMessage<T>()
207210 {
208211 bool ret = typeof ( T ) . GetTypeInfo ( ) . IsGenericType &&
209212 typeof ( T ) . GetGenericTypeDefinition ( ) == typeof ( PNMessageResult < > ) ;
210-
211- LoggingMethod . WriteToLog ( pubnubLog ,
212- $ "[{ DateTime . Now . ToString ( CultureInfo . InvariantCulture ) } ] typeof(T).GetTypeInfo().IsGenericType = { typeof ( T ) . GetTypeInfo ( ) . IsGenericType } ", config . LogVerbosity ) ;
213- if ( typeof ( T ) . GetTypeInfo ( ) . IsGenericType )
214- {
215- LoggingMethod . WriteToLog ( pubnubLog ,
216- $ "[{ DateTime . Now . ToString ( CultureInfo . InvariantCulture ) } ] typeof(T).GetGenericTypeDefinition() = { typeof ( T ) . GetGenericTypeDefinition ( ) } ", config . LogVerbosity ) ;
217- }
218- LoggingMethod . WriteToLog ( pubnubLog ,
219- $ "[{ DateTime . Now . ToString ( CultureInfo . InvariantCulture ) } ] IsGenericTypeForMessage = { ret } ", config . LogVerbosity ) ;
220213 return ret ;
221214 }
222215
223216 private T DeserializeMessageToObjectBasedOnPlatform < T > ( List < object > listObject )
224217 {
218+ logger ? . Debug ( "JsonNet Deserializing Messages data." ) ;
225219 T ret = default ( T ) ;
226220 Type dataType = typeof ( T ) . GetTypeInfo ( ) . GenericTypeArguments [ 0 ] ;
227221 Type generic = typeof ( PNMessageResult < > ) ;
@@ -296,7 +290,7 @@ private T DeserializeMessageToObjectBasedOnPlatform<T>(List<object> listObject)
296290
297291 ret = ( T ) Convert . ChangeType ( message , specific , CultureInfo . InvariantCulture ) ;
298292 }
299-
293+ logger ? . Debug ( "JsonNet Deserialized Messages successfully." ) ;
300294 return ret ;
301295 }
302296
0 commit comments