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()); }
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)); }
/// <summary> /// Translates the given data to its viewModel and applies Diagnostics queries if available /// </summary> /// <typeparam name="TOrigin">the original data that was selected from a database</typeparam> /// <typeparam name="TViewModel">the target viewmodel on which to translate the data</typeparam> /// <param name="services">the services for the current request</param> /// <param name="originalItem">the selected data</param> /// <param name="queryArguments">provides arguments for a specific record</param> /// <returns></returns> public static TViewModel DiagnoseResult <TOrigin, TViewModel>(this IServiceProvider services, TOrigin originalItem, IDictionary <string, object> queryArguments, Dictionary <string, DiagnoseQueryHelper.DiagQueryItem> knownQueries, ref DiagnoseQueryHelper.DiagEntityAnlyseItem[] typeAnalysis, Action <TOrigin, TViewModel> postProcess = null) where TViewModel : class, new() where TOrigin : class { typeAnalysis ??= DiagnoseQueryHelper.AnalyseViewModel <TViewModel>(); IContextUserProvider userProvider = services.GetService <IContextUserProvider>(); string area = null; if (userProvider?.RouteData != null) { var routeData = userProvider.RouteData; if (routeData.ContainsKey("area")) { area = (string)routeData["area"]; } } var ret = originalItem.ToViewModel <TOrigin, TViewModel>(t => { if (t == typeof(IServiceProvider)) { return(services); } if (t == typeof(DiagnoseQueryOptions)) { return(new DiagnoseQueryOptions { Area = area, KnownQueries = knownQueries, Arguments = queryArguments }); } return(null); }, postProcess); /*if (typeAnalysis.Length != 0) * { * foreach (var p in typeAnalysis) * { * IWrappedDataSource context = null; * DiagnosticsQuery qr = null; * if (knownQueries.ContainsKey(p.Attribute.DiagnosticQueryName)) * { * var item = knownQueries[p.Attribute.DiagnosticQueryName]; * context = item.Context; * qr = item.Query; * } * else * { * context = services.ContextForDiagnosticsQuery(p.Attribute.DiagnosticQueryName, area, out qr); * knownQueries.Add(p.Attribute.DiagnosticQueryName, new DiagnoseQueryHelper.DiagQueryItem * { * Query = qr, * Context = context * }); * } * * if (context != null) * { * if (p.Property.PropertyType == typeof(SimpleTriStateResult)) * { * p.Property.SetValue(ret, context.RunDiagnosticsQuery(qr, queryArguments).Cast<SimpleTriStateResult>().FirstOrDefault()); * } * else * { * p.Property.SetValue(ret, context.RunDiagnosticsQuery(qr, queryArguments).Cast<object>().FirstOrDefault()); * } * } * } * * postProcess?.Invoke(originalItem, ret); * * }*/ return(ret); }