Building our main program

Now that everything is in place, let's start building our microservice. We will start by adding three variables we need to keep track of. The first is the name of the directory we should monitor for changes. This will be a directory called test located directly under our executing assembly directory:

private static readonly string _testDir = Directory.GetCurrentDirectory() + @"test";

The second variable will track if we want to monitor subdirectories for changes as well:

private static readonly bool _includeSubDirectories = true;

As an example, we might have a main (testDir) called Incoming and one called Outgoing, and underneath would be subdirectories for the vendors that we use. Our filesystem might look something like the following:

Our third variable is perhaps the most helpful in that it prevents us from supplying duplicate events to the user. For those that have written filewatchers before, you know that many duplicate events can be triggered when files are created, especially the larger they are. This next variable helps us manage that:

private static readonly bool _excludeDuplicateEvents = true;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset