public FieldConfigurator MarkAvailable <TManifest>(string label, AvailabilityType availabilityType, bool suppressFieldDiscovery = false) where TManifest : Manifest { EnsureAvailableDataCrate(); var manifestType = ManifestDiscovery.Default.GetManifestType <TManifest>(); var fields = new List <FieldDTO>(); if (!suppressFieldDiscovery) { var members = Fr8ReflectionHelper.GetMembers(typeof(TManifest)) .Where(x => Fr8ReflectionHelper.IsPrimitiveType(x.MemberType)) .Where(x => Fr8ReflectionHelper.CheckAttributeOrTrue <ManifestFieldAttribute>(x, y => !y.IsHidden)); foreach (var memberAccessor in members) { fields.Add(new FieldDTO(memberAccessor.Name)); } } _availableData.AddOrUpdate(new CrateDescriptionDTO { Availability = availabilityType, Label = label, ManifestId = manifestType.Id, ManifestType = manifestType.Type, ProducedBy = _owner, SourceActivityId = _sourceActivityId.ToString(), Fields = fields }); return(new FieldConfigurator(fields)); }
private static object GetValue(Crate crate, string fieldKey) { if (crate.IsOfType <StandardTableDataCM>()) { var tableCrate = crate.Get <StandardTableDataCM>(); if (tableCrate.FirstRowHeaders && tableCrate.Table.Count > 1) { return(tableCrate.Table[1].Row.FirstOrDefault(a => a.Cell.Key == fieldKey)?.Cell?.Value); } } if (crate.IsKnownManifest) { var data = crate.Get(); object value = null; Fr8ReflectionHelper.VisitPropertiesRecursive(data, (instance, member) => { if (!member.CanRead) { return(Fr8ReflectionHelper.PropertiesVisitorOp.Continue); } var manifestAttr = member.GetCustomAttribute <ManifestFieldAttribute>(); if (manifestAttr != null && manifestAttr.IsHidden) { return(Fr8ReflectionHelper.PropertiesVisitorOp.Continue); } var tempValue = member.GetValue(instance); if (member.Name == fieldKey) { value = tempValue; return(Fr8ReflectionHelper.PropertiesVisitorOp.Terminate); } var keyValuePair = tempValue as KeyValueDTO; if (keyValuePair != null) { if (keyValuePair.Key == fieldKey) { value = keyValuePair.Value; return(Fr8ReflectionHelper.PropertiesVisitorOp.Terminate); } return(Fr8ReflectionHelper.PropertiesVisitorOp.SkipBranch); } return(Fr8ReflectionHelper.PropertiesVisitorOp.Continue); }); return(value); } // do nothing for uknown manifests return(null); }
internal static int?GetDataListSize(Crate crateToProcess) { var tableData = crateToProcess.ManifestType.Id == (int)MT.StandardTableData ? crateToProcess.Get <StandardTableDataCM>() : null; if (tableData != null) { return(tableData.FirstRowHeaders ? Math.Max(0, tableData.Table.Count - 1) : tableData.Table.Count); } var array = crateToProcess.IsKnownManifest ? Fr8ReflectionHelper.FindFirstArray(crateToProcess.Get()) : Fr8ReflectionHelper.FindFirstArray(crateToProcess.GetRaw()); return(array?.Length); }
internal static void RestoreDynamicControlsFrom <TActivityUi>(this TActivityUi source, StandardConfigurationControlsCM destination) { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } var dynamicControlsCollection = Fr8ReflectionHelper.GetMembers(source.GetType()).Where(x => x.CanRead && x.GetCustomAttribute <DynamicControlsAttribute>() != null && Fr8ReflectionHelper.CheckIfMemberIsCollectionOf <IControlDefinition>(x)) .ToDictionary(x => x.Name, x => x); if (dynamicControlsCollection.Count > 0) { foreach (var control in destination.Controls) { var nameAndOwner = GetDynamicControlNameAndOwner(control.Name); if (String.IsNullOrEmpty(nameAndOwner.Item2)) { continue; } IMemberAccessor member; if (!dynamicControlsCollection.TryGetValue(nameAndOwner.Item2, out member)) { continue; } var controlsCollection = (IList)member.GetValue(source); if (controlsCollection == null && (!member.CanWrite || member.MemberType.IsAbstract || member.MemberType.IsInterface)) { continue; } if (controlsCollection == null) { controlsCollection = (IList)Activator.CreateInstance(member.MemberType); member.SetValue(source, controlsCollection); } control.Name = nameAndOwner.Item1; controlsCollection.Add(control); } } }
private void FillOwnerByControl() { foreach (var collectionProperty in Fr8ReflectionHelper.GetMembers(typeof(TActivityUi)).Where(x => x.CanRead && x.GetCustomAttribute <DynamicControlsAttribute>() != null && Fr8ReflectionHelper.CheckIfMemberIsCollectionOf <IControlDefinition>(x))) { var collection = collectionProperty.GetValue(_activityUi) as IEnumerable <IControlDefinition>; if (collection == null) { continue; } foreach (var control in collection) { _ownerNameByControl.Add(control, collectionProperty.Name); } } }
private IEnumerable <KeyValueDTO> GetFields(IEnumerable <Crate> crates) { var fields = new List <KeyValueDTO>(); foreach (var crate in crates) { //let's pass unknown manifests for now if (!crate.IsKnownManifest) { continue; } fields.AddRange(Fr8ReflectionHelper.FindFieldsRecursive(crate.Get())); } return(fields); }
internal static void SaveDynamicControlsTo <TActivityUi>(this TActivityUi source, StandardConfigurationControlsCM destination) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var insertIndex = 0; foreach (var member in Fr8ReflectionHelper.GetMembers(source.GetType()).Where(x => x.CanRead)) { if (member.GetCustomAttribute <DynamicControlsAttribute>() != null && Fr8ReflectionHelper.CheckIfMemberIsCollectionOf <IControlDefinition>(member)) { var collection = member.GetValue(source) as IList; if (collection != null) { foreach (var control in collection.Cast <object>().OfType <ControlDefinitionDTO>()) { control.Name = GetDynamicControlName(control.Name, member.Name); destination.Controls.Insert(insertIndex, control); insertIndex++; } } } var controlDef = member.GetValue(source) as IControlDefinition; if (!String.IsNullOrWhiteSpace(controlDef?.Name)) { for (int i = 0; i < destination.Controls.Count; i++) { if (destination.Controls[i].Name == controlDef.Name) { insertIndex = i + 1; break; } } } } }
static AuthorizationTokenDO() { Members = Fr8ReflectionHelper.GetMembers(typeof(AuthorizationTokenDO)).ToArray(); }