コード例 #1
0
        public static bool CompileAndRun(QueryExecutionContext context,
                                         string query,
                                         TextWriter errorLogger,
                                         TextWriter logger,
                                         Dictionary <string, object> playbackProperties = null)
        {
            try
            {
                EnsureTemporaryCache();
                Assembly assembly = null;
                Logger.Log("Compiling Query \n" + query);

                if (string.IsNullOrEmpty(query))
                {
                    errorLogger.Write("No query present to execute.");
                    return(false);
                }

                if (!AssemblyCache.TryGetValue(query, out assembly))
                {
                    string usings = GetUsings();
                    assembly = GenerateAssembly(usings, query, errorLogger, logger);
                    if (assembly != null)
                    {
                        AssemblyCache[query] = assembly;
                    }
                }

                if (assembly != null)
                {
                    object t = Activator.CreateInstance(assembly.GetType("QueryExecutionTemplate.PlaybackWrapper"), context.Playback, logger);

                    if (playbackProperties != null)
                    {
                        foreach (var extraParam in playbackProperties)
                        {
                            t.GetType().GetProperty(extraParam.Key).SetValue(t, extraParam.Value, null);
                        }
                    }
                    QueryExecutionContext.Current = context;
                    bool result = (bool)t.GetType().GetMethod("CompileQuery").Invoke(t, null);
                    if (result == false)
                    {
                        Exception ex = (Exception)t.GetType().GetProperty("Exception").GetValue(t, null);
                        context.SetException(ex);
                    }
                    else
                    {
                        context.Run();
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                context.SetException(ex);
                errorLogger.WriteLine(ex.Message);
            }

            return(false);
        }
コード例 #2
0
ファイル: QueryCompiler.cs プロジェクト: aelij/svcperf
        public static bool CompileAndRun(QueryExecutionContext context,
            string query,
            TextWriter errorLogger,
            TextWriter logger,
            Dictionary<string, object> playbackProperties = null)
        {
            try
            {
                EnsureTemporaryCache();
                Assembly assembly = null;
                Logger.Log("Compiling Query \n" + query);

                if (string.IsNullOrEmpty(query))
                {
                    errorLogger.Write("No query present to execute.");
                    return false;
                }

                if (!AssemblyCache.TryGetValue(query, out assembly))
                {
                    string usings = GetUsings();
                    assembly = GenerateAssembly(usings, query, errorLogger, logger);
                    if (assembly != null)
                    {
                        AssemblyCache[query] = assembly;
                    }
                }

                if (assembly != null)
                {
                    object t = Activator.CreateInstance(assembly.GetType("QueryExecutionTemplate.PlaybackWrapper"), context.Playback, logger);

                    if (playbackProperties != null)
                    {
                        foreach (var extraParam in playbackProperties)
                        {
                            t.GetType().GetProperty(extraParam.Key).SetValue(t, extraParam.Value, null);
                        }
                    }
                    QueryExecutionContext.Current = context;
                    bool result = (bool)t.GetType().GetMethod("CompileQuery").Invoke(t, null);
                    if (result == false)
                    {
                        Exception ex = (Exception)t.GetType().GetProperty("Exception").GetValue(t, null);
                        context.SetException(ex);
                    }
                    else
                    {
                        context.Run();
                    }
                    return result;
                }
            }
            catch (Exception ex)
            {
                context.SetException(ex);
                errorLogger.WriteLine(ex.Message);
            }

            return false;
        }