Created
May 11, 2016 22:41
-
-
Save LanceMcCarthy/2eaa9adcff2b1dd2dc5812c47f19803b to your computer and use it in GitHub Desktop.
VCD helper
This file contains hidden or 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
public static class VoiceCommandUtilites | |
{ | |
private static int loadAttempts; | |
public static async Task InstallVoiceCommandFile() | |
{ | |
if (loadAttempts > 0) | |
{ | |
Debug.WriteLine($"-------Voice Commands load attempt max reached. loadAttempt: {loadAttempts}--------"); | |
return; | |
} | |
var alreadyLoaded = HaveVoiceCommandsBeenLoaded(); | |
Debug.WriteLine($"-------HaveVoiceCommandsBeenLoaded() {alreadyLoaded}--------"); | |
if (alreadyLoaded) | |
return; | |
try | |
{ | |
StorageFile vcdFile = null; | |
try | |
{ | |
//vcdFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///VoiceCommands.xml")); | |
vcdFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///VoiceCommandsRedstone.xml")); | |
//vcdFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///VoiceCommandsTest.xml")); | |
if (vcdFile == null) | |
{ | |
Debug.WriteLine($"-------vcdFile was null, returning--------"); | |
ApplicationData.Current.LocalSettings.Values["VoiceCommandsLoaded"] = false; | |
return; | |
} | |
Debug.WriteLine($"-------VoiceCommands.xml is present--------"); | |
} | |
catch (FileNotFoundException ex) | |
{ | |
Debug.WriteLine($"-------VoiceCommands.xml FileNotFound Exception-------- \r\nError: {ex.Message}"); | |
ApplicationData.Current.LocalSettings.Values["VoiceCommandsLoaded"] = false; | |
return; | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine($"-------VoiceCommandUtilities Exception--------" + | |
$"\r\nStorageFile.GetFileFromApplicationUriAsync " + | |
$"\r\nError: {ex.Message}"); | |
ApplicationData.Current.LocalSettings.Values["VoiceCommandsLoaded"] = false; | |
return; | |
} | |
try | |
{ | |
await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdFile); | |
Debug.WriteLine($"-------VoiceCommands loaded--------"); | |
ApplicationData.Current.LocalSettings.Values["VoiceCommandsLoaded"] = true; | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine($"-------VoiceCommandDefinitionManager.InstallCommandSetsFromStorageFileAsync() Exception--------\r\n-------Exception Message: {ex.Message}"); | |
} | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine($"-------VoiceCommandUtilites.InstallVoiceCommandFile() Exception--------{ex}"); | |
ApplicationData.Current.LocalSettings.Values["VoiceCommandsLoaded"] = false; | |
} | |
finally | |
{ | |
loadAttempts++; | |
} | |
} | |
private static bool HaveVoiceCommandsBeenLoaded() | |
{ | |
try | |
{ | |
object val; | |
if (ApplicationData.Current.LocalSettings.Values.TryGetValue("VoiceCommandsLoaded", out val)) | |
{ | |
return (bool) val; | |
} | |
} | |
catch (Exception ex) | |
{ | |
Debug.WriteLine($"------HaveVoiceCommandsBeenLoaded() Exception-------\r\n{ex}"); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment