Files
react-native-code-push/windows/CodePushUtils.cs
Eric Rozell b72bf77e25 fix(async): Changing all await calls to .ConfigureAwait(false)
The async calls in CodePush for ReactWindows can all be executed on any background thread, so adding .ConfigureAwait(false) can improve performance and reduce the likelihood of deadlock.  The blocking calls in `InitializeUpdateAfterRestart()` were hanging, but now that .ConfigureAwait(false) is used pervasively, it is no longer a problem.

Fixes #550
2016-10-05 09:47:20 -04:00

54 lines
1.4 KiB
C#

using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.System.Profile;
namespace CodePush.ReactNative
{
internal class CodePushUtils
{
internal async static Task<JObject> GetJObjectFromFileAsync(StorageFile file)
{
string jsonString = await FileIO.ReadTextAsync(file).AsTask().ConfigureAwait(false);
if (jsonString.Length == 0)
{
return new JObject();
}
try
{
return JObject.Parse(jsonString);
}
catch (Exception)
{
return null;
}
}
internal static void Log(string message)
{
Debug.WriteLine("[CodePush] " + message, CodePushConstants.ReactNativeLogCategory);
}
internal static void LogBundleUrl(string path)
{
Log("Loading JS bundle from \"" + path + "\"");
}
internal static string GetDeviceId()
{
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = token.Id;
var dataReader = DataReader.FromBuffer(hardwareId);
var bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes);
}
}
}