Ejemplo n.º 1
0
        private async void UpdateCloudCopy( )
        {
            if (IsCloudUpdateRequired && !Syncing && (DatabaseProvider.GoogleApiClient?.IsConnected ?? false))
            {
                Syncing = true;
                IsCloudUpdateRequired = false;
#if __ANDROID__
                LastSyncedTimestamp = await CloudCopyState.Update(Gold, Stage, Damage, DatabaseProvider.GoogleApiClient);

                DatabaseProvider.Write(DATABASE_LAST_SYNCED_TIMESTAMP, LastSyncedTimestamp);
#endif
                Syncing = false;
            }
        }
Ejemplo n.º 2
0
        public async static Task <long> Update(long Gold, long Stage, float Damage, GoogleApiClient googleApiClient)
        {
            ISnapshot snapshot = await GetSnapshot(googleApiClient);

            snapshot.SnapshotContents.WriteBytes(CloudCopyState.GetData(Gold, Stage, Damage));

            SnapshotMetadataChangeBuilder metadataChangeBuilder = new SnapshotMetadataChangeBuilder( );

            metadataChangeBuilder.SetCoverImage(Assets.Icon);
            metadataChangeBuilder.SetDescription($"Time Titan Stage {Stage}, {Gold} Gold, {Damage} Damage");
            metadataChangeBuilder.SetProgressValue(Stage);
            ISnapshotMetadataChange metadataChange = metadataChangeBuilder.Build( );

            ISnapshotsCommitSnapshotResult commitSnapshotResult = await GamesClass.Snapshots.CommitAndCloseAsync(googleApiClient, snapshot, metadataChange);

            return(commitSnapshotResult.SnapshotMetadata.LastModifiedTimestamp);
        }
Ejemplo n.º 3
0
 public bool IsAhead(CloudCopyState conflictingState)
 {
     if (Damage > conflictingState.Damage)
     {
         return(true);
     }
     else if (Stage > conflictingState.Stage)
     {
         return(true);
     }
     else if (Stage < conflictingState.Stage)
     {
         return(false);
     }
     else if (Gold > conflictingState.Gold)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
        private async void Sync( )
        {
            ISnapshot snapshot = await CloudCopyState.GetSnapshot(DatabaseProvider.GoogleApiClient);

            CloudCopyState cloudCopyState = new CloudCopyState(snapshot);

            if (cloudCopyState.Timestamp < LastSyncedTimestamp || cloudCopyState.Damage < Damage || cloudCopyState.Stage < Stage)
            {
                IsCloudUpdateRequired = true;
                UpdateCloudCopy( );
            }
            else
            {
                Gold  = cloudCopyState.Gold;
                Stage = cloudCopyState.Stage;
                LastSyncedTimestamp = cloudCopyState.Timestamp;
            }

            DatabaseProvider.Write(DATABASE_GOLD_KEY, Gold);
            DatabaseProvider.Write(DATABASE_LAST_SYNCED_TIMESTAMP, LastSyncedTimestamp);

            updateCloudCopyTimer.Change(0, SECONDS_BETWEEN_CLOUDUPDATES * 1000);
        }
Ejemplo n.º 5
0
        private async static Task <ISnapshot> GetSnapshotFromResult(GoogleApiClient googleApiClient, ISnapshotsOpenSnapshotResult openSnapshotResult)
        {
            switch (openSnapshotResult.Status.StatusCode)
            {
            case GamesStatusCodes.StatusOk:
                return(openSnapshotResult.Snapshot);

            case GamesStatusCodes.StatusSnapshotConflict:
                CloudCopyState state    = new CloudCopyState(openSnapshotResult.Snapshot);
                CloudCopyState conflict = new CloudCopyState(openSnapshotResult.ConflictingSnapshot);
                ISnapshotsOpenSnapshotResult resolveSnapshotResult;
                if (conflict.IsAhead(state))
                {
                    resolveSnapshotResult = await GamesClass.Snapshots.ResolveConflictAsync(googleApiClient, openSnapshotResult.ConflictId, openSnapshotResult.ConflictingSnapshot);
                }
                else
                {
                    resolveSnapshotResult = await GamesClass.Snapshots.ResolveConflictAsync(googleApiClient, openSnapshotResult.ConflictId, openSnapshotResult.Snapshot);
                }
                return(await GetSnapshotFromResult(googleApiClient, resolveSnapshotResult));
            }
            return(null);
        }