public void WriteToConfig(VentanaUser newUser) { Task.Run( async() => { string newFile = JsonUtility.ToJson(newUser, true); Debug.Log("NEW: " + newFile); try { //Get local folder StorageFolder storageFolder = ApplicationData.Current.LocalFolder; //Create file StorageFile textFileForWrite = await storageFolder.CreateFileAsync("VentanaConfig.json", CreationCollisionOption.ReplaceExisting); //Write to file await FileIO.WriteTextAsync(textFileForWrite, newFile); //Get file StorageFile textFileForRead = await storageFolder.GetFileAsync("VentanaConfig.json"); //Read file string plainText = ""; plainText = await FileIO.ReadTextAsync(textFileForRead); Debug.Log("New file written: " + plainText); } catch (Exception ex) { Debug.Log(ex.Message); } }).Wait(); #endif }
// Use this for initialization IEnumerator Start() { StringBuilder url = new StringBuilder(Args.HOLOHUB_ADDRESS); url.Append("/holoconfig/"); UnityWebRequest holoHubRequest = UnityWebRequest.Get(url.ToString()); yield return(holoHubRequest.Send()); if (!holoHubRequest.isError) { try { ModelController mc = ModelController.Instance; Debug.Log(holoHubRequest.downloadHandler.text); VentanaUser user = JsonUtility.FromJson <VentanaUser>(holoHubRequest.downloadHandler.text); mc.WriteToConfig(user); mc.initializeUser(); } catch (Exception e) { Debug.LogWarning(e.Message + " \nHoloHub Response Val: " + holoHubRequest.downloadHandler.text); } } else { Debug.Log("WWW Error: " + holoHubRequest.error); } }
public void initializeUser() { user = null; modelDictionary = null; VentanaModelDictionary vmDictionary = new VentanaModelDictionary(); string json = ReadFromConfig(); user = JsonUtility.FromJson <VentanaUser>(json); if (user == null) { Debug.Log("<color=yellow>Warning: Missing or malformed Ventana configuration file"); } foreach (VentanaMarkObject vmo in user.VentanaMarks) { vmDictionary.Add(Convert.ToInt32(vmo.id, 16), vmo.path); } modelDictionary = vmDictionary; }
private VentanaModelDictionary initializeModelMapping() { VentanaModelDictionary vmDictionary = new VentanaModelDictionary(); VentanaUser jsonObject = null; string json = ReadFromConfig(); jsonObject = JsonUtility.FromJson <VentanaUser>(json); if (jsonObject == null) { Debug.Log("<color=yellow>Warning: Missing or malformed Ventana configuration file"); return(null); } foreach (VentanaMarkObject vmo in jsonObject.VentanaMarks) { vmDictionary.Add(Convert.ToInt32(vmo.id, 16), vmo.path); } return(vmDictionary); }
public void WriteToConfig(VentanaUser newUser) { //string fileData = ""; string fileName = GetFilePath("Ventana/VentanaConfig.json"); UnityEngine.Windows.File.WriteAllBytes(fileName, Encoding.ASCII.GetBytes(JsonUtility.ToJson(newUser, true)));