Self-Service WebAPI

I have a console application that is ASP.Net WebAPI self-service. I would like the console application to terminate itself based on a specific call in WebAPI.

The console application is largely based on the example found here β†’ http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api

To provide some context;

The console application will be used in conjunction with Jenkins CI to automate the testing of BDD Android applications. Jenkins will be responsible for creating, installing and launching the Android application - he will call this console application. The Android application will go through a series of Jasmine BDD tests that automatically return Jenkins updates through the console application / WebAPI. Upon completion of the tests, the Android application will trigger a specific WebAPI action - at this point I want it to complete the console application so that Jenkins moves to the next build step.

Thanks in advance.

+4
source share
2 answers

Just use ManualResetEvent . In your program class, add a static public field:

 public static System.Threading.ManualResetEvent shutDown = new ManualResetEvent(false); 

And then in the main method:

 config.Routes.MapHttpRoute( "API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional }); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); //Console.WriteLine("Press Enter to quit."); //Console.ReadLine(); shutDown.WaitOne(); } 

And then in the corresponding API method:

 Program.shutDown.Set(); 

When your main method exits, the program will stop.

+7
source

To disable a regular .Net application, you can use:

 System.Environment.Exit(0) 

See MSDN

0
source

Source: https://habr.com/ru/post/1490438/


All Articles