public static void CreateNewPalette(Type type, string palette) { AssertFewEntities(type); var dic = Database.RetrieveAllLite(type).Select(l => new ChartColorEntity { Related = (Lite <Entity>)l }).ToDictionary(a => a.Related); dic.SetRange(Database.Query <ChartColorEntity>().Where(c => c.Related.EntityType == type).ToDictionary(a => a.Related)); var list = dic.Values.ToList(); var cats = Palettes.GetOrThrow(palette).Split(' '); for (int i = 0; i < list.Count; i++) { list[i].Color = ColorEmbedded.FromRGBHex(cats[i % cats.Length]); } list.SaveList(); }
static Mapping() { MappingRepository <bool> .Mapping = GetValue(ctx => ParseHtmlBool(ctx.Input)); MappingRepository <byte> .Mapping = GetValue(ctx => byte.Parse(ctx.Input)); MappingRepository <sbyte> .Mapping = GetValue(ctx => sbyte.Parse(ctx.Input)); MappingRepository <short> .Mapping = GetValue(ctx => short.Parse(ctx.Input)); MappingRepository <ushort> .Mapping = GetValue(ctx => ushort.Parse(ctx.Input)); MappingRepository <int> .Mapping = GetValue(ctx => int.Parse(ctx.Input)); MappingRepository <uint> .Mapping = GetValue(ctx => uint.Parse(ctx.Input)); MappingRepository <long> .Mapping = GetValue(ctx => long.Parse(ctx.Input)); MappingRepository <ulong> .Mapping = GetValue(ctx => ulong.Parse(ctx.Input)); MappingRepository <float> .Mapping = GetValue(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (float)ReflectionTools.ParsePercentage(ctx.Input, typeof(float), CultureInfo.CurrentCulture) : float.Parse(ctx.Input)); MappingRepository <double> .Mapping = GetValue(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (double)ReflectionTools.ParsePercentage(ctx.Input, typeof(double), CultureInfo.CurrentCulture) : double.Parse(ctx.Input)); MappingRepository <decimal> .Mapping = GetValue(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (decimal)ReflectionTools.ParsePercentage(ctx.Input, typeof(decimal), CultureInfo.CurrentCulture) : decimal.Parse(ctx.Input)); MappingRepository <DateTime> .Mapping = GetValue(ctx => DateTime.Parse(ctx.HasInput ? ctx.Input : ctx.Inputs["Date"] + " " + ctx.Inputs["Time"]).FromUserInterface()); MappingRepository <Guid> .Mapping = GetValue(ctx => Guid.Parse(ctx.Input)); MappingRepository <TimeSpan> .Mapping = GetValue(ctx => { var dateFormatAttr = ctx.PropertyRoute.PropertyInfo.GetCustomAttribute <TimeSpanDateFormatAttribute>(); if (dateFormatAttr != null) { return(DateTime.ParseExact(ctx.Input, dateFormatAttr.Format, CultureInfo.CurrentCulture).TimeOfDay); } else { return(TimeSpan.Parse(ctx.Input)); } }); MappingRepository <SqlHierarchyId> .Mapping = GetValue(ctx => SqlHierarchyId.Parse(ctx.Input)); MappingRepository <ColorEmbedded> .Mapping = GetValue(ctx => ctx.Input.HasText() ? ColorEmbedded.FromRGBHex(ctx.Input) : null); MappingRepository <bool?> .Mapping = GetValueNullable(ctx => ParseHtmlBool(ctx.Input)); MappingRepository <byte?> .Mapping = GetValueNullable(ctx => byte.Parse(ctx.Input)); MappingRepository <sbyte?> .Mapping = GetValueNullable(ctx => sbyte.Parse(ctx.Input)); MappingRepository <short?> .Mapping = GetValueNullable(ctx => short.Parse(ctx.Input)); MappingRepository <ushort?> .Mapping = GetValueNullable(ctx => ushort.Parse(ctx.Input)); MappingRepository <int?> .Mapping = GetValueNullable(ctx => int.Parse(ctx.Input)); MappingRepository <uint?> .Mapping = GetValueNullable(ctx => uint.Parse(ctx.Input)); MappingRepository <long?> .Mapping = GetValueNullable(ctx => long.Parse(ctx.Input)); MappingRepository <ulong?> .Mapping = GetValueNullable(ctx => ulong.Parse(ctx.Input)); MappingRepository <float?> .Mapping = GetValueNullable(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (float)ReflectionTools.ParsePercentage(ctx.Input, typeof(float), CultureInfo.CurrentCulture) : float.Parse(ctx.Input)); MappingRepository <double?> .Mapping = GetValueNullable(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (double)ReflectionTools.ParsePercentage(ctx.Input, typeof(double), CultureInfo.CurrentCulture) : double.Parse(ctx.Input)); MappingRepository <decimal?> .Mapping = GetValueNullable(ctx => ctx.PropertyRoute != null && ReflectionTools.IsPercentage(Reflector.FormatString(ctx.PropertyRoute), CultureInfo.CurrentCulture) ? (decimal)ReflectionTools.ParsePercentage(ctx.Input, typeof(decimal), CultureInfo.CurrentCulture) : decimal.Parse(ctx.Input)); MappingRepository <DateTime?> .Mapping = GetValue(ctx => { var input = ctx.HasInput ? ctx.Input : " ".CombineIfNotEmpty(ctx.Inputs["Date"], ctx.Inputs["Time"]); if (input.HasText()) { DateTime dt; if (DateTime.TryParse(input, out dt)) { return(dt.FromUserInterface()); } else { SmartDateTimeSpan sts; string error = SmartDateTimeSpan.TryParse(input, out sts); if (!error.HasText()) { dt = sts.ToDateTime(); return(dt.FromUserInterface()); } } } return((DateTime?)null); //return input.HasText() ? DateTime.Parse(input).FromUserInterface() : (DateTime?)null; }); MappingRepository <Guid?> .Mapping = GetValueNullable(ctx => Guid.Parse(ctx.Input)); MappingRepository <TimeSpan?> .Mapping = GetValue(ctx => { if (ctx.Input.IsNullOrEmpty()) { return((TimeSpan?)null); } var dateFormatAttr = ctx.PropertyRoute.PropertyInfo.GetCustomAttribute <TimeSpanDateFormatAttribute>(); if (dateFormatAttr != null) { return(DateTime.ParseExact(ctx.Input, dateFormatAttr.Format, CultureInfo.CurrentCulture).TimeOfDay); } else { return(TimeSpan.Parse(ctx.Input)); } }); MappingRepository <string> .Mapping = StringTrim; }