Last active
August 29, 2015 14:00
-
-
Save akyoto/e6b07e714c322f1c9405 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GetKeysAndValues | |
IEnumerator GetKeysAndValues(Bucket bucket) { | |
var getKeysReq = bucket.GetKeys(); | |
yield return getKeysReq.WaitUntilDone(); | |
if(!getKeysReq.isSuccessful) { | |
Debug.LogError("Error querying keys for " + bucket.name); | |
yield break; | |
} | |
keysScrollPosition = Vector2.zero; | |
data = new Dictionary<string, DBValue>(); | |
foreach(var key in getKeysReq.GetKeyEnumerable()) { | |
data[key] = null; | |
StartCoroutine(GetKeyValue(bucket, key)); | |
} | |
currentBucket = bucket; | |
Debug.Log("Active bucket: " + bucket.name); | |
} | |
// GetKeyValue | |
IEnumerator GetKeyValue(Bucket bucket, string key) { | |
// Get the value for the key | |
var getReq = bucket.Get(key); | |
yield return getReq.WaitUntilDone(); | |
if(getReq.isSuccessful) { | |
// Try to deserialize the data to a string. If this does not work, use the raw data. | |
var encoding = getReq.GetEncoding(); | |
if(encoding == Encoding.Json) { | |
var tree = getReq.GetValue<JsonTree>(); | |
data[key] = new DBValue { | |
text = tree.ToString(), | |
tree = tree, | |
encoding = encoding | |
}; | |
} else { | |
data[key] = new DBValue { | |
text = getReq.GetValueRaw(), | |
tree = null, | |
encoding = encoding | |
}; | |
} | |
} else { | |
Debug.LogError("Error querying value for key: " + key); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment