2323using System . Security . Cryptography ;
2424using System . Text ;
2525using UnityEngine ;
26+ using System . Net . NetworkInformation ;
27+ using System . Text . RegularExpressions ;
2628
2729
2830namespace IBM . Watson . DeveloperCloud . Utilities
@@ -33,6 +35,7 @@ namespace IBM.Watson.DeveloperCloud.Utilities
3335 static public class Utility
3436 {
3537 private static fsSerializer sm_Serializer = new fsSerializer ( ) ;
38+ private static string sm_MacAddress = null ;
3639
3740 /// <summary>
3841 /// This helper functions returns all Type's that inherit from the given type.
@@ -272,6 +275,34 @@ public static string StripString(string s)
272275 }
273276
274277
278+
279+ /// <summary>
280+ /// Returns First valid Mac address of the local machine
281+ /// </summary>
282+ public static string MacAddress
283+ {
284+ get
285+ {
286+ if ( string . IsNullOrEmpty ( sm_MacAddress ) )
287+ {
288+ foreach ( NetworkInterface adapter in NetworkInterface . GetAllNetworkInterfaces ( ) )
289+ {
290+ string macAddress = adapter . GetPhysicalAddress ( ) . ToString ( ) ;
291+ if ( ! string . IsNullOrEmpty ( macAddress ) )
292+ {
293+ string regex = "(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})" ;
294+ string replace = "$1:$2:$3:$4:$5:$6" ;
295+ sm_MacAddress = Regex . Replace ( macAddress , regex , replace ) ;
296+
297+ break ;
298+ }
299+ }
300+ }
301+
302+ return sm_MacAddress ;
303+ }
304+ }
305+
275306 #region Cache Generic Deserialization
276307
277308 public static void SaveToCache < T > ( Dictionary < string , DataCache > dictionaryCache , string cacheDirectoryId , string cacheId , T objectToCache , string prefix = "" , long maxCacheSize = 1024 * 1024 * 50 , double maxCacheAge = 24 * 7 ) where T : class , new ( )
@@ -319,6 +350,10 @@ public static string StripString(string s)
319350 return cachedObject ;
320351 }
321352
353+ #endregion
354+
355+ #region De-Serialization
356+
322357 /// <summary>
323358 /// Deserializes the response.
324359 /// </summary>
@@ -328,9 +363,20 @@ public static string StripString(string s)
328363 /// <typeparam name="T">The 1st type parameter.</typeparam>
329364 public static T DeserializeResponse < T > ( byte [ ] resp , object obj = null ) where T : class , new ( )
330365 {
331- string json = Encoding . UTF8 . GetString ( resp ) ;
366+ return DeserializeResponse < T > ( Encoding . UTF8 . GetString ( resp ) , obj ) ;
367+ }
368+
369+ /// <summary>
370+ /// Deserializes the response.
371+ /// </summary>
372+ /// <returns>The response.</returns>
373+ /// <param name="json">Json string of object</param>
374+ /// <param name="obj">Object.</param>
375+ /// <typeparam name="T">The 1st type parameter.</typeparam>
376+ public static T DeserializeResponse < T > ( string json , object obj = null ) where T : class , new ( )
377+ {
332378 try
333- {
379+ {
334380 fsData data = null ;
335381 fsResult r = fsJsonParser . Parse ( json , out data ) ;
336382 if ( ! r . Succeeded )
@@ -352,6 +398,8 @@ public static string StripString(string s)
352398
353399 return null ;
354400 }
401+
402+
355403 #endregion
356404 }
357405}
0 commit comments