Beispiel #1
0
        /// <summary>
        /// Generates a Kusto table mapping for a specific <see cref="Type"/>, by mapping it's properties to column mappings.
        /// </summary>
        /// <param name="client">The <see cref="ICslAdminProvider"/> client that we are extending.</param>
        /// <param name="type">The <see cref="Type"/> that we are generating the JSON mapping for.</param>
        /// <returns>The name of the mapping created.</returns>
        public static string GenerateTableJsonMappingFromType(this ICslAdminProvider client, Type type)
        {
            var tableName   = type.Name;
            var mappingName = $"{tableName}_mapping";
            var command     = CslCommandGenerator.GenerateTableJsonMappingShowCommand(tableName, mappingName);

            try
            {
                client.ExecuteControlCommand(command);
                return(mappingName);
            }
            catch (KustoBadRequestException ex) when(ex.ErrorMessage.Contains("'JsonMappingPersistent' was not found"))
            {
                // soak
            }

            var mappings = type.GetProperties().Select(property => new JsonColumnMapping {
                ColumnName = property.Name, JsonPath = $"$.{property.Name}"
            }).ToList();

            command = CslCommandGenerator.GenerateTableJsonMappingCreateCommand(tableName, mappingName, mappings);
            client.ExecuteControlCommand(command);

            return(mappingName);
        }
        private void CreateMergeKustoTable(ICslAdminProvider admin, IDictionary <string, object> value)
        {
            TableSchema tableSchema = new TableSchema(TableName);

            foreach (var pair in value)
            {
                tableSchema.AddColumnIfMissing(new ColumnSchema(pair.Key, _columnType[pair.Value != null ? pair.Value.GetType() : typeof(string)]));
            }

            string createTable = CslCommandGenerator.GenerateTableCreateMergeCommand(tableSchema);

            admin.ExecuteControlCommand(createTable);

            string enableIngestTime = CslCommandGenerator.GenerateIngestionTimePolicyAlterCommand(TableName, true);

            admin.ExecuteControlCommand(enableIngestTime);
        }
        private List <string> Command(string command)
        {
            Log.Info($"command:{command}", ConsoleColor.Blue);

            using (ICslAdminProvider kustoAdminClient = KustoClientFactory.CreateCslAdminProvider(ManagementConnection))
            {
                return(EnumerateResults(kustoAdminClient.ExecuteControlCommand(command)));
            }
        }
        private List <string> Command(string command)
        {
            Log.Info($"command:{command}", ConsoleColor.Blue);
            if (_kustoAdminClient == null)
            {
                _kustoAdminClient = KustoClientFactory.CreateCslAdminProvider(ManagementConnection);
                adminTimer        = new Timer(DisposeAdminClient, null, maxKustoClientTimeMs, maxKustoClientTimeMs);
            }

            adminTimer.Change(maxKustoClientTimeMs, maxKustoClientTimeMs);
            return(EnumerateResults(_kustoAdminClient.ExecuteControlCommand(command)));
        }
        /// <summary>
        /// Remove any functions and tables that are present in the database. Note that this should only be called when
        /// connecting to the temporary database
        /// </summary>
        public void CleanDatabase()
        {
            if (!_tempDatabaseUsed)
            {
                throw new Exception("CleanDatabase() was called on something other than the temporary database. This method will wipe out the entire database schema and data.");
            }

            var schema = GetDatabaseSchema();

            foreach (var function in schema.Functions)
            {
                string command = CslCommandGenerator.GenerateFunctionDropCommand(function.Value.Name, true);
                _adminClient.ExecuteControlCommand(command);
            }

            foreach (var table in schema.Tables)
            {
                string command = CslCommandGenerator.GenerateTableDropCommand(table.Value.Name, true);
                _adminClient.ExecuteControlCommand(command);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Generates a Kusto table for a specific <see cref="Type"/>, by mapping it's properties to columns.
        /// </summary>
        /// <param name="client">The <see cref="ICslAdminProvider"/> that we are extending.</param>
        /// <param name="type">The <see cref="Type"/> that we are generating a table for.</param>
        /// <returns>The name of the table created.</returns>
        public static string GenerateTableFromType(this ICslAdminProvider client, Type type)
        {
            var tableName = type.Name;
            var command   = CslCommandGenerator.GenerateTableShowCommand(tableName);

            try
            {
                client.ExecuteControlCommand(command);
                return(tableName);
            }
            catch (KustoBadRequestException ex) when(ex.ErrorMessage.Contains("'Table' was not found"))
            {
                // soak
            }

            var columns = type.GetProperties().Select(property => new Tuple <string, string>(property.Name, property.PropertyType.FullName)).ToList();

            command = CslCommandGenerator.GenerateTableCreateCommand(tableName, columns);
            client.ExecuteControlCommand(command);

            return(tableName);
        }
Beispiel #7
0
        /// <summary>
        /// Remove any functions and tables that are present in the database. Note that this should only be called when
        /// connecting to the temporary database
        /// </summary>
        public void CleanDatabase()
        {
            if (!_tempDatabaseUsed)
            {
                throw new Exception("CleanDatabase() was called on something other than the temporary database.");
            }

            var schema = GetDatabaseSchema();

            if (schema.Functions.Count > 0)
            {
                _adminClient.ExecuteControlCommand(
                    CslCommandGenerator.GenerateFunctionsDropCommand(
                        schema.Functions.Select(f => f.Value.Name), true));
            }

            if (schema.Tables.Count > 0)
            {
                _adminClient.ExecuteControlCommand(
                    CslCommandGenerator.GenerateTablesDropCommand(
                        schema.Tables.Select(f => f.Value.Name), true));
            }
        }
Beispiel #8
0
 private static void KustoExecute(string command)
 {
     TestContext.Progress.WriteLine(command);
     kustoAdminClient.ExecuteControlCommand(command);
 }