static void Main(string[] args)
        {
            // Ingest From Local Files using KustoQueuedIngestClient and Ingestion Validation

            // Create Kusto connection string with App Authentication
            var kustoConnectionStringBuilderDM =
                new KustoConnectionStringBuilder(@"https://ingest-{clusterNameAndRegion}.kusto.windows.net").WithAadApplicationKeyAuthentication(
                    applicationClientId: "{Application Client ID}",
                    applicationKey: "{Application Key (secret)}",
                    authority: "{AAD TenantID or name}");

            // Create a disposable client that will execute the ingestion
            IKustoQueuedIngestClient client = KustoIngestFactory.CreateQueuedIngestClient(kustoConnectionStringBuilderDM);

            // Ingest from files according to the required properties
            var kustoIngestionProperties = new KustoIngestionProperties(databaseName: "myDB", tableName: "myTable");

            client.IngestFromStorageAsync(@"ValidTestFile.csv", kustoIngestionProperties);
            client.IngestFromStorageAsync(@"InvalidTestFile.csv", kustoIngestionProperties);

            // Waiting for the aggregation
            Thread.Sleep(TimeSpan.FromMinutes(8));

            // Retrieve and validate failures
            var ingestionFailures = client.PeekTopIngestionFailures().GetAwaiter().GetResult();

            Ensure.IsTrue((ingestionFailures.Count() > 0), "Failures expected");
            // Retrieve, delete and validate failures
            ingestionFailures = client.GetAndDiscardTopIngestionFailures().GetAwaiter().GetResult();
            Ensure.IsTrue((ingestionFailures.Count() > 0), "Failures expected");

            // Dispose of the client
            client.Dispose();
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            // Ingest From a Local File using KustoQueuedIngestClient and report status to a table

            // Create Kusto connection string with App Authentication
            var kustoConnectionStringBuilderDM =
                new KustoConnectionStringBuilder(@"https://ingest-{clusterNameAndRegion}.kusto.windows.net").WithAadApplicationKeyAuthentication(
                    applicationClientId: "{Application Client ID}",
                    applicationKey: "{Application Key (secret)}",
                    authority: "{AAD TenantID or name}");

            // Create a disposable client that will execute the ingestion
            IKustoQueuedIngestClient client = KustoIngestFactory.CreateQueuedIngestClient(kustoConnectionStringBuilderDM);

            // Ingest from a file according to the required properties
            var kustoIngestionProperties = new KustoQueuedIngestionProperties(databaseName: "myDB", tableName: "myDB")
            {
                // Setting the report level to FailuresAndSuccesses will cause both successful and failed ingestions to be reported
                // (Rather than the default "FailuresOnly" level)
                ReportLevel = IngestionReportLevel.FailuresAndSuccesses,
                // Choose the report method of choice
                ReportMethod = IngestionReportMethod.Table
            };

            var filePath        = @"< Path to file >";
            var fileIdentifier  = Guid.NewGuid();
            var fileDescription = new FileDescription()
            {
                FilePath = filePath, SourceId = fileIdentifier
            };
            var sourceOptions = new StorageSourceOptions()
            {
                SourceId = fileDescription.SourceId.Value
            };

            // Execute the ingest operation and save the result.
            var clientResult = await client.IngestFromStorageAsync(fileDescription.FilePath,
                                                                   ingestionProperties : kustoIngestionProperties, sourceOptions);

            // Use the fileIdentifier you supplied to get the status of your ingestion
            var ingestionStatus = clientResult.GetIngestionStatusBySourceId(fileIdentifier);

            while (ingestionStatus.Status == Status.Pending)
            {
                // Wait a minute...
                Thread.Sleep(TimeSpan.FromMinutes(1));
                // Try again
                ingestionStatus = clientResult.GetIngestionStatusBySourceId(fileIdentifier);
            }

            // Verify the results of the ingestion
            Ensure.ConditionIsMet(ingestionStatus.Status == Status.Succeeded,
                                  "The file should have been ingested successfully");

            // Dispose of the client
            client.Dispose();
        }
        static void Main(string[] args)
        {
            // Ingest From a Local Files using KustoQueuedIngestClient and report status to a queue

            // Create Kusto connection string with App Authentication
            var kustoConnectionStringBuilderDM =
                new KustoConnectionStringBuilder(@"https://ingest-{clusterNameAndRegion}.kusto.windows.net").WithAadApplicationKeyAuthentication(
                    applicationClientId: "{Application Client ID}",
                    applicationKey: "{Application Key (secret)}",
                    authority: "{AAD TenantID or name}");

            // Create a disposable client that will execute the ingestion
            IKustoQueuedIngestClient client = KustoIngestFactory.CreateQueuedIngestClient(kustoConnectionStringBuilderDM);

            // Ingest from a file according to the required properties
            var kustoIngestionProperties = new KustoQueuedIngestionProperties(databaseName: "myDB", tableName: "myTable")
            {
                // Setting the report level to FailuresAndSuccesses will cause both successful and failed ingestions to be reported
                // (Rather than the default "FailuresOnly" level - which is demonstrated in the
                // 'Ingest From Local File(s) using KustoQueuedIngestClient and Ingestion Validation' section)
                ReportLevel = IngestionReportLevel.FailuresAndSuccesses,
                // Choose the report method of choice. 'Queue' is the default method.
                // For the sake of the example, we will choose it anyway.
                ReportMethod = IngestionReportMethod.Queue
            };

            client.IngestFromStorageAsync("ValidTestFile.csv", kustoIngestionProperties);
            client.IngestFromStorageAsync("InvalidTestFile.csv", kustoIngestionProperties);

            // Waiting for the aggregation
            Thread.Sleep(TimeSpan.FromMinutes(8));

            // Retrieve and validate failures
            var ingestionFailures = client.PeekTopIngestionFailures().GetAwaiter().GetResult();

            Ensure.IsTrue((ingestionFailures.Count() > 0), "The failed ingestion should have been reported to the failed ingestions queue");
            // Retrieve, delete and validate failures
            ingestionFailures = client.GetAndDiscardTopIngestionFailures().GetAwaiter().GetResult();
            Ensure.IsTrue((ingestionFailures.Count() > 0), "The failed ingestion should have been reported to the failed ingestions queue");

            // Verify the success has also been reported to the queue
            var ingestionSuccesses = client.GetAndDiscardTopIngestionSuccesses().GetAwaiter().GetResult();

            Ensure.ConditionIsMet((ingestionSuccesses.Count() > 0),
                                  "The successful ingestion should have been reported to the successful ingestions queue");

            // Dispose of the client
            client.Dispose();
        }
Exemple #4
0
 /// <summary>
 ///     Synchronously waits until all posted files have been uploaded, then disposes the internal Kusto client.
 /// </summary>
 public void Dispose()
 {
     CompleteAndWaitForPendingUploadsToFinish();
     _client.Dispose();
 }