Created
August 29, 2016 19:32
-
-
Save mattpodwysocki/40b5ff89e966ad7c6118d3657f5b71f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RunSerializedScript(string script, string sourceUrl) | |
{ | |
var localFolder = ApplicationData.Current.LocalFolder; | |
var binFile = "ReactNativeSerializedBundle.bin"; | |
var binPath = Path.Combine(localFolder.Path, binFile); | |
try | |
{ | |
if(!EnsureSerializedScriptAsync(script, binFile).Result) | |
{ | |
Native.ThrowIfError((JavaScriptErrorCode)_executor.SerializeScriptFromFile(script, binPath)); | |
} | |
var result = _executor.RunSerializedScriptFromFile(binPath, script, sourceUrl); | |
Native.ThrowIfError((JavaScriptErrorCode)result.ErrorCode); | |
} | |
catch (JavaScriptScriptException ex) | |
{ | |
var jsonError = JavaScriptValueToJTokenConverter.Convert(ex.Error); | |
var message = jsonError.Value<string>("message"); | |
var stackTrace = jsonError.Value<string>("stack"); | |
throw new Modules.Core.JavaScriptException(message ?? ex.Message, stackTrace, ex); | |
} | |
} | |
private static async Task<bool> EnsureSerializedScriptAsync(string scriptFile, string binFile) | |
{ | |
var localFolder = ApplicationData.Current.LocalFolder; | |
var scriptItem = await StorageFile.GetFileFromPathAsync(scriptFile); | |
var scriptItemProps = await scriptItem.GetBasicPropertiesAsync(); | |
var item = await localFolder.TryGetItemAsync(binFile); | |
if (item != null) | |
{ | |
var props = await item.GetBasicPropertiesAsync(); | |
return props.DateModified > scriptItemProps.DateModified; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment