Exemplo n.º 1
0
        /// <summary>
        /// Returns the database context for the given connection string,
        /// optionally loading and compiling the types if missing.
        /// </summary>
        public async Task <CompileResult> GetDatabaseContext(string connectionString, DatabaseProviderType type)
        {
            if (!_map.ContainsKey(connectionString))
            {
                var assmName     = Guid.NewGuid().ToIdentifierWithPrefix("a");
                var schemaResult = await _schemaService.GetSchemaSource(connectionString, type, assmName);

                if (schemaResult.Code != Api.StatusCode.Ok)
                {
                    var errRes = new CompileResult {
                        Code = schemaResult.Code
                    };
                    return(errRes);
                }
                var result = _compileService.LoadType(schemaResult.Schema, assmName);
                _map.Add(connectionString, result);
            }

            return(_map[connectionString]);
        }
Exemplo n.º 2
0
        public CompileResult StartGenerated(Guid id, string source, string assmName, MetadataReference context = null)
        {
            var sw = new Stopwatch();

            sw.Start();
            var compileResult = _compiler.LoadType(source, assmName, context);

            if (compileResult.Code == Api.StatusCode.Ok)
            {
                var t = new Task(async() =>
                {
                    var programInstance = (IGenerated)Activator.CreateInstance(compileResult.Type);
                    var e1 = sw.Elapsed.TotalMilliseconds;
                    sw.Reset();
                    sw.Start();
                    await StartInternal(id, programInstance);
                    var e2 = sw.Elapsed.TotalMilliseconds;
                    Logger.Debug("{2}: IGenerated.Run TotalMilliseconds {0} (startup: {1} ms)", e2, e1, id);
                });
                t.Start();
            }
            return(compileResult);
        }