void CordovaBrowser_Loaded(object sender, RoutedEventArgs e)
{
this.bmHelper.ScrollDisabled = this.DisableBouncyScrolling;
if (DesignerProperties.IsInDesignTool)
{
return;
}
// prevents refreshing web control to initial state during pages transitions
if (this.IsBrowserInitialized) return;
this.domStorageHelper = new DOMStorageHelper(this.CordovaBrowser);
try
{
// Before we possibly clean the ISO-Store, we need to grab our generated UUID, so we can rewrite it after.
string deviceUUID = "";
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
try
{
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);
using (StreamReader reader = new StreamReader(fileStream))
{
deviceUUID = reader.ReadLine();
}
}
catch (Exception /*ex*/)
{
deviceUUID = Guid.NewGuid().ToString();
}
Debug.WriteLine("Updating IsolatedStorage for APP:DeviceID :: " + deviceUUID);
IsolatedStorageFileStream file = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Create, FileAccess.Write, appStorage);
using (StreamWriter writeFile = new StreamWriter(file))
{
writeFile.WriteLine(deviceUUID);
writeFile.Close();
}
}
/*
* 11/08/12 Ruslan Kokorev
* Copying files to isolated storage is no more required in WP8. WebBrowser control now works with files located in XAP.
*/
//StreamResourceInfo streamInfo = Application.GetResourceStream(new Uri("CordovaSourceDictionary.xml", UriKind.Relative));
//if (streamInfo != null)
//{
// StreamReader sr = new StreamReader(streamInfo.Stream);
// //This will Read Keys Collection for the xml file
// XDocument document = XDocument.Parse(sr.ReadToEnd());
// var files = from results in document.Descendants("FilePath")
// select new
// {
// path = (string)results.Attribute("Value")
// };
// StreamResourceInfo fileResourceStreamInfo;
// using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
// {
// foreach (var file in files)
// {
// fileResourceStreamInfo = Application.GetResourceStream(new Uri(file.path, UriKind.Relative));
// if (fileResourceStreamInfo != null)
// {
// using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
// {
// byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
// string strBaseDir = AppRoot + file.path.Substring(0, file.path.LastIndexOf(System.IO.Path.DirectorySeparatorChar));
// if (!appStorage.DirectoryExists(strBaseDir))
// {
// Debug.WriteLine("INFO: Creating Directory :: " + strBaseDir);
// appStorage.CreateDirectory(strBaseDir);
// }
// // This will truncate/overwrite an existing file, or
// using (IsolatedStorageFileStream outFile = appStorage.OpenFile(AppRoot + file.path, FileMode.Create))
// {
// Debug.WriteLine("INFO: Writing data for " + AppRoot + file.path + " and length = " + data.Length);
// using (var writer = new BinaryWriter(outFile))
// {
// writer.Write(data);
// }
// }
// }
// }
// else
// {
// Debug.WriteLine("ERROR: Failed to write file :: " + file.path + " did you forget to add it to the project?");
// }
// }
// }
//}
CordovaBrowser.Navigate(StartPageUri);
IsBrowserInitialized = true;
AttachHardwareButtonHandlers();
}
catch (Exception ex)
{
Debug.WriteLine("ERROR: Exception in CordovaBrowser_Loaded :: {0}", ex.Message);
}
}