// This is our callback for monitoring key-value store changes void KeyValueStoreDidChangeExternally(string keyValues) { // No need to keep processing if no one is watching lock (keyValueStoreDataRegisteredComponents) { if (keyValueStoreDataRegisteredComponents.Count == 0) return; } string[] keyComponents = keyValues.Split('.'); // Get heading parameters int reason = int.Parse(keyComponents[0]); int keyCount = int.Parse(keyComponents[1]); int[] keyLength = new int[keyCount]; int[] oldValueType = new int[keyCount]; int[] oldValueLength = new int[keyCount]; int[] newValueType = new int[keyCount]; int[] newValueLength = new int[keyCount]; int offset = keyComponents[0].Length + keyComponents[1].Length + 2; // Get types & lengthes for (int i = 0; i < keyCount; i++) { keyLength[i] = int.Parse(keyComponents[i*5 + 2]); oldValueType[i] = int.Parse(keyComponents[i*5 + 3]); oldValueLength[i] = int.Parse(keyComponents[i*5 + 4]); newValueType[i] = int.Parse(keyComponents[i*5 + 5]); newValueLength[i] = int.Parse(keyComponents[i*5 + 6]); offset += keyComponents[i*5 + 2].Length + keyComponents[i*5 + 3].Length + keyComponents[i*5 + 4].Length + keyComponents[i*5 + 5].Length + keyComponents[i*5 + 6].Length + 5; } // Get keys & values JCloudKeyValueChange[] consolidatedKeyValueChangeArray = new JCloudKeyValueChange[keyCount]; for (int i = 0; i < keyCount; i++) { consolidatedKeyValueChangeArray[i] = new JCloudKeyValueChange(); consolidatedKeyValueChangeArray[i].Key = keyValues.Substring(offset, keyLength[i]); offset += keyLength[i]; consolidatedKeyValueChangeArray[i].OldValueType = (JCloudDataValueType)oldValueType[i]; switch (consolidatedKeyValueChangeArray[i].OldValueType) { case JCloudDataValueType.JCloudDataInt: consolidatedKeyValueChangeArray[i].OldValue = int.Parse(keyValues.Substring(offset, oldValueLength[i])); break; case JCloudDataValueType.JCloudDataFloat: consolidatedKeyValueChangeArray[i].OldValue = float.Parse(keyValues.Substring(offset, oldValueLength[i])); break; case JCloudDataValueType.JCloudDataString: consolidatedKeyValueChangeArray[i].OldValue = keyValues.Substring(offset, oldValueLength[i]); break; default: consolidatedKeyValueChangeArray[i].OldValue = null; break; } offset += (oldValueType[i] != 0) ? oldValueLength[i] : 0; consolidatedKeyValueChangeArray[i].NewValueType = (JCloudDataValueType)newValueType[i]; switch (consolidatedKeyValueChangeArray[i].NewValueType) { case JCloudDataValueType.JCloudDataInt: consolidatedKeyValueChangeArray[i].NewValue = int.Parse(keyValues.Substring(offset, newValueLength[i])); break; case JCloudDataValueType.JCloudDataFloat: consolidatedKeyValueChangeArray[i].NewValue = float.Parse(keyValues.Substring(offset, newValueLength[i])); break; case JCloudDataValueType.JCloudDataString: consolidatedKeyValueChangeArray[i].NewValue = keyValues.Substring(offset, newValueLength[i]); break; default: consolidatedKeyValueChangeArray[i].NewValue = null; break; } offset += (newValueType[i] != 0) ? newValueLength[i] : 0; } // Broadcast to all registered components lock (keyValueStoreDataRegisteredComponents) { for (int i = 0; i < keyValueStoreDataRegisteredComponents.Count; i++) { if (keyValueStoreDataRegisteredComponents[i] != null) keyValueStoreDataRegisteredComponents[i].SendMessage("JCloudDataDidChangeExternally", new JCloudDataExternalChange { Reason = (JCloudDataChangeReason)reason, ChangedKeyValues = consolidatedKeyValueChangeArray }); } } }
// This is our callback for monitoring key-value store changes void KeyValueStoreDidChangeExternally(string keyValues) { // No need to keep processing if no one is watching lock (keyValueStoreDataRegisteredComponents) { if (keyValueStoreDataRegisteredComponents.Count == 0) { return; } } string[] keyComponents = keyValues.Split('.'); // Get heading parameters int reason = int.Parse(keyComponents[0]); int keyCount = int.Parse(keyComponents[1]); int[] keyLength = new int[keyCount]; int[] oldValueType = new int[keyCount]; int[] oldValueLength = new int[keyCount]; int[] newValueType = new int[keyCount]; int[] newValueLength = new int[keyCount]; int offset = keyComponents[0].Length + keyComponents[1].Length + 2; // Get types & lengthes for (int i = 0; i < keyCount; i++) { keyLength[i] = int.Parse(keyComponents[i * 5 + 2]); oldValueType[i] = int.Parse(keyComponents[i * 5 + 3]); oldValueLength[i] = int.Parse(keyComponents[i * 5 + 4]); newValueType[i] = int.Parse(keyComponents[i * 5 + 5]); newValueLength[i] = int.Parse(keyComponents[i * 5 + 6]); offset += keyComponents[i * 5 + 2].Length + keyComponents[i * 5 + 3].Length + keyComponents[i * 5 + 4].Length + keyComponents[i * 5 + 5].Length + keyComponents[i * 5 + 6].Length + 5; } // Get keys & values JCloudKeyValueChange[] consolidatedKeyValueChangeArray = new JCloudKeyValueChange[keyCount]; for (int i = 0; i < keyCount; i++) { consolidatedKeyValueChangeArray[i] = new JCloudKeyValueChange(); consolidatedKeyValueChangeArray[i].Key = keyValues.Substring(offset, keyLength[i]); offset += keyLength[i]; consolidatedKeyValueChangeArray[i].OldValueType = (JCloudDataValueType)oldValueType[i]; switch (consolidatedKeyValueChangeArray[i].OldValueType) { case JCloudDataValueType.JCloudDataInt: consolidatedKeyValueChangeArray[i].OldValue = int.Parse(keyValues.Substring(offset, oldValueLength[i])); break; case JCloudDataValueType.JCloudDataFloat: consolidatedKeyValueChangeArray[i].OldValue = float.Parse(keyValues.Substring(offset, oldValueLength[i])); break; case JCloudDataValueType.JCloudDataString: consolidatedKeyValueChangeArray[i].OldValue = keyValues.Substring(offset, oldValueLength[i]); break; default: consolidatedKeyValueChangeArray[i].OldValue = null; break; } offset += (oldValueType[i] != 0) ? oldValueLength[i] : 0; consolidatedKeyValueChangeArray[i].NewValueType = (JCloudDataValueType)newValueType[i]; switch (consolidatedKeyValueChangeArray[i].NewValueType) { case JCloudDataValueType.JCloudDataInt: consolidatedKeyValueChangeArray[i].NewValue = int.Parse(keyValues.Substring(offset, newValueLength[i])); break; case JCloudDataValueType.JCloudDataFloat: consolidatedKeyValueChangeArray[i].NewValue = float.Parse(keyValues.Substring(offset, newValueLength[i])); break; case JCloudDataValueType.JCloudDataString: consolidatedKeyValueChangeArray[i].NewValue = keyValues.Substring(offset, newValueLength[i]); break; default: consolidatedKeyValueChangeArray[i].NewValue = null; break; } offset += (newValueType[i] != 0) ? newValueLength[i] : 0; } // Broadcast to all registered components lock (keyValueStoreDataRegisteredComponents) { for (int i = 0; i < keyValueStoreDataRegisteredComponents.Count; i++) { if (keyValueStoreDataRegisteredComponents[i] != null) { keyValueStoreDataRegisteredComponents[i].SendMessage("JCloudDataDidChangeExternally", new JCloudDataExternalChange { Reason = (JCloudDataChangeReason)reason, ChangedKeyValues = consolidatedKeyValueChangeArray }); } } } }