コード例 #1
0
        static void Main(string[] args)
        {
            if (!ParseCommandLine(args, out var cluster, out var database, out var table))
            {
                Usage();
                return;
            }

            var kcsb = new KustoConnectionStringBuilder
            {
                DataSource = cluster
            };

            kcsb = kcsb.WithAadUserPromptAuthentication();

            CreateJsonMappingIfNotExists(kcsb, database, table);

            // Do ingestion using Kusto.Data client library
            using (var siClient = KustoClientFactory.CreateCslStreamIngestClient(kcsb))
            {
                using (var data = CreateSampleEventLogCsvStream(10))
                {
                    siClient.ExecuteStreamIngest(database, table, data);
                }

                using (var data = CreateSampleEventLogJsonStream(10))
                {
                    siClient.ExecuteStreamIngestAsync(
                        database,
                        table,
                        data,
                        null,
                        Kusto.Data.Common.DataSourceFormat.json,
                        compressStream: false,
                        mappingName: s_jsonMappingName);
                }
            }

            // Do ingestion using Kusto.Ingest client library. The data still goes directly to the engine cluster
            // Just a convenience for applications already using IKustoIngest interface
            using (var ingestClient = KustoIngestFactory.CreateStreamingIngestClient(kcsb))
            {
                using (var data = CreateSampleEventLogCsvStream(10))
                {
                    var ingestProperties = new KustoIngestionProperties(database, table)
                    {
                        Format = DataSourceFormat.csv,
                    };
                    ingestClient.IngestFromStreamAsync(data, ingestProperties);
                }

                using (var data = CreateSampleEventLogJsonStream(10))
                {
                    var ingestProperties = new KustoIngestionProperties(database, table)
                    {
                        Format = DataSourceFormat.json,
                        JSONMappingReference = s_jsonMappingName
                    };

                    ingestClient.IngestFromStreamAsync(data, ingestProperties);
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var kcsb = new KustoConnectionStringBuilder();

            kcsb.DataSource        = "https://kustolab.kusto.windows.net";
            kcsb.FederatedSecurity = true;

            string databaseName = "StreamingIngestionSample";
            string tableName    = "EventLog";

            CreateJsonMappingIfNotExists(kcsb, databaseName, tableName);

            // Do ingestion using Kusto.Data client library
            using (var siClient = KustoClientFactory.CreateCslStreamIngestClient(kcsb))
            {
                using (var data = CreateSampleEventLogCsvStream(10))
                {
                    siClient.ExecuteStreamIngestAsync(
                        databaseName,
                        tableName,
                        data,
                        null,
                        DataSourceFormat.csv);
                }

                using (var data = CreateSampleEventLogJsonStream(10))
                {
                    siClient.ExecuteStreamIngestAsync(
                        databaseName,
                        tableName,
                        data,
                        null,
                        DataSourceFormat.json,
                        compressStream: false,
                        mappingName: s_jsonMappingName).ResultEx();
                }
            }

            // Do ingestion using Kusto.Ingest client library. The data still goes directly to the engine cluster
            // Just a convenience for applications already using IKustoIngest interface
            using (var ingestClient = KustoIngestFactory.CreateStreamingIngestClient(kcsb))
            {
                using (var data = CreateSampleEventLogCsvStream(10))
                {
                    var ingestProperties = new KustoIngestionProperties(databaseName, tableName)
                    {
                        Format = DataSourceFormat.csv,
                    };
                    ingestClient.IngestFromStreamAsync(data, ingestProperties).ResultEx();
                }

                using (var data = CreateSampleEventLogJsonStream(10))
                {
                    var ingestProperties = new KustoIngestionProperties(databaseName, tableName)
                    {
                        Format           = DataSourceFormat.json,
                        IngestionMapping = new IngestionMapping {
                            IngestionMappingKind = Kusto.Data.Ingestion.IngestionMappingKind.Json, IngestionMappingReference = s_jsonMappingName
                        }
                    };

                    ingestClient.IngestFromStream(data, ingestProperties);
                }
            }
        }