Exemple #1
0
        /// <summary>
        /// Loads and adds the <see cref="DatabaseSymbol"/> for any database explicity referenced in the <see cref="CodeScript"/ document but not already present in the <see cref="GlobalState"/>.
        /// </summary>
        public async Task <CodeScript> AddReferencedDatabasesAsync(CodeScript script, CancellationToken cancellationToken = default)
        {
            var globals = script.Globals;

            foreach (var block in script.Blocks)
            {
                globals = await AddReferencedDatabasesAsync(globals, block.Service, cancellationToken).ConfigureAwait(false);
            }

            return(script.WithGlobals(globals));
        }
Exemple #2
0
        public async Task TestAddReferencedDatabasesAsync_CodeScript()
        {
            var loader = new SymbolLoader(HelpConnection);

            // set default database to database other than Samples.
            var globals = await loader.AddOrUpdateDefaultDatabaseAsync(GlobalState.Default, "KustoMonitoringPersistentDatabase");

            // just one database should exist
            Assert.AreEqual(1, globals.Cluster.Databases.Count);

            // create script from query and globals
            var script = CodeScript.From("database('Samples').StormEvents", globals);

            // use loader to add symbols for any explicity referenced databases
            var newScript = await loader.AddReferencedDatabasesAsync(script);

            // both databases should exist now
            Assert.AreEqual(2, newScript.Globals.Cluster.Databases.Count);

            // find StormEvents table in Samples database
            var samples = newScript.Globals.Cluster.Databases.First(db => db.Name == "Samples");
            var storm   = samples.GetTable("StormEvents");
        }