private void GetHierarchyRecords( RecordHierarchy parentHierarchy, IList<dynamic> records, IEnumerable<EntityHierarchy> subHierarchies, string foreignKey = null, string foreignKeyValue = null) { foreach (var hierarchy in subHierarchies) { var prefix = hierarchy.Alias.Trim("[]".ToCharArray()) + "_"; foreach (var record in records) { var recordDict = (IDictionary<string, object>)record; var rowData = new DataRow(recordDict, hierarchy.Entity, prefix); if (!rowData.KeyValue.IsNullOrEmpty()) { var subRecord = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = hierarchy.Entity.ToString(rowData), SubRecordsHierarchies = new List<RecordHierarchy>() }; if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.KeyValue == subRecord.KeyValue) == null && (foreignKey.IsNullOrEmpty() || recordDict[foreignKey].ToStringSafe() == foreignKeyValue)) { parentHierarchy.SubRecordsHierarchies.Add(subRecord); GetHierarchyRecords( subRecord, records, hierarchy.SubHierarchies, prefix + hierarchy.Entity.Key.ColumnName, rowData.KeyValue); } } } } }
private RecordHierarchy GetHierarchyRecords( IList<IDictionary<string, object>> records, EntityHierarchy hierarchy) { var baseRecord = records.FirstOrDefault(); var prefix = hierarchy.Alias.Undecorate() + "_"; var rowData = new DataRow(baseRecord, hierarchy.Entity, prefix); var recordHierarchy = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = hierarchy.Entity.ToString(rowData), SubRecordsHierarchies = new List<RecordHierarchy>() }; GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies); return recordHierarchy; }
private RecordHierarchy GetHierarchyRecords( IList<dynamic> records, EntityHierarchy hierarchy) { var baseRecord = records.FirstOrDefault(); var prefix = hierarchy.Alias.Trim("[]".ToCharArray()) + "_"; var rowData = new DataRow(baseRecord, hierarchy.Entity, prefix); var recordHierarchy = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = hierarchy.Entity.ToString(rowData), SubRecordsHierarchies = new List<RecordHierarchy>() }; GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies); return recordHierarchy; }
private void GetHierarchyRecords( RecordHierarchy parentHierarchy, IList<IDictionary<string, object>> records, IEnumerable<EntityHierarchy> subHierarchies, IList<string> foreignKey = null, IList<string> foreignKeyValue = null) { foreach (var hierarchy in subHierarchies) { var prefix = hierarchy.Alias.Undecorate() + "_"; foreach (var record in records) { var rowData = new DataRow(record, hierarchy.Entity, prefix); if (!rowData.KeyValue.IsNullOrEmpty()) { var subRecord = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = hierarchy.Entity.ToString(rowData), SubRecordsHierarchies = new List<RecordHierarchy>() }; if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeyValue == subRecord.JoinedKeyValue) == null && Matching(record, foreignKey, foreignKeyValue)) { parentHierarchy.SubRecordsHierarchies.Add(subRecord); GetHierarchyRecords( subRecord, records, hierarchy.SubHierarchies, hierarchy.Entity.Key.Select(x => prefix + x.ColumnName.Undecorate()).ToList(), rowData.KeyValue); } } } } }
/// <summary> /// Get display name for entity /// </summary> /// <param name="row">Instance value</param> /// <returns>Display name</returns> public string ToString(DataRow row) { // check if has to string attribute if (!RecordDisplayFormat.IsNullOrEmpty()) { var result = RecordDisplayFormat; foreach (var cellValue in row.Values) { result = result.Replace("{" + cellValue.Property.Name + "}", cellValue.AsString); } return result; } // if not check if has ToString() method if (HasToStringMethod) { var methodInfo = Type.GetMethod("ToString"); var instance = Activator.CreateInstance(Type, null); foreach (var cellValue in row.Values .Where(x => !x.Property.IsForeignKey || (x.Property.IsForeignKey && x.Property.TypeInfo.IsSystemType))) { var propertyInfo = Type.GetProperty(cellValue.Property.Name); propertyInfo.SetValue(instance, cellValue.Raw); } var result = methodInfo.Invoke(instance, null); return result.ToStringSafe(); } // if not get first matching property // %Name%, %Title%, %Description%, %Value% // if not found any property use KeyValue var possibleNames = new List<string> { "name", "title", "description", "value" }; var value = String.Empty; foreach (var possibleName in possibleNames) { var cell = row.Values .FirstOrDefault(x => x.Property.Name.ToLower().Contains(possibleName)); if (cell != null) { value = cell.AsString; break; } } if (value.IsNullOrEmpty()) { return "#" + row.JoinedKeyValue; } return value; }
public ChangeRow(DataRow row) { Row = row; }