private static void SaveItem(IDataItem dataItem, ISharedPreferencesEditor editor, IDictionary <string, object> allPrefs) { DataMap dataMap = DataMapItem.FromDataItem(dataItem).DataMap; if (dataMap.KeySet().Count == 0 && dataItem.Uri.PathSegments.LastOrDefault() != PrefListener.KEY_SYNC_DONE) { // Testing has shown that when an item is deleted from the Data API, it // will often come through as an empty TYPE_CHANGED rather than a TYPE_DELETED. DeleteItem(dataItem.Uri, editor, allPrefs); } else { foreach (var key in dataMap.KeySet()) { Java.Lang.Object value = dataMap.Get(key); if (value == null) { if (allPrefs != null && value.Equals(allPrefs.ContainsKey(key))) { editor.Remove(key); } continue; } if (allPrefs != null && allPrefs.TryGetValue(key, out var found) && value.Equals(found)) { // No change to value. continue; } if (key.Equals(KEY_TIMESTAMP)) { continue; } if (value is Java.Lang.Boolean) { editor.PutBoolean(key, (bool)value); } else if (value is Java.Lang.Float) { editor.PutFloat(key, (float)value); } else if (value is Java.Lang.Integer) { editor.PutInt(key, (int)value); } else if (value is Java.Lang.Long) { editor.PutLong(key, (long)value); } else if (value is Java.Lang.String) { editor.PutString(key, (string)value); } else if (value is Java.Lang.Object javaValue && javaValue.Class.SimpleName == "String[]") { if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) { editor.PutStringSet(key, (string[])value); } }
public Object GetMap(DataMap map) { return(map.Get(_propertyName)); }
private DataMap ConstructPropertyTypes(String eventTypeName, DataMap propertyTypesGiven, EventAdapterService eventAdapterService) { var propertyTypes = new Dictionary <string, object>(); var eventType = eventAdapterService.GetEventTypeByName(eventTypeName); if (eventType == null) { if (propertyTypesGiven != null) { eventAdapterService.AddNestableMapType(eventTypeName, new Dictionary <string, object>(propertyTypesGiven), null, true, true, true, false, false); } return(propertyTypesGiven); } if (eventType.UnderlyingType != typeof(DataMap)) { _beanType = eventType.UnderlyingType; } if (propertyTypesGiven != null && eventType.PropertyNames.Length != propertyTypesGiven.Count) { // allow this scenario for beans as we may want to bring in a subset of properties if (_beanType != null) { return(propertyTypesGiven); } throw new EPException("Event type " + eventTypeName + " has already been declared with a different number of parameters"); } foreach (var property in eventType.PropertyNames) { Type type; try { type = eventType.GetPropertyType(property); } catch (PropertyAccessException e) { // thrown if trying to access an invalid property on an EventBean throw new EPException(e); } if (propertyTypesGiven != null && propertyTypesGiven.Get(property) == null) { throw new EPException("Event type " + eventTypeName + "has already been declared with different parameters"); } if (propertyTypesGiven != null && !Equals(propertyTypesGiven.Get(property), type)) { throw new EPException("Event type " + eventTypeName + "has already been declared with a different type for property " + property); } // we can't set read-only properties for bean if (eventType.UnderlyingType != typeof(DataMap)) { var magicType = MagicType.GetCachedType(_beanType); var magicProperty = magicType.ResolveProperty(property, PropertyResolutionStyle.CASE_SENSITIVE); if (magicProperty == null) { continue; } if (!magicProperty.CanWrite) { if (propertyTypesGiven == null) { continue; } else { throw new EPException("Event type " + eventTypeName + "property " + property + " is read only"); } } } propertyTypes[property] = type; } // flatten nested types var flattenPropertyTypes = new Dictionary <string, object>(); foreach (var prop in propertyTypes) { var name = prop.Key; var type = prop.Value; var asType = type as Type; if ((asType != null) && (asType.IsGenericStringDictionary()) && (eventType is MapEventType)) { var mapEventType = (MapEventType)eventType; var nested = (DataMap)mapEventType.Types.Get(name); foreach (var nestedProperty in nested.Keys) { flattenPropertyTypes.Put(name + "." + nestedProperty, nested.Get(nestedProperty)); } } else if (asType != null) { if (asType.IsNullable()) { asType = Nullable.GetUnderlyingType(asType); } if ((!asType.IsPrimitive) && (asType != typeof(string))) { var magicType = MagicType.GetCachedType(asType); foreach (var magicProperty in magicType.GetAllProperties(false)) { if (magicProperty.CanWrite) { flattenPropertyTypes[name + '.' + magicProperty.Name] = magicProperty.PropertyType; } } } else { flattenPropertyTypes[name] = type; } } else { flattenPropertyTypes[name] = type; } } return(flattenPropertyTypes); }
public bool IsMapExistsProperty(DataMap map) { Object value = map.Get(_fieldName); return(BaseNestableEventUtil.IsExistsIndexedValue(value, _index)); }
public Object GetMap(DataMap map) { Object value = map.Get(_fieldName); return(BaseNestableEventUtil.GetIndexedValue(value, _index)); }
private Object GetMapInternal(DataMap map, String providedKey) { Object value = map.Get(_fieldName); return(BaseNestableEventUtil.GetMappedPropertyValue(value, providedKey)); }
public bool IsMapExistsProperty(DataMap asMap) { var value = asMap.Get(_fieldName); return(BaseNestableEventUtil.GetMappedPropertyExists(value, _key)); }