0

I'm developing a Windows service which monitors different configurations of directories and does some file operations (copies newly created files from source to target directories).

It can have one or more source directories to monitor and it can have one or more target directories to copy the newly available files to.

Ideally, I would like to be able to start the service from the command line with a number of arguments such like this:

$ sc start fileMonitorService from= "/path/to/first/source/dir, /path/to/second/source/dir" to= "/path/to/first/out/dir, /path/to/second/out/dir"

What's a recommended way of organising a program like that?

TMOTTM
  • 3,286
  • 6
  • 32
  • 63
  • 1
    Short answer: you don't do this. You could probably do this with a config file that it reads on startup but I don't really understand why you would use a service in this way. – DavidG Sep 05 '19 at 15:31
  • A config File is a good idea. Gonna look into it. The service is needed because its a situation where these directories need to be monitored. What would be the alternative to a service here? – TMOTTM Sep 05 '19 at 15:39
  • 1
    If you need to dynamically change configuration, host a REST API (locked down to local requests) that can accept configuration changes and restructure your service to be able to change what it's watching without having to restart. Then write an application (command line, WinForms, whatever) that sends API requests to make the changes you want. You could also write your configuration back to disk so it persists across restarts. – madreflection Sep 05 '19 at 15:53
  • 1
    You don't need to add a REST API that may not otherwise be part of the system architecture. You can use a config file with a file watcher on that config file. Have the watcher reload the configuration when the config file changes. – Eric J. Sep 05 '19 at 17:48
  • @madreflection I'm not yet completely comfortable developing REST APIs. In the scenario here, what would be the "ressource" then? The configuration of the Windows Service? – TMOTTM Sep 06 '19 at 07:12
  • Sure. Doesn't have to be true REST, either, or even HTTP-based. You could use named pipes if you wanted. The point is that you could communicate with the service while it's running instead of having to restart it to load new configuration. EricJ.'s idea of using a file watcher also would work. – madreflection Sep 06 '19 at 07:18

1 Answers1

0

Use App.config for this purpose with ConfigurationSection in case you are watching multiple folders and you may use the FileSystemWatcher class to monitor the folders.

Vinod Srivastav
  • 3,644
  • 1
  • 27
  • 40