/// <summary> /// Finds the demanded DiagnosticsQuery and returns it including Query-Arguments /// </summary> /// <param name="queryName">the name of the requested DiagnosticsQuery</param> /// <returns>a DiagnosticsQueryDefinition-Object containing all parameters and permissions required to execute it</returns> public DiagnosticsQueryDefinition GetQuery(string queryName) { var dbQuery = dbContext.DiagnosticsQueries.FirstOrDefault(n => n.DiagnosticsQueryName == queryName); if (dbQuery != null) { var retVal = new DiagnosticsQueryDefinition { AutoReturn = dbQuery.AutoReturn, DbContext = dbQuery.DbContext, DiagnosticsQueryName = dbQuery.DiagnosticsQueryName, Permission = dbQuery.Permission.PermissionName, QueryText = dbQuery.QueryText }; foreach (var diagnosticsQueryParameter in dbQuery.Parameters) { retVal.Parameters.Add(new DiagnosticsQueryParameterDefinition { DefaultValue = diagnosticsQueryParameter.DefaultValue, Format = diagnosticsQueryParameter.Format, Optional = diagnosticsQueryParameter.Optional, ParameterName = diagnosticsQueryParameter.ParameterName, ParameterType = diagnosticsQueryParameter.ParameterType }); } return(retVal); } return(null); }
public static IEnumerable RunDiagnosticsQuery(this DbContext context, DiagnosticsQueryDefinition query, IDictionary <string, object> arguments) { var args = new Dictionary <string, object>(arguments); var queryText = CreateDiagQuery(context, query, args); return(RunQuery(context, queryText, RosDiagConfig, args)); }
public static IDictionary <string, object> BuildArguments(DiagnosticsQueryDefinition query, IDictionary <string, string> arguments) { var retVal = new Dictionary <string, object>(); BuildArguments(query, arguments, (name, value, type, nullable) => retVal.Add(name, value), (name, type, nullable) => retVal.Add(name, DBNull.Value)); return(retVal); }
private static string CreateDiagQuery(DbContext context, DiagnosticsQueryDefinition query, IDictionary <string, object> arguments) { ConfigureLinqForContext(context, RosDiagConfig, out var contextType); StringBuilder fullQuery = new StringBuilder($@"{contextType.Name} db = Global.Db; "); DiagnoseQueryHelper.VerifyArguments(query, arguments, fullQuery); fullQuery.AppendLine($"{(query.AutoReturn ? "return " : "")}{query.QueryText}{(query.AutoReturn ? ";" : "")}"); return(fullQuery.ToString()); }
private static void BuildArguments(DiagnosticsQueryDefinition query, IDictionary <string, string> arguments, Action <string, object, string, bool> paramWithValue, Action <string, string, bool> paramWithoutValue) { ProcessArguments(query, s => { object retVal = null; if (arguments.ContainsKey(s)) { retVal = arguments[s]; } return(retVal); }, paramWithValue, paramWithoutValue); }
public static void BuildArguments(DiagnosticsQueryDefinition query, IDictionary <string, string> arguments, IDictionary <string, object> queryArguments, StringBuilder fullQuery) { var writeParam = new Action <string, string, bool>((name, type, nullable) => { fullQuery.AppendLine($"{type}{(nullable ? "?" : "")} {name} = Global.{name};"); }); BuildArguments(query, arguments, (name, value, type, nullable) => { if (!queryArguments.ContainsKey(name)) { queryArguments.Add(name, value); } writeParam(name, type, nullable); }, writeParam); }
/// <summary> /// Gets the EntityContext for a DiagnosticsQuery and the DiagnosticsQuery object that represents the requested query /// </summary> /// <param name="services">the services for the current request</param> /// <param name="queryName">the name of the requested query</param> /// <param name="queryObject">the query-object that was found in the Diagnostics-DB</param> /// <returns>the Db-Context that is used to execute the requested query</returns> public static IWrappedDataSource ContextForDiagnosticsQuery(this IServiceProvider services, string queryName, string area, out DiagnosticsQueryDefinition queryObject) { var store = services.GetService <IDiagnosticsStore>(); queryObject = store.GetQuery(queryName); if (queryObject != null) { if (services.VerifyUserPermissions(new[] { queryObject.Permission })) { var options = services.GetService <IOptions <DiagnosticsSourceOptions> >().Value; Func <IServiceProvider, string, string, object> factory = null; var connection = queryObject.DbContext; if (options.Factories.ContainsKey(connection)) { factory = options.Factories[connection]; } else if (options.Factories.ContainsKey("*")) { factory = options.Factories["*"]; } if (factory != null) { var retVal = factory(services, connection, area); if (retVal is DbContext dbc) { return(new WrappedDbContext(dbc, services)); } else if (retVal is DynamicDataAdapter dynda) { return(new WrappedDynamicDataAdapter(dynda)); } else { throw new InvalidOperationException("Unexpected returned value"); } } } } return(null); }
private static void ProcessArguments(DiagnosticsQueryDefinition query, Func <string, object> argumentValue, Action <string, object, string, bool> paramWithValue, Action <string, string, bool> paramWithoutValue) { foreach (var arg in query.Parameters) { var rawValue = argumentValue(arg.ParameterName); if (rawValue == null && !arg.Optional) { throw new ArgumentException($"Missing parameter {arg.ParameterName}!", arg.ParameterName); } bool nullable = arg.Optional && string.IsNullOrEmpty(arg.DefaultValue); rawValue ??= arg.DefaultValue; string typeDef; if (rawValue is string s && !string.IsNullOrEmpty(s)) { var paramValue = ParseArgument(s, arg.ParameterType, arg.Format, out typeDef); paramWithValue(arg.ParameterName, paramValue, typeDef, nullable); //queryArguments.Add(arg.ParameterName, ParseArgument(arg.DefaultValue, arg.ParameterType, arg.Format, out typeDef)); }
public IEnumerable RunDiagnosticsQuery(DiagnosticsQueryDefinition query, IDictionary <string, object> arguments) { var arg = DiagnoseQueryHelper.VerifyArguments(query, arguments); return(src.SqlQuery(query.QueryText, arg)); }
public IEnumerable RunDiagnosticsQuery(DiagnosticsQueryDefinition query, IDictionary <string, string> queryArguments) { var arguments = DiagnoseQueryHelper.BuildArguments(query, queryArguments); return(src.SqlQuery(query.QueryText, arguments)); }
public IEnumerable RunDiagnosticsQuery(DiagnosticsQueryDefinition query, IDictionary <string, object> arguments) { return(decoratedContext.RunDiagnosticsQuery(query, arguments)); }
public IEnumerable RunDiagnosticsQuery(DiagnosticsQueryDefinition qr, IDictionary <string, string> queryArguments) { return(decoratedContext.RunDiagnosticsQuery(qr, queryArguments)); }