1 /** 2 * Copyright © DiamondMVC 2019 3 * License: MIT (https://github.com/DiamondMVC/Diamond/blob/master/LICENSE) 4 * Author: Jacob Jensen (bausshf) 5 */ 6 module diamond.security.backup.backupservice; 7 8 import diamond.security.backup.backuppath; 9 10 /// Wrapper around a backup service. 11 abstract class BackupService 12 { 13 private: 14 /// The paths to backup. 15 BackupPath[] _paths; 16 /// The time to wait between backing up. 17 size_t _time; 18 19 protected: 20 /** 21 * Creates a new backup service. 22 * Params: 23 * time = The time to wait between backing up. 24 */ 25 this(size_t time) 26 { 27 _time = time; 28 } 29 30 /** 31 * Handler for performing a backup. 32 * Params: 33 * paths = The paths to backup. 34 */ 35 abstract void onBackup(const(BackupPath[]) paths); 36 37 public: 38 @property 39 { 40 /// Gets the time to wait between backing up. 41 const(size_t) time() { return _time; } 42 } 43 /** 44 * Adds a path to backup. 45 * Params: 46 * path = The path to backup. 47 */ 48 void addPath(BackupPath path) 49 { 50 _paths ~= path; 51 } 52 53 package(diamond): 54 /// Performs the specified backup. 55 void backup() 56 { 57 if (_paths) 58 { 59 onBackup(_paths); 60 } 61 } 62 }