protected List <QueryToken> SubTokensBase(Type type, SubTokensOptions options, Implementations?implementations) { var ut = type.UnNullify(); if (ut == typeof(DateTime)) { return(DateTimeProperties(this, DateTimePrecision.Milliseconds)); } if (ut == typeof(float) || ut == typeof(double) || ut == typeof(decimal)) { return(StepTokens(this, 4)); } if (ut == typeof(int) || ut == typeof(long) || ut == typeof(short)) { return(StepTokens(this, 0)); } Type cleanType = type.CleanType(); if (cleanType.IsIEntity()) { if (implementations.Value.IsByAll) { return(new List <QueryToken>()); // new[] { EntityPropertyToken.IdProperty(this) }; } var onlyType = implementations.Value.Types.Only(); if (onlyType != null && onlyType == cleanType) { return new[] { EntityPropertyToken.IdProperty(this), new EntityToStringToken(this) } }
public static QueryToken Parse(string tokenString, QueryDescription qd, SubTokensOptions options) { if (string.IsNullOrEmpty(tokenString)) { throw new ArgumentNullException("tokenString"); } string[] parts = tokenString.Split('.'); string firstPart = parts.FirstEx(); QueryToken result = SubToken(null, qd, options, firstPart); if (result == null) { throw new FormatException("Column {0} not found on query {1}".FormatWith(firstPart, QueryUtils.GetCleanName(qd.QueryName))); } foreach (var part in parts.Skip(1)) { var newResult = SubToken(result, qd, options, part); if (newResult == null) { throw new FormatException("Token with key '{0}' not found on {1} of query {2}".FormatWith(part, result.FullKey(), QueryUtils.GetCleanName(qd.QueryName))); } result = newResult; } return(result); }
public static QueryToken Parse(string tokenString, QueryDescription qd, SubTokensOptions options) { if (string.IsNullOrEmpty(tokenString)) { throw new ArgumentNullException(nameof(tokenString)); } //https://stackoverflow.com/questions/35418597/split-string-on-the-dot-characters-that-are-not-inside-of-brackets string[] parts = Regex.Split(tokenString, @"\.(?!([^[]*\]|[^(]*\)))"); string firstPart = parts.FirstEx(); QueryToken result = SubToken(null, qd, options, firstPart); if (result == null) { throw new FormatException("Column {0} not found on query {1}".FormatWith(firstPart, QueryUtils.GetKey(qd.QueryName))); } foreach (var part in parts.Skip(1)) { var newResult = SubToken(result, qd, options, part); result = newResult ?? throw new FormatException("Token with key '{0}' not found on {1} of query {2}".FormatWith(part, result.FullKey(), QueryUtils.GetKey(qd.QueryName))); } return(result); }
static List <QueryToken> SubTokensBasic(QueryToken?token, QueryDescription qd, SubTokensOptions options) { if (token == null) { if (MergeEntityColumns != null && !MergeEntityColumns()) { return(qd.Columns.Select(cd => (QueryToken) new ColumnToken(cd, qd.QueryName)).ToList()); } var dictonary = qd.Columns.Where(a => !a.IsEntity).Select(cd => (QueryToken) new ColumnToken(cd, qd.QueryName)).ToDictionary(t => t.Key); var entity = new ColumnToken(qd.Columns.SingleEx(a => a.IsEntity), qd.QueryName); dictonary.Add(entity.Key, entity); foreach (var item in entity.SubTokensInternal(options).OrderByDescending(a => a.Priority).ThenBy(a => a.ToString())) { if (!dictonary.ContainsKey(item.Key)) { dictonary.Add(item.Key, item); } } return(dictonary.Values.ToList()); } else { return(token.SubTokensInternal(options)); } }
public void ParseData(Entity context, QueryDescription description, SubTokensOptions options) { if (Token != null) { Token.ParseData(context, description, options); } }
public void ParseData(ModifiableEntity context, QueryDescription description, SubTokensOptions options) { if (token != null) { token.ParseData(context, description, options & ~SubTokensOptions.CanAnyAll); } }
public static QueryTokenBuilderSettings GetQueryTokenBuilderSettings(QueryDescription qd, SubTokensOptions options) { return new QueryTokenBuilderSettings(qd, options) { ControllerUrl = RouteHelper.New().Action("NewSubTokensCombo", "Word"), Decorators = TemplatingClient.TemplatingDecorators, RequestExtraJSonData = null, }; }
public List <QueryToken> SubTokensInternal(SubTokensOptions options) { return(CachedSubTokensOverride(options).Values .Concat(OnEntityExtension(this)) .Where(t => t.IsAllowed() == null) .OrderByDescending(a => a.Priority) .ThenBy(a => a.ToString()) .ToList()); }
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { return(new List <QueryToken> { new StepRoundingToken(this, RoundingType.Ceil), new StepRoundingToken(this, RoundingType.Floor), new StepRoundingToken(this, RoundingType.Round), new StepRoundingToken(this, RoundingType.RoundMiddle), }); }
public void ParseData(ModifiableEntity context, QueryDescription description, SubTokensOptions options) { try { token = QueryUtils.Parse(TokenString, description, options); } catch (Exception e) { parseException = new FormatException("{0} {1}: {2}\r\n{3}".FormatWith(context.GetType().Name, (context as Entity)?.IdOrNull, context, e.Message), e); } }
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { if (Column.Type.UnNullify() == typeof(DateTime)) { if (Column.PropertyRoutes != null) { DateTimePrecision?precision = Column.PropertyRoutes .Select(pr => Validator.TryGetPropertyValidator(pr.Parent !.Type, pr.PropertyInfo !.Name)?.Validators.OfType <DateTimePrecisionValidatorAttribute>().SingleOrDefaultEx()) .Select(dtp => dtp?.Precision) .Distinct() .Only(); if (precision != null) { return(DateTimeProperties(this, precision.Value).AndHasValue(this)); } } if (Column.Format == "d") { return(DateTimeProperties(this, DateTimePrecision.Days).AndHasValue(this)); } } if (Column.Type.UnNullify() == typeof(double) || Column.Type.UnNullify() == typeof(float) || Column.Type.UnNullify() == typeof(decimal)) { if (Column.PropertyRoutes != null) { int?decimalPlaces = Column.PropertyRoutes .Select(pr => Validator.TryGetPropertyValidator(pr.Parent !.Type, pr.PropertyInfo !.Name)?.Validators.OfType <DecimalsValidatorAttribute>().SingleOrDefaultEx()) .Select(dtp => dtp?.DecimalPlaces) .Distinct() .Only(); if (decimalPlaces != null) { return(StepTokens(this, decimalPlaces.Value).AndHasValue(this)); } } if (Column.Format != null) { return(StepTokens(this, Reflector.NumDecimals(Column.Format)).AndHasValue(this)); } } return(SubTokensBase(Column.Type, options, Column.Implementations)); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { return new List<QueryToken> { new StepMultiplierToken(this, 1), new StepMultiplierToken(this, 1.2m), new StepMultiplierToken(this, 1.5m), new StepMultiplierToken(this, 2), new StepMultiplierToken(this, 2.5m), new StepMultiplierToken(this, 3), new StepMultiplierToken(this, 4), new StepMultiplierToken(this, 5), new StepMultiplierToken(this, 6), new StepMultiplierToken(this, 8), }; }
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { return(new List <QueryToken> { new StepMultiplierToken(this, 1), new StepMultiplierToken(this, 1.2m), new StepMultiplierToken(this, 1.5m), new StepMultiplierToken(this, 2), new StepMultiplierToken(this, 2.5m), new StepMultiplierToken(this, 3), new StepMultiplierToken(this, 4), new StepMultiplierToken(this, 5), new StepMultiplierToken(this, 6), new StepMultiplierToken(this, 8), }); }
public QueryToken SubTokenInternal(string key, SubTokensOptions options) { var result = CachedSubTokensOverride(options).TryGetC(key) ?? OnEntityExtension(this).SingleOrDefaultEx(a => a.Key == key); if (result == null) { return(null); } if (result.IsAllowed() != null) { return(null); } return(result); }
public static QueryToken SubToken(QueryToken token, QueryDescription qd, SubTokensOptions options, string key) { var result = SubTokenBasic(token, qd, options, key); if (result != null) { return(result); } if ((options & SubTokensOptions.CanAggregate) != 0) { return(AggregateTokens(token, qd).SingleOrDefaultEx(a => a.Key == key)); } return(null); }
public static ParsedToken TryParseToken(string tokenString, SubTokensOptions options, QueryDescription qd, ScopedDictionary <string, ValueProviderBase> variables, Action <bool, string> addError) { ParsedToken result = new ParsedToken { String = tokenString }; if (tokenString.StartsWith("$")) { string v = tokenString.TryBefore('.') ?? tokenString; if (!variables.TryGetValue(v, out ValueProviderBase vp)) { addError(false, "Variable '{0}' is not defined at this scope".FormatWith(v)); return(result); } var tvp = vp as TokenValueProvider; if (tvp == null) { addError(false, "Variable '{0}' is not a token".FormatWith(v)); return(result); } if (tvp.ParsedToken.QueryToken == null) { addError(false, "Variable '{0}' is not a correctly parsed".FormatWith(v)); return(result); } var after = tokenString.TryAfter('.'); tokenString = tvp.ParsedToken.QueryToken.FullKey() + (after == null ? null : ("." + after)); } try { result.QueryToken = QueryUtils.Parse(tokenString, qd, options); } catch (Exception ex) { addError(false, ex.Message); } return(result); }
public QueryToken SubTokenInternal(string key, SubTokensOptions options) { var result = CachedSubTokensOverride(options).TryGetC(key) ?? OnEntityExtension(this).SingleOrDefaultEx(a => a.Key == key); if (result == null) { return(null); } string allowed = result.IsAllowed(); if (allowed != null) { throw new UnauthorizedAccessException($"Access to token '{key}' in '{this.FullKey()}' for query '{QueryUtils.GetKey(this.QueryName)}' is not allowed because: {allowed}"); } return(result); }
static QueryToken SubTokenBasic(QueryToken token, QueryDescription qd, SubTokensOptions options, string key) { if (token == null) { var column = qd.Columns.SingleOrDefaultEx(a => a.Name == key); if (column == null) { return(null); } return(new ColumnToken(column, qd.QueryName)); } else { return(token.SubTokenInternal(key, options)); } }
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { var type = this.Type; if (type.UnNullify() == typeof(DateTime)) { PropertyRoute route = this.GetPropertyRoute(); if (route != null) { var att = Validator.TryGetPropertyValidator(route.Parent.Type, route.PropertyInfo.Name)?.Validators .OfType <DateTimePrecisionValidatorAttribute>().SingleOrDefaultEx(); if (att != null) { return(DateTimeProperties(this, att.Precision).AndHasValue(this)); } } } if (type.UnNullify() == typeof(double) || type.UnNullify() == typeof(float) || type.UnNullify() == typeof(decimal)) { PropertyRoute route = this.GetPropertyRoute(); if (route != null) { var att = Validator.TryGetPropertyValidator(route.Parent.Type, route.PropertyInfo.Name)?.Validators .OfType <DecimalsValidatorAttribute>().SingleOrDefaultEx(); if (att != null) { return(StepTokens(this, att.DecimalPlaces).AndHasValue(this)); } var format = Reflector.FormatString(route); if (format != null) { return(StepTokens(this, Reflector.NumDecimals(format)).AndHasValue(this)); } } } return(SubTokensBase(this.Type, options, GetImplementations())); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { if (Column.Type.UnNullify() == typeof(DateTime)) { if (Column.PropertyRoutes != null) { DateTimePrecision? precission = Column.PropertyRoutes.Select(pr => Validator.TryGetPropertyValidator(pr.Parent.Type, pr.PropertyInfo.Name) .Validators.OfType<DateTimePrecissionValidatorAttribute>().SingleOrDefaultEx()) .Select(dtp => dtp?.Precision).Distinct().Only(); if (precission != null) return DateTimeProperties(this, precission.Value); } if (Column.Format == "d") return DateTimeProperties(this, DateTimePrecision.Days); } if (Column.Type.UnNullify() == typeof(double) || Column.Type.UnNullify() == typeof(float) || Column.Type.UnNullify() == typeof(decimal)) { if (Column.PropertyRoutes != null) { int? decimalPlaces= Column.PropertyRoutes.Select(pr => Validator.TryGetPropertyValidator(pr.Parent.Type, pr.PropertyInfo.Name) .Validators.OfType<DecimalsValidatorAttribute>().SingleOrDefaultEx()) .Select(dtp => dtp?.DecimalPlaces).Distinct().Only(); if (decimalPlaces != null) return StepTokens(this, decimalPlaces.Value); } if (Column.Format != null) return StepTokens(this, Reflector.NumDecimals(Column.Format)); } return SubTokensBase(Column.Type, options, Column.Implementations); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { if (PropertyInfo.PropertyType.UnNullify() == typeof(DateTime)) { PropertyRoute route = this.GetPropertyRoute(); if (route != null) { var att = Validator.TryGetPropertyValidator(route.Parent.Type, route.PropertyInfo.Name)?.Validators .OfType<DateTimePrecissionValidatorAttribute>().SingleOrDefaultEx(); if (att != null) { return DateTimeProperties(this, att.Precision); } } } if (PropertyInfo.PropertyType.UnNullify() == typeof(double) || PropertyInfo.PropertyType.UnNullify() == typeof(float) || PropertyInfo.PropertyType.UnNullify() == typeof(decimal)) { PropertyRoute route = this.GetPropertyRoute(); if (route != null) { var att = Validator.TryGetPropertyValidator(route.Parent.Type, route.PropertyInfo.Name)?.Validators .OfType<DecimalsValidatorAttribute>().SingleOrDefaultEx(); if (att != null) { return StepTokens(this, att.DecimalPlaces); } var format = Reflector.FormatString(route); if (format != null) return StepTokens(this, Reflector.NumDecimals(format)); } } return SubTokensBase(PropertyInfo.PropertyType, options, GetImplementations()); }
public ContentResult NewSubTokensCombo(string webQueryName, string tokenName, int options) { ChartRequest request = this.ExtractChartRequestCtx(null).Value; SubTokensOptions ops = (SubTokensOptions)options; if (request.GroupResults) { ops = ops | SubTokensOptions.CanAggregate; } else { ops = ops & ~SubTokensOptions.CanAggregate; } QueryDescription qd = DynamicQueryManager.Current.QueryDescription(request.QueryName); QueryToken token = QueryUtils.Parse(tokenName, qd, ops); var combo = FinderController.CreateHtmlHelper(this).QueryTokenBuilderOptions(token, new Context(null, this.Prefix()), ChartClient.GetQueryTokenBuilderSettings(qd, ops)); return(Content(combo.ToHtmlString())); }
public void ParseData(ModifiableEntity context, QueryDescription description, SubTokensOptions options) { token?.ParseData(context, description, options); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { return new List<QueryToken> { new StepRoundingToken(this, RoundingType.Ceil), new StepRoundingToken(this, RoundingType.Floor), new StepRoundingToken(this, RoundingType.Round), new StepRoundingToken(this, RoundingType.RoundMiddle), }; }
public static QueryTokenBuilderSettings GetQueryTokenBuilderSettings(QueryDescription qd, SubTokensOptions options) { return new QueryTokenBuilderSettings(qd, options) { Decorators = new Action<QueryToken, HtmlTag>(CanColumnDecorator) + new Action<QueryToken, HtmlTag>(CanFilterDecorator), ControllerUrl = RouteHelper.New().Action("NewSubTokensCombo", "Finder"), RequestExtraJSonData = null }; }
public static FixTokenResult FixToken(Replacements replacements, ref QueryTokenEntity token, QueryDescription qd, SubTokensOptions options, string remainingText, bool allowRemoveToken, bool allowReCreate) { SafeConsole.WriteColor(token.ParseException == null ? ConsoleColor.Gray : ConsoleColor.Red, " " + token.TokenString); Console.WriteLine(" " + remainingText); if (token.ParseException == null) return FixTokenResult.Nothing; QueryToken resultToken; FixTokenResult result = FixToken(replacements, token.TokenString, out resultToken, qd, options, remainingText, allowRemoveToken, allowReCreate); if (result == FixTokenResult.Fix) token = new QueryTokenEntity(resultToken); return result; }
public static IEnumerable <QueryFilterItem> ToQueryFiltersEmbedded(FilterNode filter, QueryDescription qd, SubTokensOptions options, int ident = 0) { if (filter.groupOperation == null) { var token = QueryUtils.Parse(filter.tokenString !, qd, options); var expectedValueType = filter.operation !.Value.IsList() ? typeof(ObservableCollection <>).MakeGenericType(token.Type.Nullify()) : token.Type; var val = filter.value is JToken jtok? jtok.ToObject(expectedValueType, JsonSerializer.Create(SignumServer.JsonSerializerSettings)) : filter.value; yield return(new QueryFilterItem { token = new QueryTokenTS(token, true), operation = filter.operation, valueString = FilterValueConverter.ToString(val, token.Type), indentation = ident, pinned = filter.pinned, }); } else { var token = filter.tokenString == null ? null : QueryUtils.Parse(filter.tokenString, qd, options); yield return(new QueryFilterItem { isGroup = true, groupOperation = filter.groupOperation, token = token == null ? null : new QueryTokenTS(token, true), indentation = ident, valueString = filter.value != null?FilterValueConverter.ToString(filter.value, typeof(string)) : null, pinned = filter.pinned, }); foreach (var f in filter.filters) { foreach (var fe in ToQueryFiltersEmbedded(f, qd, options, ident + 1)) { yield return(fe); } } } }
protected abstract List <QueryToken> SubTokensOverride(SubTokensOptions options);
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { return(new List <QueryToken>()); }
public static QueryToken Parse(string tokenString, QueryDescription qd, SubTokensOptions options) { if (string.IsNullOrEmpty(tokenString)) throw new ArgumentNullException("tokenString"); string[] parts = tokenString.Split('.'); string firstPart = parts.FirstEx(); QueryToken result = SubToken(null, qd, options, firstPart); if (result == null) throw new FormatException("Column {0} not found on query {1}".FormatWith(firstPart, QueryUtils.GetKey(qd.QueryName))); foreach (var part in parts.Skip(1)) { var newResult = SubToken(result, qd, options, part); if (newResult == null) throw new FormatException("Token with key '{0}' not found on {1} of query {2}".FormatWith(part, result.FullKey(), QueryUtils.GetKey(qd.QueryName))); result = newResult; } return result; }
static List<QueryToken> SubTokensBasic(QueryToken token, QueryDescription qd, SubTokensOptions options) { if (token == null) { if (MergeEntityColumns != null && !MergeEntityColumns()) return qd.Columns.Select(cd => (QueryToken)new ColumnToken(cd, qd.QueryName)).ToList(); var dictonary = qd.Columns.Where(a => !a.IsEntity).Select(cd => (QueryToken)new ColumnToken(cd, qd.QueryName)).ToDictionary(t => t.Key); var entity = new ColumnToken(qd.Columns.SingleEx(a => a.IsEntity), qd.QueryName); dictonary.Add(entity.Key, entity); foreach (var item in entity.SubTokensInternal(options).OrderByDescending(a=>a.Priority).ThenBy(a => a.ToString())) { if (!dictonary.ContainsKey(item.Key)) { dictonary.Add(item.Key, item); } } return dictonary.Values.ToList(); } else return token.SubTokensInternal(options); }
static QueryToken SubTokenBasic(QueryToken token, QueryDescription qd, SubTokensOptions options, string key) { if (token == null) { var column = qd.Columns.SingleOrDefaultEx(a=>a.Name == key); if (column == null) return null; return new ColumnToken(column, qd.QueryName); } else { return token.SubTokenInternal(key, options); } }
public static List<QueryToken> SubTokens(this QueryToken token, QueryDescription qd, SubTokensOptions options) { var result = SubTokensBasic(token, qd, options); if ((options & SubTokensOptions.CanAggregate) != 0) result.InsertRange(0, AggregateTokens(token, qd)); return result; }
public void ParseData(Entity context, QueryDescription description, SubTokensOptions options) { token.ParseData(context, description, options); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { return base.SubTokensBase(type, options, implementations); }
static SqlPreCommand ProcessUserChart(Replacements replacements, Table table, UserChartEntity uc) { try { Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "UserChart: " + uc.DisplayName); Console.WriteLine(" ChartScript: " + uc.ChartScript.ToString()); Console.WriteLine(" Query: " + uc.Query.Key); if (uc.Filters.Any(a => a.Token.ParseException != null) || uc.Columns.Any(a => a.Token != null && a.Token.ParseException != null) || uc.Orders.Any(a => a.Token.ParseException != null)) { QueryDescription qd = DynamicQueryManager.Current.QueryDescription(uc.Query.ToQueryName()); SubTokensOptions canAggregate = uc.GroupResults ? SubTokensOptions.CanAggregate : 0; if (uc.Filters.Any()) { Console.WriteLine(" Filters:"); foreach (var item in uc.Filters.ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | canAggregate, "{0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc)); case FixTokenResult.RemoveToken: uc.Filters.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } if (uc.Columns.Any()) { Console.WriteLine(" Columns:"); foreach (var item in uc.Columns.ToList()) { QueryTokenEmbedded token = item.Token; if (item.Token == null) { continue; } switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement | canAggregate, item.ScriptColumn.DisplayName, allowRemoveToken: item.ScriptColumn.IsOptional, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc)); case FixTokenResult.RemoveToken: item.Token = null; break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } if (uc.Orders.Any()) { Console.WriteLine(" Orders:"); foreach (var item in uc.Orders.ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement | canAggregate, item.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc)); case FixTokenResult.RemoveToken: uc.Orders.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } } foreach (var item in uc.Filters.ToList()) { string val = item.ValueString; switch (QueryTokenSynchronizer.FixValue(replacements, item.Token.Token.Type, ref val, allowRemoveToken: true, isList: item.Operation.IsList())) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc)); case FixTokenResult.RemoveToken: uc.Filters.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.ValueString = val; break; } } foreach (var item in uc.Columns) { uc.FixParameters(item); } foreach (var item in uc.Parameters) { string val = item.Value; retry: switch (FixParameter(item, ref val)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc)); case FixTokenResult.RemoveToken: uc.Parameters.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: { item.Value = val; goto retry; } } } try { return(table.UpdateSqlSync(uc, includeCollections: true)); } catch (Exception e) { Console.WriteLine("Integrity Error:"); SafeConsole.WriteLineColor(ConsoleColor.DarkRed, e.Message); while (true) { SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity"); SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity"); string answer = Console.ReadLine(); if (answer == null) { throw new InvalidOperationException("Impossible to synchronize interactively without Console"); } answer = answer.ToLower(); if (answer == "s") { return(null); } if (answer == "d") { return(table.DeleteSqlSync(uc)); } } } } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(uc.BaseToString(), e.Message))); } finally { Console.Clear(); } }
public void ParseData(Entity context, QueryDescription description, SubTokensOptions options) { if (token != null) token.ParseData(context, description, options & ~SubTokensOptions.CanAnyAll); }
static List <QueryToken> GetImplementedByAllSubTokens(QueryToken queryToken, Type type, SubTokensOptions options) { var cleanType = type.CleanType(); return(Schema.Current.Tables.Keys .Where(t => cleanType.IsAssignableFrom(t)) .Select(t => (QueryToken) new AsTypeToken(queryToken, t)) .ToList()); }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { return SubTokensBase(Type, options, GetImplementations()); }
public static FixTokenResult FixToken(Replacements replacements, string original, out QueryToken token, QueryDescription qd, SubTokensOptions options, string remainingText, bool allowRemoveToken, bool allowReGenerate) { string[] parts = original.Split('.'); QueryToken current; if (TryParseRemember(replacements, original, qd, options, out current)) { if (current.FullKey() != original) { SafeConsole.WriteColor(ConsoleColor.DarkRed, " " + original); Console.Write(" -> "); SafeConsole.WriteColor(ConsoleColor.DarkGreen, current.FullKey()); } Console.WriteLine(remainingText); token = current; return FixTokenResult.Fix; } while (true) { var result = SelectInteractive(ref current, qd, options, allowRemoveToken, allowReGenerate); switch (result) { case UserAssetTokenAction.DeleteEntity: SafeConsole.WriteLineColor(ConsoleColor.Red, "Entity deleted"); token = null; return FixTokenResult.DeleteEntity; case UserAssetTokenAction.ReGenerateEntity: if (!allowReGenerate) throw new InvalidOperationException("Unexpected ReGenerate"); SafeConsole.WriteLineColor(ConsoleColor.Magenta, "Entity Re-Generated"); token = null; return FixTokenResult.ReGenerateEntity; case UserAssetTokenAction.RemoveToken: if (!allowRemoveToken) throw new InvalidOperationException("Unexpected RemoveToken"); Console.SetCursorPosition(0, Console.CursorTop - 1); SafeConsole.WriteColor(ConsoleColor.DarkRed, " " + original); SafeConsole.WriteColor(ConsoleColor.DarkRed, " (token removed)"); Console.WriteLine(remainingText); token = null; return FixTokenResult.RemoveToken; case UserAssetTokenAction.SkipEntity: SafeConsole.WriteLineColor(ConsoleColor.DarkYellow, "Entity skipped"); token = null; return FixTokenResult.SkipEntity; case UserAssetTokenAction.Confirm: Remember(replacements, original, current); Console.SetCursorPosition(0, Console.CursorTop - 1); SafeConsole.WriteColor(ConsoleColor.DarkRed, " " + original); Console.Write(" -> "); SafeConsole.WriteColor(ConsoleColor.DarkGreen, current.FullKey()); Console.WriteLine(remainingText); token = current; return FixTokenResult.Fix; } } }
static bool TryParseRemember(Replacements replacements, string tokenString, QueryDescription qd, SubTokensOptions options, out QueryToken result) { string[] parts = tokenString.Split('.'); result = null; for (int i = 0; i < parts.Length; i++) { string part = parts[i]; QueryToken newResult = QueryUtils.SubToken(result, qd, options, part); if (newResult != null) { result = newResult; } else { if (i == 0) { var entity = QueryUtils.SubToken(result, qd, options, "Entity"); QueryToken newSubResult = QueryUtils.SubToken(entity, qd, options, part); if (newSubResult != null) { result = newSubResult; continue; } } if (Replacements.AutoReplacement != null) { Replacements.Selection? sel = Replacements.AutoReplacement(part, result.SubTokens(qd, options).Select(a => a.Key).ToList()); if (sel != null && sel.Value.NewValue != null) { newResult = QueryUtils.SubToken(result, qd, options, sel.Value.NewValue); if (newResult != null) { result = newResult; continue; } } } string key = result == null ? QueryKey(qd.QueryName) : TypeKey(result.Type); Dictionary<string, string> dic = replacements.TryGetC(key); if (dic == null) return false; string remainging = parts.Skip(i).ToString("."); string old = dic.Keys.OrderByDescending(a => a.Length).FirstOrDefault(s => remainging.StartsWith(s)); if (old == null) return false; var subParts = dic[old].Let(s => s.HasText() ? s.Split('.') : new string[0]); for (int j = 0; j < subParts.Length; j++) { string subPart = subParts[j]; QueryToken subNewResult = QueryUtils.SubToken(result, qd, options, subPart); if (subNewResult == null) return false; result = subNewResult; } i += (old == "" ? 0 : old.Split('.').Length) - 1; } } return true; }
protected override List <QueryToken> SubTokensOverride(SubTokensOptions options) { return(base.SubTokensBase(type, options, implementations)); }
static UserAssetTokenAction? SelectInteractive(ref QueryToken token, QueryDescription qd, SubTokensOptions options, bool allowRemoveToken, bool allowReGenerate) { var top = Console.CursorTop; try { if (Console.Out == null) throw new InvalidOperationException("Impossible to synchronize without interactive Console"); var subTokens = token.SubTokens(qd, options).OrderBy(a => a.Parent != null).ThenBy(a => a.Key).ToList(); int startingIndex = 0; SafeConsole.WriteLineColor(ConsoleColor.Cyan, " " + token.Try(a => a.FullKey())); bool isRoot = token == null; retry: int maxElements = Console.LargestWindowHeight - 11; subTokens.Skip(startingIndex).Take(maxElements) .Select((s, i) => "- {1,2}: {2} ".FormatWith(i + " ", i + startingIndex, ((isRoot && s.Parent != null) ? "-" : "") + s.Key)).ToConsole(); Console.WriteLine(); int remaining = subTokens.Count - startingIndex - maxElements; if (remaining > 0) SafeConsole.WriteLineColor(ConsoleColor.White, "- +: Show more values ({0} remaining)", remaining); if (token != null) { SafeConsole.WriteLineColor(ConsoleColor.White, "- b: Back"); SafeConsole.WriteLineColor(ConsoleColor.Green, "- c: Confirm"); } SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity"); if (allowRemoveToken) SafeConsole.WriteLineColor(ConsoleColor.DarkRed, "- r: Remove token"); if (allowReGenerate) SafeConsole.WriteLineColor(ConsoleColor.Magenta, "- g: Generate from default template"); SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity"); while (true) { string answer = Console.ReadLine(); if (answer == null) throw new InvalidOperationException("Impossible to synchronize interactively without Console"); answer = answer.ToLower(); if (answer == "+" && remaining > 0) { startingIndex += maxElements; goto retry; } if (answer == "s") return UserAssetTokenAction.SkipEntity; if (answer == "r" && allowRemoveToken) return UserAssetTokenAction.RemoveToken; if (answer == "d") return UserAssetTokenAction.DeleteEntity; if (answer == "g") return UserAssetTokenAction.ReGenerateEntity; if (token != null) { if (answer == "c") return UserAssetTokenAction.Confirm; if (answer == "b") { token = token.Parent; return null; } } int option = 0; if (int.TryParse(answer, out option)) { token = subTokens[option]; return null; } Console.WriteLine("Error"); } } finally { Clean(top, Console.CursorTop); } }
static List <FilterNode> ParseFilterInternal(IEnumerable <QueryFilterItem> filters, QueryDescription qd, SubTokensOptions options, int indent) { return(filters.GroupWhen(filter => filter.indentation == indent).Select(gr => { if (!gr.Key.isGroup) { if (gr.Count() != 0) { throw new InvalidOperationException("Unexpected childrens of condition"); } var filter = gr.Key; var token = QueryUtils.Parse(filter.tokenString !, qd, options); var value = FilterValueConverter.Parse(filter.valueString, token.Type, filter.operation !.Value.IsList()); return new FilterNode { token = new QueryTokenTS(token, true), operation = filter.operation.Value, value = value, pinned = filter.pinned, }; } else { var group = gr.Key; var token = group.tokenString == null ? null : QueryUtils.Parse(group.tokenString !, qd, options); var value = FilterValueConverter.Parse(group.valueString, typeof(string), false); return new FilterNode { groupOperation = group.groupOperation !.Value, token = token == null ? null : new QueryTokenTS(token, true), pinned = gr.Key.pinned, filters = ParseFilterInternal(gr, qd, options, indent + 1).ToList() }; } }).ToList()); }
public void ParseData(Entity context, QueryDescription description, SubTokensOptions options) { Token.ParseData(context, description, options & ~SubTokensOptions.CanAnyAll); }
public static List <QueryToken> SubTokens(this QueryToken token, QueryDescription qd, SubTokensOptions options) { var result = SubTokensBasic(token, qd, options); if ((options & SubTokensOptions.CanAggregate) != 0) { result.InsertRange(0, AggregateTokens(token, qd)); } return(result); }
public void ParseData(Entity context, QueryDescription description, SubTokensOptions options) { Token.ParseData(context, description, options); SummaryToken?.ParseData(context, description, options | SubTokensOptions.CanAggregate); }
public QueryTokenBuilderSettings(QueryDescription descripton, SubTokensOptions options) { this.QueryDescription = descripton; this.Options = options; }
protected override List<QueryToken> SubTokensOverride(SubTokensOptions options) { return new List<QueryToken>(); }
public static QueryTokenBuilderSettings GetQueryTokenBuilderSettings(QueryDescription qd, SubTokensOptions options) { return(new QueryTokenBuilderSettings(qd, options) { ControllerUrl = RouteHelper.New().Action("NewSubTokensCombo", "Mailing"), Decorators = TemplatingClient.TemplatingDecorators, RequestExtraJSonData = null, }); }
public static QueryToken SubToken(QueryToken token, QueryDescription qd, SubTokensOptions options, string key) { var result = SubTokenBasic(token, qd, options, key); if (result != null) return result; if ((options & SubTokensOptions.CanAggregate) != 0) return AggregateTokens(token, qd).SingleOrDefaultEx(a => a.Key == key); return null; }