/// <summary> /// Converts a given element to a json string, dependent on the column definition as given by the /// ColumnCreationResult /// </summary> /// <param name="element"></param> /// <param name="creatorResult"></param> /// <returns></returns> private Dictionary<string, object> ConvertToJson(IObject element, ColumnCreationResult creatorResult) { var result = new Dictionary<string, object>(); foreach (var property in creatorResult.Properties .Where(property => element.isSet(property))) { var propertyAsString = ColumnCreator.ConvertPropertyToColumnName(property); var propertyValue = element.get(property); if (creatorResult.ColumnsOnProperty[property].isEnumeration) { if (propertyValue is IEnumerable && !(propertyValue is string)) { var list = new List<object>(); foreach (var listValue in (propertyValue as IEnumerable)) { var asElement = listValue as IElement; string url; if (asElement != null) { url = asElement.GetUri(); } else { url = null; } list.Add(new { u = url, v = listValue == null ? "null" : _resolution.GetName(listValue) }); } result[propertyAsString] = list; } else { result[propertyAsString] = propertyValue == null ? "null" : _resolution.GetName(propertyValue); } } else { result[propertyAsString] = propertyValue == null ? "null" : _resolution.GetName(propertyValue); } } return result; }
public ColumnCreationResult FindColumnsForItem(object item) { var result = new ColumnCreationResult(); EvaluateColumnsForItem(result, item); return result; }
public ColumnCreationResult FindColumnsForTable(IReflectiveSequence elements) { var result = new ColumnCreationResult(); foreach (var item in elements) { EvaluateColumnsForItem(result, item); } return result; }
private void EvaluateColumnsForItem(ColumnCreationResult result, object item) { // First phase: Get the properties by using the metaclass var asElement = item as IElement; var metaClass = asElement?.metaclass; if (metaClass != null) { var dataLayer = _dataLayerLogic?.GetDataLayerOfObject(metaClass); var metaLayer = _dataLayerLogic?.GetMetaLayerFor(dataLayer); var uml = _dataLayerLogic?.Get<_UML>(metaLayer); if (uml != null && metaClass.isSet(_UML._Classification._Classifier.attribute)) { var properties = metaClass.get(_UML._Classification._Classifier.attribute) as IEnumerable; if (properties != null) { foreach (var property in properties.Cast<IObject>()) { var propertyName = property.get("name").ToString(); FieldData column; if (!result.ColumnsOnProperty.TryGetValue(propertyName, out column)) { column = new TextFieldData { name = ConvertPropertyToColumnName(property), title = property.get(_UML._CommonStructure._NamedElement.name).ToString() }; result.ColumnsOnProperty[propertyName] = column; } } } } } // Second phase: Get properties by the object iself // This item does not have a metaclass and also no properties, so we try to find them by using the item var itemAsAllProperties = item as IObjectAllProperties; if (itemAsAllProperties != null) { var properties = itemAsAllProperties.getPropertiesBeingSet(); foreach (var property in properties) { FieldData column; if (!result.ColumnsOnProperty.TryGetValue(property, out column)) { column = new TextFieldData { name = ConvertPropertyToColumnName(property), title = _nameResolution == null ? property.ToString() : _nameResolution.GetName(property) }; result.ColumnsOnProperty[property] = column; } var value = ((IObject) item).get(property); column.isEnumeration |= value is IEnumerable && !(value is string); } } }