private void SaveCallback(IAsyncResult result) { StorageContainer container = StorageDevice.EndOpenContainer(result); SaveGameRequest saveGameRequest = (SaveGameRequest)result.AsyncState; // Overwrite existing save. if (container.FileExists(saveGameRequest.SaveName)) { container.DeleteFile(saveGameRequest.SaveName); } // Create the file. Stream stream = container.CreateFile(saveGameRequest.SaveName); // Convert the object to XML data and put it in the stream. XmlSerializer serializer = new XmlSerializer(saveGameRequest.SaveType); serializer.Serialize(stream, saveGameRequest.SaveData); // Close the file. stream.Close(); // Dispose the container, to commit changes. container.Dispose(); }
private bool DoSave(SaveGameRequest saveGameRequest) { // If we have a storage device: if (StorageDevice != null && StorageDevice.IsConnected) { IAsyncResult result = StorageDevice.BeginOpenContainer(saveGameRequest.ContainerName, SaveCallback, saveGameRequest); return(true); } return(false); }
public void Save(SaveGameRequest saveGameRequest) { lock (this) { SaveGameRequests.Enqueue(saveGameRequest); } if (!IsStorageDeviceLoaded && !IsStorageDeviceLoading) { RequestStorageDevice = true; } }
private void UpdateStorageRequests() { #if XBOX StorageThread.SetProcessorAffinity(4); #endif SaveGameRequest sg = null; LoadGameRequest lg = null; while (true) { if (RequestStorageDevice) { RequestDevice(); RequestStorageDevice = false; } if (IsStorageDeviceLoaded) { lock (this) { if (SaveGameRequests.Count > 0) { sg = SaveGameRequests.Dequeue(); } } Thread.Sleep(ThreadSleepMilliseconds); if (sg != null) { if (!DoSave(sg)) { lock (this) { SaveGameRequests.Enqueue(sg); } Thread.Sleep(ThreadSleepMilliseconds); } else { sg = null; } } lock (this) { if (LoadGameRequests.Count > 0) { lg = LoadGameRequests.Dequeue(); } } Thread.Sleep(ThreadSleepMilliseconds); if (lg != null) { if (!DoLoad(lg)) { lock (this) { LoadGameRequests.Enqueue(lg); } Thread.Sleep(ThreadSleepMilliseconds); } else { lg = null; } } } } }