void commitCurrentSnapshot(UIImage snapshotImage, string description, NSData gameData) { if (!CurrentSnapshotMetadata.IsOpen) { // Perhaps we could be harsher here and make this an assertion Console.WriteLine("Error trying to commit a snapshot. You must always open it first"); return; } var dataChange = new SnapshotMetadataChange(); dataChange.SnapshotDescription = description; // Done for simplicity, but this should really record the time since you last // opened a snapshot int millsSinceaPreviousSnapshotWasOpened = 10000; dataChange.PlayedTime = CurrentSnapshotMetadata.PlayedTime + millsSinceaPreviousSnapshotWasOpened; dataChange.CoverImage = new SnapshotMetadataChangeCoverImage(snapshotImage); CurrentSnapshotMetadata.Commit(dataChange, gameData, async delegate(SnapshotMetadata snapshotMetadata, NSError error) { if (error == null) { Console.WriteLine("Successfully saved {0}", snapshotMetadata); // Once our game has been saved, we should re-open it, so it's ready for saving again. LoadSnapshot(snapshotMetadata); } else { Console.WriteLine("Error while saving: {0}", error); } }); }
public override void commitAndClose(OnSnapshotResultListener listener, SnapshotMetadataChange metadataChange) { var change = metadataChange as SnapshotMetadataChangeAndroid; mClient.CallClientApi("Commit snapshot", () => { mClient.GHManager.CallGmsApiWithResult( "games.Games", "Snapshots", "commitAndClose", new OnCommitResultProxy(mClient, listener), mObj, change.javaObj() ); }, null); }
/** * If you want to attempt a manual merge, this would be the way to do it. * Note that in general, manual merges work best if you have "union" type of merges where taking * the highest value is the best resolution (i.e. high scores on a level, stars per level, * unlocked levels, etc.) */ void resolveSnapshot(SnapshotMetadata conflictingSnapshotBase, SnapshotMetadata conflictingSnapshotRemote, string conflictId) { Console.WriteLine("Resolving snapshot conflicts: {0} >> {1}", conflictingSnapshotBase, conflictingSnapshotRemote); conflictingSnapshotBase.Read(async delegate(NSData baseData, NSError baseError) { if (baseError == null) { conflictingSnapshotRemote.Read(async delegate(NSData remoteData, NSError remoteError) { if (remoteError == null) { var baseInv = StarInventory.FromCloudData(baseData); var remoteInv = StarInventory.FromCloudData(remoteData); var merged = new StarInventory(); for (int world = 1; world <= 20; world++) { for (int level = 1; level <= 12; level++) { var baseStars = baseInv.GetStars(world, level); var remoteStars = remoteInv.GetStars(world, level); var maxStars = Math.Max(baseStars, remoteStars); if (maxStars > 0) { Console.WriteLine("Level {0}-{1} had {2} stars on base, {3} stars on remote. Merging to {4}", world, level, baseStars, remoteStars, maxStars); merged.SetStars(maxStars, world, level); } } } // We have a merged data set, we need to create a merged metadata change var change = new SnapshotMetadataChange(); change.SnapshotDescription = "Merged save data"; change.PlayedTime = Math.Max(conflictingSnapshotBase.PlayedTime, conflictingSnapshotRemote.PlayedTime); var mergedData = merged.GetCloudData(); // [base resolveWithMetadataChange:change conflictId:conflictId data:mergedData completionHandler:^(GPGSnapshotMetadata *snapshotMetadata, NSError *error) { // if (!error) { // // Once we're done, we need to re-read the returned snapshot in case there are further // // conflicts waiting to be merged // [self loadSnapshot:snapshotMetadata]; // } // }]; } }); } }); }
protected override void CallDispose(HandleRef selfPointer) { SnapshotMetadataChange.SnapshotMetadataChange_Dispose(selfPointer); }
public static async Task <ISnapshotsOpenSnapshotResult> ResolveConflictAsync(this ISnapshots api, GoogleApiClient apiClient, string conflictId, string snapshotId, SnapshotMetadataChange metadataChange, ISnapshotContents snapshotContents) { return((await api.ResolveConflict(apiClient, conflictId, snapshotId, metadataChange, snapshotContents)).JavaCast <ISnapshotsOpenSnapshotResult> ()); }
public static async Task <ISnapshotsCommitSnapshotResult> CommitAndCloseAsync(this ISnapshots api, GoogleApiClient apiClient, ISnapshot snapshot, SnapshotMetadataChange metadataChange) { return((await api.CommitAndClose(apiClient, snapshot, metadataChange)).JavaCast <ISnapshotsCommitSnapshotResult> ()); }
public abstract void commitAndClose(OnSnapshotResultListener listener, SnapshotMetadataChange metadataChange);