private Dictionary <string, IBuffer> LoadDataHelper(string containerName, string[] blobsToRead) { var container = this.gameSaveProvider.CreateContainer(containerName); var resultBuffers = new Dictionary <string, IBuffer>(); GameSaveBlobGetResult loadResult = container.GetAsync(blobsToRead).AsTask().Result; if (loadResult.Status == GameSaveErrorStatus.Ok) { foreach (var blobName in blobsToRead) { IBuffer loadedBuffer; loadResult.Value.TryGetValue(blobName, out loadedBuffer); if (loadedBuffer == null && XboxLiveServicesSettings.Instance.DebugLogsOn) { Debug.LogFormat("An Exception Occured: Didn't find expected blob \"{0}\" in the loaded data.", blobName); return(null); } resultBuffers.Add(blobName, loadedBuffer); } return(resultBuffers); } else { if (XboxLiveServicesSettings.Instance.DebugLogsOn) { Debug.LogFormat("An Exception Occured: Loading Data failed. Error Status: {0}", loadResult.Status); } return(null); } }
public async Task <LoadDataResult> LoadData() { if (m_saveProvider == null) { throw new InvalidOperationException("The save system is not initialized."); } GameSaveContainer container = m_saveProvider.CreateContainer(c_saveContainerName); string[] blobsToRead = new string[] { c_saveBlobName }; // GetAsync allocates a new Dictionary to hold the retrieved data. You can also use ReadAsync // to provide your own preallocated Dictionary. GameSaveBlobGetResult result = await container.GetAsync(blobsToRead); int loadedData = 0; if (result.Status == GameSaveErrorStatus.Ok) { IBuffer loadedBuffer; result.Value.TryGetValue(c_saveBlobName, out loadedBuffer); if (loadedBuffer == null) { throw new Exception(String.Format("Didn't find expected blob \"{0}\" in the loaded data.", c_saveBlobName)); } DataReader reader = DataReader.FromBuffer(loadedBuffer); loadedData = reader.ReadInt32(); } return(new LoadDataResult(result.Status, loadedData)); }
public static async Task <string> Load(string filename) { string loadedData = null; const string c_saveBlobName = "data"; string c_saveContainerName = filename; //Now you have a GameSaveProvider //Next you need to call CreateContainer to get a GameSaveContainer var gameSaveProvider = await GetGameSaveProvider(); if (gameSaveProvider == null) { return(null); } GameSaveContainer gameSaveContainer = gameSaveProvider.CreateContainer(c_saveContainerName); //Parameter //string name (name of the GameSaveContainer Created) //form an array of strings containing the blob names you would like to read. string[] blobsToRead = new string[] { c_saveBlobName }; // GetAsync allocates a new Dictionary to hold the retrieved data. You can also use ReadAsync // to provide your own preallocated Dictionary. GameSaveBlobGetResult result = await gameSaveContainer.GetAsync(blobsToRead); //Check status to make sure data was read from the container if (result.Status == GameSaveErrorStatus.Ok) { //prepare a buffer to receive blob IBuffer loadedBuffer; //retrieve the named blob from the GetAsync result, place it in loaded buffer. result.Value.TryGetValue(c_saveBlobName, out loadedBuffer); if (loadedBuffer == null) { throw new Exception(String.Format("Didn't find expected blob \"{0}\" in the loaded data.", c_saveBlobName)); } DataReader reader = DataReader.FromBuffer(loadedBuffer); uint bytesToRead = reader.ReadUInt32(); loadedData = reader.ReadString(bytesToRead); Debug.WriteLine("XboxLiveConnectedStorage :: Loaded Data - " + loadedData); return(loadedData); } else { return(null); } }
private Dictionary <string, IBuffer> LoadDataHelper(string containerName, string[] blobsToRead) { var container = this.gameSaveProvider.CreateContainer(containerName); var resultBuffers = new Dictionary <string, IBuffer>(); GameSaveBlobGetResult loadResult = container.GetAsync(blobsToRead).AsTask().Result; if (loadResult.Status == GameSaveErrorStatus.Ok) { foreach (var blobName in blobsToRead) { IBuffer loadedBuffer; loadResult.Value.TryGetValue(blobName, out loadedBuffer); if (loadedBuffer == null) { var errorMessage = string.Format("An Exception Occured: Didn't find expected blob \"{0}\" in the loaded data.", blobName); ExceptionManager.Instance.ThrowException( ExceptionSource.GameSaveManager, ExceptionType.BlobNotFound, new Exception(errorMessage)); return(null); } resultBuffers.Add(blobName, loadedBuffer); } return(resultBuffers); } else { var errorMessage = string.Format("An Exception Occured: Loading Data failed. Error Status: {0}", loadResult.Status); ExceptionManager.Instance.ThrowException( ExceptionSource.GameSaveManager, ExceptionType.LoadingDataFailed, new Exception(errorMessage)); return(null); } }