示例#1
0
        public IDictionary <string, object> ExecuteQuery(QueryInput input)
        {
            var sw = new Stopwatch();

            sw.Start();
            var contextResult = _databaseContextService.GetDatabaseContext(input.ConnectionString);
            var assmName      = Guid.NewGuid().ToIdentifierWithPrefix("a");
            var programSource = _template
                                .Replace("##SOURCE##", input.Text)
                                .Replace("##NS##", assmName)
                                .Replace("##DB##", contextResult.Type.ToString());
            var e1 = sw.Elapsed.TotalMilliseconds;

            sw.Reset();
            sw.Start();
            var result          = _compiler.LoadType(programSource, assmName, contextResult.Reference);
            var method          = result.Type.GetMethod("Run");
            var programInstance = Activator.CreateInstance(result.Type);
            var e2 = sw.Elapsed.TotalMilliseconds;

            sw.Reset();
            sw.Start();
            var res = method.Invoke(programInstance, new object[] { }) as IDictionary <string, object>;
            var e3  = sw.Elapsed.TotalMilliseconds;

            //res.Add("Performance", new { DbContext = e1, Loading = e2, Execution = e3 });
            return(res);
        }
示例#2
0
        /// <summary>
        /// Returns the database context for the given connection string,
        /// optionally loading and compiling the types if missing.
        /// </summary>
        public CompileResult GetDatabaseContext(string connectionString)
        {
            if (!_map.ContainsKey(connectionString))
            {
                var assmName  = Guid.NewGuid().ToIdentifierWithPrefix("a");
                var schemaSrc = _schemaService.GetSchemaSource(connectionString, assmName);
                var result    = _compileService.LoadType(schemaSrc, assmName);
                _map.Add(connectionString, result);
            }

            return(_map[connectionString]);
        }