public static FixTokenResult FixToken(Replacements replacements, ref QueryTokenEmbedded 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); } FixTokenResult result = FixToken(replacements, token.TokenString, out QueryToken resultToken, qd, options, remainingText, allowRemoveToken, allowReCreate); if (result == FixTokenResult.Fix) { token = new QueryTokenEmbedded(resultToken); } return(result); }
static SqlPreCommand?ProcessUserChart(Replacements replacements, Table table, UserChartEntity uc) { Console.Write("."); using (DelayedConsole.Delay(() => SafeConsole.WriteLineColor(ConsoleColor.White, "UserChart: " + uc.DisplayName))) using (DelayedConsole.Delay(() => Console.WriteLine(" ChartScript: " + uc.ChartScript.ToString()))) using (DelayedConsole.Delay(() => Console.WriteLine(" Query: " + uc.Query.Key))) { try { if (uc.Filters.Any(a => a.Token?.ParseException != null) || uc.Columns.Any(a => a.Token?.ParseException != null)) { QueryDescription qd = QueryLogic.Queries.QueryDescription(uc.Query.ToQueryName()); if (uc.Filters.Any()) { using (DelayedConsole.Delay(() => Console.WriteLine(" Filters:"))) { foreach (var item in uc.Filters.ToList()) { if (item.Token != null) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | SubTokensOptions.CanAggregate, "{0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc, u => u.Guid == uc.Guid)); 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()) { using (DelayedConsole.Delay(() => Console.WriteLine(" Columns:"))) { foreach (var item in uc.Columns.ToList()) { if (item.Token == null) { continue; } QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement | SubTokensOptions.CanAggregate, item.ScriptColumn.DisplayName, allowRemoveToken: item.ScriptColumn.IsOptional, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uc, u => u.Guid == uc.Guid)); case FixTokenResult.RemoveToken: item.Token = null; break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } } } foreach (var item in uc.Filters.Where(f => !f.IsGroup).ToList()) { retry: string?val = item.ValueString; switch (QueryTokenSynchronizer.FixValue(replacements, item.Token !.Token.Type, ref val, allowRemoveToken: true, isList: item.Operation.Value.IsList())) { case FixTokenResult.Nothing: break;
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 string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { return(Encodings.GetOrThrow(encoding).ValidateEncodingProperty(predictor, subQuery, encoding, usage, token)); }
internal static SqlPreCommand?ProcessEmailTemplate(Replacements replacements, Table table, EmailTemplateEntity et, StringDistance sd) { Console.Write("."); try { var queryName = QueryLogic.ToQueryName(et.Query.Key); QueryDescription qd = QueryLogic.Queries.QueryDescription(queryName); using (DelayedConsole.Delay(() => SafeConsole.WriteLineColor(ConsoleColor.White, "EmailTemplate: " + et.Name))) using (DelayedConsole.Delay(() => Console.WriteLine(" Query: " + et.Query.Key))) { if (et.From != null && et.From.Token != null) { QueryTokenEmbedded token = et.From.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " From", allowRemoveToken: false, allowReCreate: et.Model != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et, e => e.Name == et.Name)); case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: et.From.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } if (et.Recipients.Any(a => a.Token != null)) { using (DelayedConsole.Delay(() => Console.WriteLine(" Recipients:"))) { foreach (var item in et.Recipients.Where(a => a.Token != null).ToList()) { QueryTokenEmbedded token = item.Token !; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " Recipient", allowRemoveToken: false, allowReCreate: et.Model != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et, e => e.Name == et.Name)); case FixTokenResult.RemoveToken: et.Recipients.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } } } try { foreach (var item in et.Messages) { SynchronizationContext sc = new SynchronizationContext(replacements, sd, qd, et.Model?.ToType()); item.Subject = TextTemplateParser.Synchronize(item.Subject, sc); item.Text = TextTemplateParser.Synchronize(item.Text, sc); } using (replacements.WithReplacedDatabaseName()) return(table.UpdateSqlSync(et, e => e.Name == et.Name, includeCollections: true, comment: "EmailTemplate: " + et.Name)); } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) { return(null); } if (ex.Result == FixTokenResult.DeleteEntity) { return(table.DeleteSqlSync(et, e => e.Name == et.Name)); } if (ex.Result == FixTokenResult.ReGenerateEntity) { return(Regenerate(et, replacements, table)); } throw new UnexpectedValueException(ex.Result); } } } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception on {0}. {1}\r\n{2}".FormatWith(et.BaseToString(), e.GetType().Name, e.Message.Indent(2, '-')))); } }
internal void FromXml(XElement element, IFromXmlContext ctx) { Query = ctx.GetQuery(element.Attribute("Query") !.Value); Token = new QueryTokenEmbedded(element.Attribute("Token") !.Value); }
internal void FromXml(XElement element, IFromXmlContext ctx) { Token = new QueryTokenEmbedded(element.Attribute("Token").Value); OrderType = element.Attribute("OrderType").Value.ToEnum <OrderType>(); }
internal void FromXml(XElement element, IFromXmlContext ctx) { Token = new QueryTokenEmbedded(element.Attribute("Token").Value); DisplayName = element.Attribute("DisplayName")?.Value; }
public string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { var nn = (NeuralNetworkSettingsEntity)predictor.AlgorithmSettings; if (token.Token.Type != typeof(string)) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), predictor.Algorithm.NiceToString())); } if (usage == PredictorColumnUsage.Output) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), usage.NiceToString())); } return(null); }
public string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { var nn = (NeuralNetworkSettingsEntity)predictor.AlgorithmSettings; if (ReflectionTools.IsDecimalNumber(token.Token.Type)) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), predictor.Algorithm.NiceToString())); } if (usage == PredictorColumnUsage.Output && (nn.PredictionType == PredictionType.Regression || nn.PredictionType == PredictionType.MultiRegression)) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), nn.PredictionType.NiceToString())); } return(null); }
public string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { var nn = (NeuralNetworkSettingsEntity)predictor.AlgorithmSettings; if (!ReflectionTools.IsNumber(token.Token.Type) && token.Token.Type.UnNullify() != typeof(bool)) { return(PredictorMessage._0IsRequiredFor1.NiceToString(DefaultColumnEncodings.OneHot.NiceToString(), token.Token.NiceTypeName)); } if (usage == PredictorColumnUsage.Output && (nn.PredictionType == PredictionType.Classification || nn.PredictionType == PredictionType.MultiClassification)) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), nn.PredictionType.NiceToString())); } return(null); }
public string?ValidateEncodingProperty(PredictorEntity predictor, PredictorSubQueryEntity?subQuery, PredictorColumnEncodingSymbol encoding, PredictorColumnUsage usage, QueryTokenEmbedded token) { if (!ReflectionTools.IsDecimalNumber(token.Token.Type) && !ReflectionTools.IsNumber(token.Token.Type)) { return(PredictorMessage._0NotSuportedFor1.NiceToString(encoding.NiceToString(), predictor.Algorithm.NiceToString())); } return(null); }
static SqlPreCommand ProcessUserQuery(Replacements replacements, Table table, UserQueryEntity uq) { try { Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "UserQuery: " + uq.DisplayName); Console.WriteLine(" Query: " + uq.Query.Key); if (uq.Filters.Any(a => a.Token.ParseException != null) || uq.Columns.Any(a => a.Token != null && a.Token.ParseException != null) || uq.Orders.Any(a => a.Token.ParseException != null)) { QueryDescription qd = DynamicQueryManager.Current.QueryDescription(uq.Query.ToQueryName()); if (uq.Filters.Any()) { Console.WriteLine(" Filters:"); foreach (var item in uq.Filters.ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement, "{0} {1}".FormatWith(item.Operation, item.ValueString), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uq)); case FixTokenResult.RemoveToken: uq.Filters.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } if (uq.Columns.Any()) { Console.WriteLine(" Columns:"); foreach (var item in uq.Columns.ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, item.DisplayName.HasText() ? "'{0}'".FormatWith(item.DisplayName) : null, allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity:; return(table.DeleteSqlSync(uq)); case FixTokenResult.RemoveToken: uq.Columns.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } if (uq.Orders.Any()) { Console.WriteLine(" Orders:"); foreach (var item in uq.Orders.ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, item.OrderType.ToString(), allowRemoveToken: true, allowReCreate: false)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(uq)); case FixTokenResult.RemoveToken: uq.Orders.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; default: break; } } } } foreach (var item in uq.Filters.ToList()) { retry: 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(uq)); case FixTokenResult.RemoveToken: uq.Filters.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.ValueString = val; goto retry; } } if (uq.WithoutFilters) { uq.Filters.Clear(); } if (!uq.ShouldHaveElements && uq.ElementsPerPage.HasValue) { uq.ElementsPerPage = null; } if (uq.ShouldHaveElements && !uq.ElementsPerPage.HasValue) { uq.ElementsPerPage = 20; } Console.Clear(); using (replacements.WithReplacedDatabaseName()) return(table.UpdateSqlSync(uq, includeCollections: true)); } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception in {0}: {1}".FormatWith(uq.BaseToString(), e.Message))); } }
public void FromXml(XElement element, IFromXmlContext ctx) { Token = new QueryTokenEmbedded(element.Attribute("Token").Value); Operation = element.Attribute("Operation").Value.ToEnum <FilterOperation>(); ValueString = element.Attribute("Value").Value; }
internal static SqlPreCommand ProcessEmailTemplate(Replacements replacements, Table table, EmailTemplateEntity et, StringDistance sd) { try { var queryName = QueryLogic.ToQueryName(et.Query.Key); QueryDescription qd = DynamicQueryManager.Current.QueryDescription(queryName); Console.Clear(); SafeConsole.WriteLineColor(ConsoleColor.White, "EmailTemplate: " + et.Name); Console.WriteLine(" Query: " + et.Query.Key); if (et.From != null && et.From.Token != null) { QueryTokenEmbedded token = et.From.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " From", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et)); case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: et.From.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } if (et.Recipients.Any(a => a.Token != null)) { Console.WriteLine(" Recipients:"); foreach (var item in et.Recipients.Where(a => a.Token != null).ToList()) { QueryTokenEmbedded token = item.Token; switch (QueryTokenSynchronizer.FixToken(replacements, ref token, qd, SubTokensOptions.CanElement, " Recipient", allowRemoveToken: false, allowReCreate: et.SystemEmail != null)) { case FixTokenResult.Nothing: break; case FixTokenResult.DeleteEntity: return(table.DeleteSqlSync(et)); case FixTokenResult.RemoveToken: et.Recipients.Remove(item); break; case FixTokenResult.SkipEntity: return(null); case FixTokenResult.Fix: item.Token = token; break; case FixTokenResult.ReGenerateEntity: return(Regenerate(et, replacements, table)); default: break; } } } try { foreach (var item in et.Messages) { SyncronizationContext sc = new SyncronizationContext { ModelType = et.SystemEmail.ToType(), QueryDescription = qd, Replacements = replacements, StringDistance = sd, Variables = new ScopedDictionary <string, ValueProviderBase>(null) }; item.Subject = Synchronize(item.Subject, sc); item.Text = Synchronize(item.Text, sc); } using (replacements.WithReplacedDatabaseName()) return(table.UpdateSqlSync(et, includeCollections: true, comment: "EmailTemplate: " + et.Name)); } catch (TemplateSyncException ex) { if (ex.Result == FixTokenResult.SkipEntity) { return(null); } if (ex.Result == FixTokenResult.DeleteEntity) { return(table.DeleteSqlSync(et)); } if (ex.Result == FixTokenResult.ReGenerateEntity) { return(Regenerate(et, replacements, table)); } throw new InvalidOperationException("Unexcpected {0}".FormatWith(ex.Result)); } finally { Console.Clear(); } } catch (Exception e) { return(new SqlPreCommandSimple("-- Exception on {0}. {1}\r\n{2}".FormatWith(et.BaseToString(), e.GetType().Name, e.Message.Indent(2, '-')))); } }