public static void SynchronizeTypes(Assembly assembly, string directoryName) { string assemblyName = assembly.GetName().Name !; HashSet <string> newNames = (from t in assembly.GetTypes() let opts = LocalizedAssembly.GetDescriptionOptions(t) where opts != DescriptionOptions.None select t.Name).ToHashSet(); Dictionary <string, string?> memory = new Dictionary <string, string?>(); foreach (var fileName in Directory.EnumerateFiles(directoryName, "{0}.*.xml".FormatWith(assemblyName))) { var doc = XDocument.Load(fileName); HashSet <string> oldNames = doc.Element("Translations").Elements("Type").Select(t => t.Attribute("Name").Value).ToHashSet(); Dictionary <string, string> replacements = AskForReplacementsWithMemory(newNames.ToHashSet(), oldNames.ToHashSet(), memory, replacementKey: Path.GetFileNameWithoutExtension(fileName) !); //cloning var culture = fileName.After(assemblyName + ".").Before(".xml"); var locAssem = LocalizedAssembly.FromXml(assembly, CultureInfo.GetCultureInfo(culture), doc, replacements?.Inverse()); locAssem.ToXml().Save(fileName); } }
private static MvcHtmlString InternalComboBox(HtmlHelper helper, ValueLine valueLine, Type uType, Enum value) { if (valueLine.ReadOnly) { MvcHtmlString result = MvcHtmlString.Empty; if (valueLine.WriteHiddenOnReadonly) { result = result.Concat(HiddenWithoutId(valueLine.Prefix, valueLine.UntypedValue.ToString())); } string str = value == null ? null : LocalizedAssembly.GetDescriptionOptions(uType).IsSet(DescriptionOptions.Members) ? value.NiceToString() : value.ToString(); return(result.Concat(helper.FormControlStatic(valueLine, valueLine.Prefix, str, valueLine.ValueHtmlProps))); } StringBuilder sb = new StringBuilder(); List <SelectListItem> items = valueLine.EnumComboItems ?? valueLine.CreateComboItems(); if (value != null) { items.Where(e => e.Value == value.ToString()) .SingleOrDefaultEx()?.Do(s => s.Selected = true); } valueLine.ValueHtmlProps.AddCssClass("form-control"); return(helper.SafeDropDownList(valueLine.Prefix, items, valueLine.ValueHtmlProps)); }
public static Dictionary <string, TypeInfoTS> GetEnums(IEnumerable <Type> allTypes) { var queries = QueryLogic.Queries; var result = (from type in allTypes where type.IsEnum let descOptions = LocalizedAssembly.GetDescriptionOptions(type) where descOptions != DescriptionOptions.None let kind = type.Name.EndsWith("Query") ? KindOfType.Query : type.Name.EndsWith("Message") ? KindOfType.Message : KindOfType.Enum select KVP.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS { Kind = kind, FullName = type.FullName, NiceName = descOptions.HasFlag(DescriptionOptions.Description) ? type.NiceName() : null, Members = type.GetFields(staticFlags) .Where(fi => kind != KindOfType.Query || queries.QueryDefined(fi.GetValue(null))) .ToDictionary(fi => fi.Name, fi => OnAddFieldInfoExtension(new MemberInfoTS { NiceName = fi.NiceName(), IsIgnoredEnum = kind == KindOfType.Enum && fi.HasAttribute <IgnoreAttribute>() }, fi)), }, type))).ToDictionaryEx("enums"); return(result); }
public LocalizableTypeTS(Type type) { var options = LocalizedAssembly.GetDescriptionOptions(type); this.type = type.Name; hasDescription = options.IsSet(DescriptionOptions.Description); hasPluralDescription = options.IsSet(DescriptionOptions.PluralDescription); hasMembers = options.IsSet(DescriptionOptions.Members); hasGender = options.IsSet(DescriptionOptions.Gender); }
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 TranslationController.LocalizableTypeTS ToLocalizableTypeTS(this Type type) { var options = LocalizedAssembly.GetDescriptionOptions(type); return(new TranslationController.LocalizableTypeTS() { type = type.Name, hasDescription = options.IsSet(DescriptionOptions.Description), hasPluralDescription = options.IsSet(DescriptionOptions.PluralDescription), hasMembers = options.IsSet(DescriptionOptions.Members), hasGender = options.IsSet(DescriptionOptions.Gender), }); }
static QuerySettings() { FormatRules = new List <FormatterRule> { new FormatterRule("Default", c => true, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Left, null)), new FormatterRule("Checkbox", c => c.Type.UnNullify() == typeof(bool), c => b => FormatTools.CheckBoxTemplate(b, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("Enum", c => c.Type.UnNullify().IsEnum, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Left, LocalizedAssembly.GetDescriptionOptions(c.Type.UnNullify()).IsSet(DescriptionOptions.Members) ? Converters.EnumDescription: null)), new FormatterRule("Number", c => Reflector.IsNumber(c.Type), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("DateTime", c => c.Type.UnNullify() == typeof(DateTime), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("TimeSpan", c => c.Type.UnNullify() == typeof(TimeSpan), c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, c.Format == null ? null : ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, null)))), new FormatterRule("Lite", c => c.Type.IsLite(), //Not on entities! c => b => FormatTools.LightEntityLineTemplate(b)), new FormatterRule("NumberUnit", c => Reflector.IsNumber(c.Type) && c.Unit != null, c => b => FormatTools.TextBlockTemplate(b, TextAlignment.Right, ConverterFactory.New(Reflector.GetPropertyFormatter(c.Format, c.Unit)))) }; PropertyFormatters = new Dictionary <PropertyRoute, Func <Binding, DataTemplate> >(); }