Hello Perigee!
Resources
Our first application
Go ahead and create a new .NET 5/6+ console application. Open up Program.cs
, and head to the first step to get started!
If you haven't gone through the installation step, please do so first!
Step 1) The application starting point
Let's start with the basics. First let's create a new application in Program.cs
. Depending on the version of .NET you started with, you'll see two different things when you open Program.cs
Net 6++
The .NET 6 ++ version looks like this:
If this is the case, delete Line 2 - Console.WriteLine("Hello, World!");
and start there.
Net 5 and lower
The .NET 5 and below versions looks like this:
If this is the case, start coding on Line 6.
The application code
Now that we know where to start, here's a simple Perigee application.
Let's look what what we have here in the constructor:
Line 2 -
"FirstApp"
- The name of the application, this can be whatever you like!Line 3 -
taskConfig block
- This block is where we add any and all thread managed tasks.
Step 2) Adding thread managed code
This wouldn't be a hello tutorial without writing "Hello, World!", so let's add a CRON method to log Hello Perigee
every 15 seconds!
The .AddCron
method adds a new thread to the system. Each thread is managed by Perigee and is independent of every other thread. This is an important aspect of Perigee Application Design as it allows for individual thread management. Threads do not affect each other, and Perigee's internal thread management system has mechanisms in place to automatically restart downed threads.
Line 4 - We use fluent syntax to
.AddCRON()
- This method takes aname
,CRON string
, and acallback(cancelToken, ILogger)
.Line 5 - We use the built in logger passed to us to log information in a templated format, passing in the name of the application to the logger.
Running the application produces a log new line every 15 seconds!
To close this application using graceful shutdown, press CTRL-C, it will start the safe shutdown procedure allowing the application to properly stop all running tasks before just exiting out.
Hello Perigee - Extended
Simply replace .AddCron()
with the directory watcher instead, full code below:
Here's a sample.csv
:
Voila! You're now watching for CSV files, reading them in, and reporting on the number of rows and columns.
For an intro to Perigee we accomplished quite a lot.
We learned about threads - how they're added and independent of each other.
We learned about logging information to the available sinks.
CRON strings and how to use a CRON thread.
How to configure Perigee.
What "Graceful Shutdown" looks like.
We even got to see the CSV reader in action.
Let's hop over to the next section and continue!
Last updated