1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Globalization ;
4
- using System . IO ;
5
3
using System . Linq ;
4
+ using System . IO ;
6
5
using System . Reflection ;
6
+ using System . Globalization ;
7
7
using Newtonsoft . Json ;
8
8
using Newtonsoft . Json . Linq ;
9
9
10
- namespace PubnubApi . Unity . PubNub . Runtime . Util {
11
- public class NewtonsoftJsonUnity : IJsonPluggableLibrary
10
+ namespace PubnubApi
11
+ {
12
+ public class NewtonsoftJsonUnity : IJsonPluggableLibrary
12
13
{
13
14
private readonly PNConfiguration config ;
14
- private readonly IPubnubLog pubnubLog ;
15
15
private readonly JsonSerializerSettings defaultJsonSerializerSettings ;
16
+ private readonly PubnubLogModule logger ;
16
17
17
- public NewtonsoftJsonUnity ( PNConfiguration pubnubConfig , IPubnubLog log )
18
+ public NewtonsoftJsonUnity ( PNConfiguration pubnubConfig )
18
19
{
19
20
this . config = pubnubConfig ;
20
- this . pubnubLog = log ;
21
21
defaultJsonSerializerSettings = new JsonSerializerSettings { MaxDepth = 64 } ;
22
+ logger = pubnubConfig . Logger ;
22
23
}
23
24
24
25
#region IJsonPlugableLibrary methods implementation
@@ -139,6 +140,7 @@ public object DeserializeToObject(object rawObject, Type type)
139
140
{
140
141
try
141
142
{
143
+ logger ? . Debug ( "JsonNet Deserializing object data." ) ;
142
144
if ( rawObject is JObject jObject )
143
145
{
144
146
return jObject . ToObject ( type ) ;
@@ -150,13 +152,14 @@ public object DeserializeToObject(object rawObject, Type type)
150
152
}
151
153
catch ( Exception e )
152
154
{
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 } " ) ;
154
156
return rawObject ;
155
157
}
156
158
}
157
159
158
160
public object DeserializeToObject ( string jsonString )
159
161
{
162
+ logger ? . Debug ( "JsonNet Deserializing json string data." ) ;
160
163
object result = JsonConvert . DeserializeObject < object > ( jsonString ,
161
164
new JsonSerializerSettings { DateParseHandling = DateParseHandling . None , MaxDepth = 64 } ) ;
162
165
if ( result . GetType ( ) . ToString ( ) == "Newtonsoft.Json.Linq.JArray" )
@@ -177,7 +180,7 @@ public object DeserializeToObject(string jsonString)
177
180
result = objectContainer ;
178
181
}
179
182
}
180
-
183
+ logger ? . Debug ( "JsonNet Deserialsed json string data successfully." ) ;
181
184
return result ;
182
185
}
183
186
@@ -207,21 +210,12 @@ private bool IsGenericTypeForMessage<T>()
207
210
{
208
211
bool ret = typeof ( T ) . GetTypeInfo ( ) . IsGenericType &&
209
212
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 ) ;
220
213
return ret ;
221
214
}
222
215
223
216
private T DeserializeMessageToObjectBasedOnPlatform < T > ( List < object > listObject )
224
217
{
218
+ logger ? . Debug ( "JsonNet Deserializing Messages data." ) ;
225
219
T ret = default ( T ) ;
226
220
Type dataType = typeof ( T ) . GetTypeInfo ( ) . GenericTypeArguments [ 0 ] ;
227
221
Type generic = typeof ( PNMessageResult < > ) ;
@@ -296,7 +290,7 @@ private T DeserializeMessageToObjectBasedOnPlatform<T>(List<object> listObject)
296
290
297
291
ret = ( T ) Convert . ChangeType ( message , specific , CultureInfo . InvariantCulture ) ;
298
292
}
299
-
293
+ logger ? . Debug ( "JsonNet Deserialized Messages successfully." ) ;
300
294
return ret ;
301
295
}
302
296
0 commit comments