123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- namespace PRSDesktop.Configuration
- {
- internal class CustomPropertyGrid : DynamicDataGrid<CustomProperty>
- {
- public CustomPropertyGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
- HiddenColumns.Add(x => x.Class);
- HiddenColumns.Add(x => x.Type);
- }
- protected override void DoValidate(CustomProperty[] items, List<string> errors)
- {
- base.DoValidate(items, errors);
- if (items.Any(x => string.IsNullOrWhiteSpace(x.Class)))
- errors.Add("[Class] must not be blank!");
- if (items.Any(x => string.IsNullOrWhiteSpace(x.Name)))
- errors.Add("[Name] must not be blank!");
- if (items.Any(x => string.IsNullOrWhiteSpace(x.Type)))
- errors.Add("[Type] must not be blank!");
- }
- private IEnumerable<Type> FindTypes(Func<Type, bool> predicate)
- {
- if (predicate == null)
- throw new ArgumentNullException(nameof(predicate));
- foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
- if (!assembly.IsDynamic)
- {
- Type[] exportedTypes = null;
- try
- {
- exportedTypes = assembly.GetExportedTypes();
- }
- catch (ReflectionTypeLoadException e)
- {
- exportedTypes = e.Types;
- }
- if (exportedTypes != null)
- foreach (var type in exportedTypes)
- if (predicate(type))
- yield return type;
- }
- }
- public override void ConfigureColumns(DynamicGridColumns columns /*, bool dolookups = true */)
- {
- base.ConfigureColumns(columns /*, dolookups */);
- var column = columns.FirstOrDefault(x => x.ColumnName.Equals("Class"));
- if (column != null)
- {
- column.Lookups.Clear();
- var classes = CoreUtils.TypeList(
- new[]
- {
- typeof(Setout).Assembly
- },
- myType =>
- myType.IsClass
- && !myType.IsAbstract
- && !myType.IsGenericType
- && myType.IsSubclassOf(typeof(Entity))
- && myType.GetInterfaces().Contains(typeof(IPersistent))
- ).OrderBy(x => x.EntityName()).ToArray();
- foreach (var entity in classes)
- if (ClientFactory.IsSupported(entity))
- column.Lookups[entity.EntityName()] = entity;
- }
- column = columns.FirstOrDefault(x => x.ColumnName.Equals("Type"));
- if (column != null)
- {
- column.Lookups.Clear();
- column.Lookups[typeof(string).EntityName()] = typeof(string).EntityName();
- column.Lookups[typeof(int).EntityName()] = typeof(int).EntityName();
- column.Lookups[typeof(double).EntityName()] = typeof(double).EntityName();
- column.Lookups[typeof(bool).EntityName()] = typeof(bool).EntityName();
- column.Lookups[typeof(DateTime).EntityName()] = typeof(DateTime).EntityName();
- }
- }
- protected override void Reload(Filters<CustomProperty> criteria, Columns<CustomProperty> columns, ref SortOrder<CustomProperty> sort,
- Action<CoreTable, Exception> action)
- {
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|