|
1 | 1 | # FileMonitor |
2 | | -File Monitor is an utility for monitor changes and automate action on them |
| 2 | +File Monitor is an utility for monitor changes and automate action on them. You need this program if you want to do something like the case below, **without writing a line of code**: |
| 3 | + |
| 4 | +* Copy a file from location A to locatio B |
| 5 | +* Roll a file basing on size |
| 6 | +* Do something when some user (or one specific user) edit a file |
| 7 | +* Send an email when some file is deleted |
| 8 | +* Send an alert when a file become bigger than a given value |
| 9 | +* Count number of access on a file in a given amount of time |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +##How to use |
| 14 | +1. Download "dist" folder |
| 15 | +2. set up config.json |
| 16 | +3. run executable |
| 17 | + |
| 18 | +##How to configure |
| 19 | +Configure FileMonitor is easy you just have to |
| 20 | + |
| 21 | +1. list all file you want to listen. Each entry can be a set of file using * selector. You can specify many set of file by adding an entry in "Filters" property of config (see example below) |
| 22 | +2. For each *Filter* (set of file to be monitored) you can specify many *action* to do on a given *event* |
| 23 | +3. Each action is described by an ActionName (Move,Copy, SendEmail,etc..) and basing on action type could need additiona parameter, i.e. the recipient for email to send in SendEmail case. |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +##Example of usage |
| 28 | +create a file "config.json" (on template will be create if missing) |
| 29 | + |
| 30 | +Foreach file filter you can specify wich action to do for each event. |
| 31 | + |
| 32 | +```json |
| 33 | +{ |
| 34 | + "Filters": [ |
| 35 | + { |
| 36 | + "FileFolder": "C:\\temp\\", |
| 37 | + "FileName": "*.txt", |
| 38 | + "OnChange": [ |
| 39 | + { |
| 40 | + "ActionName": "Move", |
| 41 | + "Arguments": { "destination": "C:\\temp\\{filename}_{dt}.txt" } |
| 42 | + } |
| 43 | + ], |
| 44 | + "OnNew": null, |
| 45 | + "OnDeleted": null |
| 46 | + } |
| 47 | + ] |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +##Core Actions |
| 52 | +Here are reported the action shipped with FileMonitor. Many addctional action can be implemented by following the guide above. |
| 53 | + |
| 54 | +ActionName|Description| |
| 55 | +----------|-----------| |
| 56 | +Move| move the file monitored to a destination| |
| 57 | + |
| 58 | +##Contributor Actions |
| 59 | +Please contact us opening an issue to have you plugin listed here. |
| 60 | + |
| 61 | +ActionName|Description|Author| |
| 62 | +----------|-----------|------| |
| 63 | + |
| 64 | + |
| 65 | +##How to extend a plugin |
| 66 | + |
| 67 | +You just have to implement FileProcessor class, where |
| 68 | +* *ActionName:* is the name of the action. It have to be unique, so it's a good idea to use a prefix in case you whant to share it with others, to avoid naming collision. i.e. you can use mynickname.Action insthead of Action. _just place an hardcoded string_ |
| 69 | +* *Process:* Take in input all an object that stores: |
| 70 | + * info about the file and history of last changes |
| 71 | + * arguments specified by the user in config.json for your action, |
| 72 | + * the result of previous steps |
| 73 | + |
| 74 | +```cs |
| 75 | + public class Move : Core.FileProcessor |
| 76 | + { |
| 77 | + public override string ActionName |
| 78 | + { |
| 79 | + get |
| 80 | + { |
| 81 | + return "Move"; |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public override void Process(EventContext context) |
| 86 | + { |
| 87 | + if (!context.Arguments.ContainsKey("destination")) throw new Exception("Move action requires destination field"); |
| 88 | + |
| 89 | + string destination = context.Arguments["destination"]; |
| 90 | + destination = destination.Replace("{filename}", Path.GetFileName(context.File.FilePath)); |
| 91 | + destination = destination.Replace("{sourceDir}", Path.GetDirectoryName(context.File.FilePath)); |
| 92 | + destination = destination.Replace("{sourceExt}", Path.GetExtension(context.File.FilePath)); |
| 93 | + destination = destination.Replace("{dt}", DateTime.Now.ToString("yyyy-MM-dd-HHmmSS")); |
| 94 | + File.Move(context.File.FilePath, destination); |
| 95 | + } |
| 96 | + } |
| 97 | +``` |
| 98 | + |
| 99 | +Do you want to try coding? It's simple to start: just |
| 100 | + |
| 101 | +1. open your ide and create a library project |
| 102 | +2. add FileMonitor from nuget. This will allow you to see interface and classes from the core |
| 103 | +3. implement your file processor using this guide |
| 104 | +4. copy your library and all dependencies on the path |
| 105 | +5. edit config.json and run FileMonitor |
| 106 | + |
| 107 | +#License |
| 108 | + |
| 109 | + Copyright (c) 2015 Daniele Fotnani. |
| 110 | + |
| 111 | + This program is free software: you can redistribute it and/or modify |
| 112 | + it under the terms of the GNU Lesser General Public License as |
| 113 | + published by the Free Software Foundation, version 3. |
| 114 | + |
| 115 | + This program is distributed in the hope that it will be useful, but |
| 116 | + WITHOUT ANY WARRANTY; without even the implied warranty of |
| 117 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 118 | + Lesser General Lesser Public License for more details. |
| 119 | + |
| 120 | + You should have received a copy of the GNU Lesser General Public License |
| 121 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 122 | + |
| 123 | + |
0 commit comments