A directory monitoring class. When a certain type of file is created, it is "locked" and read, passed to another class and then deleted.
Please read the attached documents carefully before bidding.
## Deliverables
### DirectoryWatcher
Namespace: [login to view URL]
Overview
This is a class that invokes a RuleEngine (re) whenever a file is created in a directory. There may be multiple directories being watched and there may be multiple applications, on different machines, watching the same directories. When a file in a directory changes the file is read and the RulesEngine is invoked.
A call to beginWatching will start the process of watching the directories.
Processing is done in the single thread, as user intervention may be required.
**Details**
An xml configuration file will determine the rules. The configuration file will be located at [login to view URL] + "[\\[login to view URL]][1]". The class constructor will load it. The structure will be:
<rules>
<ruleset directoryName="...." />
<ruleset directoryName="...." />
....
</rules>
An xml configuration file ([login to view URL]) will have 'ruleset' nodes with an attribute of 'directoryName'. The method beginWatching() should read the configuration file and watch every directory referenced for changed files.
When a file has been changed first verify that the extension of the file is CSV then verify that there is no file of the same name with a "lock" extension. Then write a lock file into the directory, catering for race conditions. If successful, the ruleset node matching the directory that has the modified file needs to be found within the xml file i.e. .selectSingleNode("//ruleset[@directoryName='directory']".
An object (re) of type RuleEngine (namespace AgentMangler) is created passing the ruleset to the constructor and the method:
Public void [login to view URL](stream csvData)
Is called. When the method completes the file is to be moved to the Done folder (as specified as an attribute on the ruleset) and the lock file removed.
The process method may throw an InvalidEntity error in which case the original file is moved to a designated errors folder (attribute errorFolder) and the lock file removed. An email is then sent out to a predesignated email address.
The To: email address will be an attribute (errorEmail) on the ruleset
The From: email address will be an attribute (email) on the rules.documentElement.
The SMTP server will be an attribute (smtp) on the rules.documentElement.
The subject should be "Error parsing file"
The body should contain the record number (+1) of the toBeProcessed object that failed and the file name.
Simple email code shown below:
[login to view URL] message = new [login to view URL]();
[login to view URL]("[luckyperson@[login to view URL]][2]");
[login to view URL] = "This is the Subject line";
[login to view URL] = new [login to view URL]("[From@[login to view URL]][3]");
[login to view URL] = "This is the message body";
[login to view URL] smtp = new [login to view URL]("yoursmtphost");
[login to view URL](message);
# Scope
The class [login to view URL] is required.
Unit tests in [login to view URL]
The unit test should verify the functionality of :
* Monitoring a directory
* Finding, and passing, the correct ruleset node
* The full file locking process
* emails
The class Config will be mocked for the unit test
The class RuleEngine will be mocked for the unit test
The mocked objects should be located in a separate file [login to view URL]