Skip to content

Commit c1e8eab

Browse files
authored
Merge pull request #106768 from MarkHeff/csharptutorial-updates
Add ExitProgram to C# Tutorial
2 parents aecee48 + 41dfd99 commit c1e8eab

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

articles/search/cognitive-search-tutorial-blob-dotnet.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace EnrichwithAI
182182

183183
### Create a client
184184

185-
Create an instance of the `SearchServiceClient` class under Main.
185+
Create an instance of the `SearchServiceClient` class under `Main`.
186186

187187
```csharp
188188
public static void Main(string[] args)
@@ -210,6 +210,22 @@ private static SearchServiceClient CreateSearchServiceClient(IConfigurationRoot
210210
> The `SearchServiceClient` class manages connections to your search service. In order to avoid opening too many connections, you should try to share a single instance of `SearchServiceClient` in your application if possible. Its methods are thread-safe to enable such sharing.
211211
>
212212

213+
### Add function to exit the program during failure
214+
215+
This tutorial is meant to help you understand each step of the indexing pipeline. If there is a critical issue that prevents the program from creating the data source, skillset, index, or indexer the program will output the error message and exit so that the issue can be understood and addressed.
216+
217+
Add `ExitProgram` to `Main` to handle scenarios that require the program to exit.
218+
219+
```csharp
220+
private static void ExitProgram(string message)
221+
{
222+
Console.WriteLine("{0}", message);
223+
Console.WriteLine("Press any key to exit the program...");
224+
Console.ReadKey();
225+
Environment.Exit(0);
226+
}
227+
```
228+
213229
## 3 - Create the pipeline
214230

215231
In Azure Cognitive Search, AI processing occurs during indexing (or data ingestion). This part of the walkthrough creates four objects: data source, index definition, skillset, indexer.
@@ -247,7 +263,7 @@ private static DataSource CreateOrUpdateDataSource(SearchServiceClient serviceCl
247263

248264
For a successful request, the method will return the data source that was created. If there is a problem with the request, such as an invalid parameter, the method will throw an exception.
249265

250-
Now add a line in Main to call the `CreateOrUpdateDataSource` function that you've just added.
266+
Now add a line in `Main` to call the `CreateOrUpdateDataSource` function that you've just added.
251267

252268
```csharp
253269
public static void Main(string[] args)
@@ -533,7 +549,7 @@ private static Skillset CreateOrUpdateDemoSkillSet(SearchServiceClient serviceCl
533549
}
534550
```
535551
536-
Add the following lines to Main.
552+
Add the following lines to `Main`.
537553
538554
```csharp
539555
// Create the skills
@@ -671,7 +687,7 @@ private static Index CreateDemoIndex(SearchServiceClient serviceClient)
671687
672688
During testing you may find that you're attempting to create the index more than once. Because of this, check to see if the index that you're about to create already exists before attempting to create it.
673689
674-
Add the following lines to Main.
690+
Add the following lines to `Main`.
675691
676692
```csharp
677693
// Create the index
@@ -775,7 +791,7 @@ private static Indexer CreateDemoIndexer(SearchServiceClient serviceClient, Data
775791
return indexer;
776792
}
777793
```
778-
Add the following lines to Main.
794+
Add the following lines to `Main`.
779795
780796
```csharp
781797
// Create the indexer, map fields, and execute transformations
@@ -836,7 +852,7 @@ private static void CheckIndexerOverallStatus(SearchServiceClient serviceClient,
836852
837853
Warnings are common with some source file and skill combinations and do not always indicate a problem. In this tutorial, the warnings are benign (for example, no text inputs from the JPEG files).
838854
839-
Add the following lines to Main.
855+
Add the following lines to `Main`.
840856
841857
```csharp
842858
// Check indexer overall status
@@ -850,7 +866,7 @@ After indexing is finished, you can run queries that return the contents of indi
850866
851867
As a verification step, query the index for all of the fields.
852868
853-
Add the following lines to Main.
869+
Add the following lines to `Main`.
854870
855871
```csharp
856872
DocumentSearchResult<DemoIndex> results;
@@ -886,7 +902,7 @@ private static SearchIndexClient CreateSearchIndexClient(IConfigurationRoot conf
886902
}
887903
```
888904
889-
Add the following code to Main. The first try-catch returns the index definition, with the name, type, and attributes of each field. The second is a parameterized query, where `Select` specifies which fields to include in the results, for example `organizations`. A search string of `"*"` returns all contents of a single field.
905+
Add the following code to `Main`. The first try-catch returns the index definition, with the name, type, and attributes of each field. The second is a parameterized query, where `Select` specifies which fields to include in the results, for example `organizations`. A search string of `"*"` returns all contents of a single field.
890906
891907
```csharp
892908
//Verify content is returned after indexing is finished

0 commit comments

Comments
 (0)