-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ms
committed
Feb 28, 2021
1 parent
e1eb4df
commit aab191d
Showing
5 changed files
with
91 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using RcloneFileWatcherCore.Logic.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using RcloneFileWatcherCore.DTO; | ||
|
||
namespace RcloneFileWatcherCore.Logic | ||
{ | ||
|
||
class Config | ||
{ | ||
private readonly string _configFileName; | ||
private readonly ILogger _logger; | ||
public Config(string configFileName, ILogger logger) | ||
{ | ||
_configFileName = configFileName; | ||
_logger = logger; | ||
} | ||
|
||
internal List<PathDTO> LoadConfig() | ||
{ | ||
try | ||
{ | ||
List<PathDTO> pathDTOs = new List<PathDTO>(); | ||
if (!File.Exists(_configFileName)) | ||
{ | ||
_logger.WriteAlways("Config file is missing"); | ||
return null; | ||
} | ||
string[] parameters = File.ReadAllLines(_configFileName); | ||
foreach (var param in parameters) | ||
{ | ||
if (param.ToUpper().Contains("CONSOLEWRITER.OFF")) | ||
{ | ||
_logger.Enable = false; | ||
} | ||
else if (param.ToUpper().Contains("CONSOLEWRITER.ON")) | ||
{ | ||
_logger.Enable = true; | ||
} | ||
else | ||
{ | ||
var item = param.Split(','); | ||
if (item.Length == 3) | ||
{ | ||
PathDTO pathDTO = new PathDTO(); | ||
pathDTO.WatchingPath = item[0]; | ||
pathDTO.RcloneFilesFromPath = item[1]; | ||
pathDTO.RcloneBatch = item[2]; | ||
pathDTOs.Add(pathDTO); | ||
} | ||
else | ||
{ | ||
_logger.WriteAlways("Error in config file."); | ||
return null; | ||
} | ||
} | ||
} | ||
return pathDTOs; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.WriteAlways(ex.ToString()); | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ interface ILogger | |
{ | ||
bool Enable { get; set; } | ||
void Write(string text); | ||
void WriteAlways(string text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters