internal static SchemaMapInfo GetMapInfo() { var getStats = GetRuntimeStats(); var s = Schema.Current; var nodes = (from t in s.Tables.Values where s.IsAllowed(t.Type, true) == null let type = EnumEntity.Extract(t.Type) ?? t.Type select new TableInfo { typeName = TypeLogic.GetCleanName(t.Type), niceName = type.NiceName(), tableName = t.Name.ToString(), columns = t.Columns.Count, entityData = EntityKindCache.GetEntityData(t.Type), entityKind = EntityKindCache.GetEntityKind(t.Type), entityBaseType = GetEntityBaseType(t.Type), @namespace = type.Namespace !, rows = getStats.TryGetC(t.Name)?.rows, total_size_kb = getStats.TryGetC(t.Name)?.total_size_kb, rows_history = t.SystemVersioned?.Let(sv => getStats.TryGetC(sv.TableName)?.rows), total_size_kb_history = t.SystemVersioned?.Let(sv => getStats.TryGetC(sv.TableName)?.total_size_kb), mlistTables = t.TablesMList().Select(ml => new MListTableInfo { niceName = ml.PropertyRoute.PropertyInfo !.NiceName(), tableName = ml.Name.ToString(), rows = getStats.TryGetC(ml.Name)?.rows, total_size_kb = getStats.TryGetC(ml.Name)?.total_size_kb, history_rows = ml.SystemVersioned?.Let(sv => getStats.TryGetC(sv.TableName)?.rows), history_total_size_kb = ml.SystemVersioned?.Let(sv => getStats.TryGetC(sv.TableName)?.total_size_kb), columns = ml.Columns.Count, }).ToList()
public static Dictionary <string, TypeInfoTS> GetEntities(IEnumerable <Type> allTypes) { var models = (from type in allTypes where typeof(ModelEntity).IsAssignableFrom(type) && !type.IsAbstract select type).ToList(); var queries = QueryLogic.Queries; var schema = Schema.Current; var settings = Schema.Current.Settings; var result = (from type in TypeLogic.TypeToEntity.Keys.Concat(models) where !type.IsEnumEntity() && !ReflectionServer.ExcludeTypes.Contains(type) let descOptions = LocalizedAssembly.GetDescriptionOptions(type) let allOperations = !type.IsEntity() ? null : OperationLogic.GetAllOperationInfos(type) select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS { Kind = KindOfType.Entity, FullName = type.FullName, NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null, NicePluralName = descOptions.HasFlag(DescriptionOptions.PluralDescription) ? type.NicePluralName() : null, Gender = descOptions.HasFlag(DescriptionOptions.Gender) ? type.GetGender().ToString() : null, EntityKind = type.IsIEntity() ? EntityKindCache.GetEntityKind(type) : (EntityKind?)null, EntityData = type.IsIEntity() ? EntityKindCache.GetEntityData(type) : (EntityData?)null, IsLowPopulation = type.IsIEntity() ? EntityKindCache.IsLowPopulation(type) : false, IsSystemVersioned = type.IsIEntity() ? schema.Table(type).SystemVersioned != null : false, ToStringFunction = typeof(Symbol).IsAssignableFrom(type) ? null : LambdaToJavascriptConverter.ToJavascript(ExpressionCleaner.GetFieldExpansion(type, miToString)), QueryDefined = queries.QueryDefined(type), Members = PropertyRoute.GenerateRoutes(type).Where(pr => InTypeScript(pr)) .ToDictionary(p => p.PropertyString(), p => { var mi = new MemberInfoTS { NiceName = p.PropertyInfo?.NiceName(), TypeNiceName = GetTypeNiceName(p.PropertyInfo?.PropertyType), Format = p.PropertyRouteType == PropertyRouteType.FieldOrProperty ? Reflector.FormatString(p) : null, IsReadOnly = !IsId(p) && (p.PropertyInfo?.IsReadOnly() ?? false), Unit = UnitAttribute.GetTranslation(p.PropertyInfo?.GetCustomAttribute <UnitAttribute>()?.UnitName), Type = new TypeReferenceTS(IsId(p) ? PrimaryKey.Type(type).Nullify() : p.PropertyInfo?.PropertyType, p.Type.IsMList() ? p.Add("Item").TryGetImplementations() : p.TryGetImplementations()), IsMultiline = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.MultiLine ?? false, MaxLength = Validator.TryGetPropertyValidator(p)?.Validators.OfType <StringLengthValidatorAttribute>().FirstOrDefault()?.Max.DefaultToNull(-1), PreserveOrder = settings.FieldAttributes(p)?.OfType <PreserveOrderAttribute>().Any() ?? false, }; return(OnAddPropertyRouteExtension(mi, p)); }), Operations = allOperations == null ? null : allOperations.ToDictionary(oi => oi.OperationSymbol.Key, oi => OnAddOperationExtension(new OperationInfoTS(oi), oi, type)), RequiresEntityPack = allOperations != null && allOperations.Any(oi => oi.HasCanExecute != null), }, type))).ToDictionaryEx("entities"); return(result); }
public static void CacheTable <T>(SchemaBuilder sb) where T : Entity { AssertStarted(sb); EntityData data = EntityDataOverrides.TryGetS(typeof(T)) ?? EntityKindCache.GetEntityData(typeof(T)); if (data == EntityData.Master) { var cc = new CacheController <T>(sb.Schema); controllers.AddOrThrow(typeof(T), cc, "{0} already registered"); TryCacheSubTables(typeof(T), sb); } else //data == EntityData.Transactional { controllers.AddOrThrow(typeof(T), null, "{0} already registered"); TryCacheSubTables(typeof(T), sb); } }
internal static void SetDefaultOrder(FindOptions findOptions, QueryDescription description) { var entityColumn = description.Columns.SingleOrDefaultEx(cd => cd.IsEntity); if (findOptions.OrderOptions.IsNullOrEmpty() && !entityColumn.Implementations.Value.IsByAll) { var orderType = entityColumn.Implementations.Value.Types.All(t => EntityKindCache.GetEntityData(t) == EntityData.Master) ? OrderType.Ascending : OrderType.Descending; var settings = Finder.QuerySettings(description.QueryName); var column = description.Columns.SingleOrDefaultEx(c => c.Name == settings.DefaultOrderColumn); if (column != null) { findOptions.OrderOptions.Add(new OrderOption { Token = new ColumnToken(column, description.QueryName), ColumnName = column.Name, OrderType = orderType }); } } }
static void Schema_SchemaCompleted(SchemaBuilder sb) { foreach (var kvp in VirtualMList.RegisteredVirtualMLists) { var type = kvp.Key; if (controllers.TryGetCN(type) != null) { foreach (var vml in kvp.Value) { var rType = vml.Value.BackReferenceRoute.RootType; EntityData data = EntityDataOverrides.TryGetS(rType) ?? EntityKindCache.GetEntityData(rType); if (data == EntityData.Transactional) { throw new InvalidOperationException($"Type {rType.Name} should be {nameof(EntityData)}.{nameof(EntityData.Master)} because is in a virtual MList of {type.Name} (Master and cached)"); } TryCacheTable(sb, rType); dependencies.Add(type, rType); inverseDependencies.Add(rType, type); } } } foreach (var cont in controllers.Values.NotNull()) { cont.BuildCachedTable(); } foreach (var cont in controllers.Values.NotNull()) { cont.CachedTable.SchemaCompleted(); } }
internal static SchemaMapInfo GetMapInfo(out List <MapColorProvider> providers) { var getStats = GetRuntimeStats(); var nodes = (from t in Schema.Current.Tables.Values let type = EnumEntity.Extract(t.Type) ?? t.Type select new TableInfo { findUrl = Finder.IsFindable(t.Type) ? Finder.FindRoute(t.Type) : null, webTypeName = Navigator.ResolveWebTypeName(t.Type), niceName = type.NiceName(), tableName = t.Name.ToString(), columns = t.Columns.Count, entityData = EntityKindCache.GetEntityData(t.Type), entityKind = EntityKindCache.GetEntityKind(t.Type), entityBaseType = GetEntityBaseType(t.Type), @namespace = type.Namespace, rows = getStats.GetOrThrow(t.Name).rows, total_size_kb = getStats.GetOrThrow(t.Name).total_size_kb, mlistTables = t.TablesMList().Select(ml => new MListTableInfo { niceName = ml.Field.Route.PropertyInfo.NiceName(), tableName = ml.Name.ToString(), rows = getStats.GetOrThrow(t.Name).rows, total_size_kb = getStats.GetOrThrow(t.Name).total_size_kb, columns = ml.Columns.Count, }).ToList() }).ToList(); providers = MapClient.GetColorProviders.GetInvocationListTyped().SelectMany(f => f()).OrderBy(a => a.Order).ToList(); var extraActions = providers.Select(a => a.AddExtra).NotNull().ToList(); if (extraActions.Any()) { foreach (var n in nodes) { foreach (var action in extraActions) { action(n); } } } var normalEdges = (from t in Schema.Current.Tables.Values from kvp in t.DependentTables() where !kvp.Value.IsCollection select new RelationInfo { fromTable = t.Name.ToString(), toTable = kvp.Key.Name.ToString(), lite = kvp.Value.IsLite, nullable = kvp.Value.IsNullable }).ToList(); var mlistEdges = (from t in Schema.Current.Tables.Values from tm in t.TablesMList() from kvp in tm.GetTables() select new RelationInfo { fromTable = tm.Name.ToString(), toTable = kvp.Key.Name.ToString(), lite = kvp.Value.IsLite, nullable = kvp.Value.IsNullable }).ToList(); return(new SchemaMapInfo { tables = nodes, relations = normalEdges.Concat(mlistEdges).ToList() }); }
public void OnLoaded() { if (loaded) { return; } loaded = true; if (FilterColumn.HasText()) { FilterOptions.Add(new FilterOption { ColumnName = FilterColumn, Operation = FilterOperation.EqualTo, Frozen = true, }.Bind(FilterOption.ValueProperty, new Binding("DataContext" + (FilterRoute.HasText() ? "." + FilterRoute : null)) { Source = this })); if (QueryUtils.IsColumnToken(FilterColumn)) { ColumnOptions.Add(new ColumnOption(FilterColumn)); ColumnOptionsMode = ColumnOptionsMode.Remove; } if (this.NotSet(SearchOnLoadProperty)) { SearchOnLoad = true; } } if (OrderOptions.IsNullOrEmpty() && !entityColumn.Implementations.Value.IsByAll) { var orderType = entityColumn.Implementations.Value.Types.All(t => EntityKindCache.GetEntityData(t) == EntityData.Master) ? OrderType.Ascending : OrderType.Descending; var column = Description.Columns.SingleOrDefaultEx(c => c.Name == "Id"); if (column != null) { OrderOptions.Add(new OrderOption(column.Name, orderType)); } } btCreate.ToolTip = SearchMessage.CreateNew0_G.NiceToString() .ForGenderAndNumber(entityColumn.Implementations.Value.Types.FirstOrDefault()?.GetGender() ?? 'm') .FormatWith(entityColumn.Implementations.Value.Types.CommaOr(a => a.NiceName())); if (this.NotSet(SearchControl.NavigateProperty) && Navigate) { Navigate = Implementations.IsByAll ? true : Implementations.Types.Any(t => Navigator.IsNavigable(t, isSearch: true)); } if (this.NotSet(EntityBase.CreateProperty) && Create) { Create = Implementations.IsByAll ? false : Implementations.Types.Any(t => Navigator.IsCreable(t, isSearch: true)); } ColumnOption.SetColumnTokens(ColumnOptions, Description); if (this.CanAddFilters || this.AllowChangeColumns) { headerContextMenu = new ContextMenu(); if (this.CanAddFilters) { headerContextMenu.Items.Add(new MenuItem { Header = SearchMessage.AddFilter.NiceToString() }.Handle(MenuItem.ClickEvent, filterHeader_Click)); } if (this.CanAddFilters && this.AllowChangeColumns) { headerContextMenu.Items.Add(new Separator()); } if (this.AllowChangeColumns) { headerContextMenu.Items.Add(new MenuItem { Header = SearchMessage.Rename.NiceToString() }.Handle(MenuItem.ClickEvent, renameMenu_Click)); headerContextMenu.Items.Add(new MenuItem { Header = EntityControlMessage.Remove.NiceToString() }.Handle(MenuItem.ClickEvent, removeMenu_Click)); } } GenerateListViewColumns(); FilterOption.SetFilterTokens(FilterOptions, Description); filterBuilder.Filters = FilterOptions; ((INotifyCollectionChanged)FilterOptions).CollectionChanged += FilterOptions_CollectionChanged; OrderOption.SetOrderTokens(OrderOptions, Description); SortGridViewColumnHeader.SetColumnAdorners(gvResults, OrderOptions); if (IsVisible) { FillMenuItems(); if (SearchOnLoad) { Search(); } } else { IsVisibleChanged += SearchControl_IsVisibleChanged; } UpdateVisibility(); AutomationProperties.SetName(this, QueryUtils.GetKey(QueryName)); foreach (var item in FilterOptions) { item.BindingValueChanged += new DependencyPropertyChangedEventHandler(item_BindingValueChanged); } }
internal static string GetEntityHelp(Type type) { string typeIs = HelpMessage._0IsA1.NiceToString().ForGenderAndNumber(type.BaseType.GetGender()).FormatWith(type.NiceName(), type.BaseType.NiceName()); string kind = HelpKindMessage.HisMainFunctionIsTo0.NiceToString(GetEntityKindMessage(EntityKindCache.GetEntityKind(type), EntityKindCache.GetEntityData(type), type.GetGender())); return(typeIs + ". " + kind + "."); }