Synchronize() public method

Synchronize Dataset between local storage and remote storage.
public Synchronize ( ) : void
return void
コード例 #1
0
    private bool HandleDatasetMerged(Dataset localDataset, List<string> mergedDatasetNames)
    {
		Debug.LogWarning("Sync merge");

        if (mergeInCourse) {
			Debug.LogWarning ("Already in a merge");
			return false;            
        }

		//This variable can be used to hold the game from actually starting
        //and show a loading indicator to the user meanwhile
        mergeInCourse = true;
        
        //Delete the merged datasets and just keep the local data
        foreach (string name in mergedDatasetNames) {

			Dataset mergedDataset = syncManager.OpenOrCreateDataset(name);
			//mergedDataset.Delete(); //Remove any data we could have from a previous execution of this handler
            //Lambda function to delete the dataset after fetching it
            EventHandler<SyncSuccessEvent> lambda =null;
            Debug.Log ("fetching dataset to merge: " + name);
            lambda = (object sender, SyncSuccessEvent e) => { 
                //Actual merge code: We join the local characters and the remote characters into a new single dataset.
                List<string> allCharacters = new List<string>();
				ICollection<string> existingCharacters = localDataset.GetAll().Values;
				ICollection<string> newCharacters = mergedDataset.GetAll().Values;
				Debug.LogWarning(localDataset.Metadata.DatasetName + ": " + existingCharacters.Count);
				Debug.LogWarning(mergedDataset.Metadata.DatasetName + ": " + newCharacters.Count);
                allCharacters.AddRange(existingCharacters);
                allCharacters.AddRange(newCharacters);
                int i = 0;
                foreach (string characterString in allCharacters) {
					localDataset.Put (indexToKey(i++), characterString);
                }

                Debug.Log ("deleting merged dataset: " + name);
				mergedDataset.Delete(); //Delete the dataset locally
				mergedDataset.OnSyncSuccess -= lambda; //We don't want this callback to be fired again
				mergedDataset.OnSyncSuccess += (object s2, SyncSuccessEvent e2) => {
                    Debug.Log ("merge comleted (dataset merged and deleted)");
                    mergeInCourse = false;
					localDataset.Synchronize(); //Continue the sync operation that was interrupted by the merge
                };
				mergedDataset.Synchronize(); //Synchronize it as deleted, failing to do so will leave us in an inconsistent state

            };
            
			mergedDataset.OnSyncSuccess += lambda;
			mergedDataset.Synchronize(); //Asnchronously fetch the dataset
        }

        // returning true allows the Synchronize to continue and false cancels it
		return true;
    }