|
3 | 3 | using NLog; |
4 | 4 | using Wikiled.Common.Arguments; |
5 | 5 | using Wikiled.Console.Arguments; |
6 | | -using Wikiled.YiScanner.Client; |
7 | 6 | using Wikiled.YiScanner.Client.Predicates; |
8 | | -using Wikiled.YiScanner.Destinations; |
9 | | -using Wikiled.YiScanner.Monitoring; |
| 7 | +using Wikiled.YiScanner.Monitoring.Config; |
10 | 8 | using Wikiled.YiScanner.Monitoring.Source; |
11 | 9 |
|
12 | 10 | namespace Wikiled.YiScanner.Commands |
13 | 11 | { |
14 | | - public abstract class BaseCommand : Command, IScanConfig |
| 12 | + public abstract class BaseCommand : Command |
15 | 13 | { |
16 | 14 | private static readonly Logger log = LogManager.GetCurrentClassLogger(); |
17 | 15 |
|
18 | | - private readonly FtpConfig ftpConfig; |
19 | | - |
20 | | - protected BaseCommand(FtpConfig ftpConfig) |
| 16 | + protected BaseCommand(MonitoringConfig config) |
21 | 17 | { |
22 | | - Guard.NotNull(() => ftpConfig, ftpConfig); |
23 | | - this.ftpConfig = ftpConfig; |
| 18 | + Guard.NotNull(() => config, config); |
| 19 | + Config = config; |
24 | 20 | } |
25 | 21 |
|
26 | | - public ActionConfig Action { get; set; } |
| 22 | + [Description("Archive video after days")] |
| 23 | + public int? Archive { get => Config.Archive; set => Config.Archive = value; } |
27 | 24 |
|
28 | 25 | [Description("Auto discover cameras")] |
29 | | - public bool? AutoDiscover { get; set; } |
| 26 | + public bool? AutoDiscover |
| 27 | + { |
| 28 | + get => Config.AutoDiscovery?.On; |
| 29 | + set |
| 30 | + { |
| 31 | + if (Config.AutoDiscovery == null) |
| 32 | + { |
| 33 | + Config.AutoDiscovery = new AutoDiscoveryConfig(); |
| 34 | + } |
30 | 35 |
|
31 | | - [Description("Discovery network mask")] |
32 | | - public string NetworkMask { get; set; } |
| 36 | + Config.AutoDiscovery.On = value; |
| 37 | + } |
| 38 | + } |
33 | 39 |
|
34 | 40 | [Required] |
35 | 41 | [Description("List of camera names")] |
36 | | - public string Cameras { get; set; } |
| 42 | + public string Cameras |
| 43 | + { |
| 44 | + get => Config.Known?.Cameras; |
| 45 | + set |
| 46 | + { |
| 47 | + if (Config.Known == null) |
| 48 | + { |
| 49 | + Config.Known = new PredefinedCameraConfig(); |
| 50 | + } |
| 51 | + |
| 52 | + Config.Known.Cameras = value; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + [Description("Compress video files")] |
| 57 | + public bool? Compress |
| 58 | + { |
| 59 | + get => Config.Output?.Compress; |
| 60 | + set |
| 61 | + { |
| 62 | + if (Config.Output == null) |
| 63 | + { |
| 64 | + Config.Output = new OutputConfig(); |
| 65 | + } |
| 66 | + |
| 67 | + Config.Output.Compress = value.Value; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + public MonitoringConfig Config { get; } |
37 | 72 |
|
38 | 73 | [Required] |
39 | 74 | [Description("List of camera hosts")] |
40 | | - public string Hosts { get; set; } |
| 75 | + public string Hosts |
| 76 | + { |
| 77 | + get => Config.Known?.Hosts; |
| 78 | + set |
| 79 | + { |
| 80 | + if (Config.Known == null) |
| 81 | + { |
| 82 | + Config.Known = new PredefinedCameraConfig(); |
| 83 | + } |
41 | 84 |
|
42 | | - [Description("Compress video files")] |
43 | | - public bool Compress { get; set; } |
| 85 | + Config.Known.Hosts = value; |
| 86 | + } |
| 87 | + } |
44 | 88 |
|
45 | 89 | [Description("Do you want to save it as image")] |
46 | | - public bool Images { get; } |
| 90 | + public bool? Images |
| 91 | + { |
| 92 | + get => Config.Output?.Images; |
| 93 | + set |
| 94 | + { |
| 95 | + if (Config.Output == null) |
| 96 | + { |
| 97 | + Config.Output = new OutputConfig(); |
| 98 | + } |
| 99 | + |
| 100 | + Config.Output.Images = value.Value; |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + [Description("Discovery network mask")] |
| 105 | + public string NetworkMask |
| 106 | + { |
| 107 | + get => Config.AutoDiscovery?.NetworkMask; |
| 108 | + set |
| 109 | + { |
| 110 | + if (Config.AutoDiscovery == null) |
| 111 | + { |
| 112 | + Config.AutoDiscovery = new AutoDiscoveryConfig(); |
| 113 | + } |
| 114 | + |
| 115 | + Config.AutoDiscovery.NetworkMask = value; |
| 116 | + } |
| 117 | + } |
47 | 118 |
|
48 | 119 | [Required] |
49 | 120 | [Description("File destination")] |
50 | | - public string Out { get; set; } |
| 121 | + public string Out |
| 122 | + { |
| 123 | + get => Config.Output?.Out; |
| 124 | + set |
| 125 | + { |
| 126 | + if (Config.Output == null) |
| 127 | + { |
| 128 | + Config.Output = new OutputConfig(); |
| 129 | + } |
51 | 130 |
|
52 | | - [Description("Archive video after days")] |
53 | | - public int? Archive { get; set; } |
| 131 | + Config.Output.Out = value; |
| 132 | + } |
| 133 | + } |
54 | 134 |
|
55 | 135 | public override void Execute() |
56 | 136 | { |
57 | 137 | log.Info("Starting camera download..."); |
58 | | - SourceFactory factory = new SourceFactory(ftpConfig, this, ConstructPredicate()); |
| 138 | + SourceFactory factory = new SourceFactory(Config, ConstructPredicate()); |
59 | 139 | ProcessFtp(factory); |
60 | 140 | } |
61 | 141 |
|
|
0 commit comments