public void ScanFolder() { string searchPattern = SearchPattern.Log; var repo = new DisconnectedRepository(); var fileProcessor = new FileProcessor(); LocalSetting setting = repo.GetLocalSettings(); string folderPath = @"" + setting.FolderPath; var filesToProcess = fileProcessor.FindNewFiles(folderPath, searchPattern); var ipDetails = repo.GetIpDetails(); List <string> ipNumbers = ipDetails.Select(p => p.IpNumber).ToList(); List <string> scannedIpNumbers = new List <string>(); Guid id = new Guid(); var logProcessor = new LogProcessor(); foreach (var logFile in filesToProcess) { var linesToProcess = logProcessor.FindNewlogLines(logFile); var fileInDatabase = repo.GetLogFileByFileName(logFile.FileName); if (fileInDatabase != null) { id = fileInDatabase.LogFileId; } else { id = logFile.LogFileId; repo.AddNewLogFile(logFile); } foreach (var logLine in linesToProcess) { scannedIpNumbers.Add(logLine.IpClient); logLine.LogFileId = id; repo.AddNewLogLine(logLine); } } var newIpNumbers = scannedIpNumbers.Except(ipNumbers); foreach (var item in newIpNumbers) { var ipDetail = new IpDetail(); ipDetail.IpNumber = item; repo.AddNewIpDetail(ipDetail); Console.WriteLine(item); } }
public void SaveSetting(LocalSetting localSetting) { var repo = new DisconnectedRepository(); var setting = repo.GetLocalSettings(); if (setting != null) { repo.EditLocalSetting(localSetting); } else { repo.AddNewLocalSetting(localSetting); } }
public IEnumerable <string> GetBackups() { var repo = new DisconnectedRepository(); IEnumerable <string> result = new List <string>(); var directorySearcher = new DirectorySearcher(); var setting = repo.GetLocalSettings(); if (setting != null) { result = directorySearcher.ScanFolder(setting.BackupFolder, SearchPattern.Xml); } return(result); }
public void BackupDetails() { var repo = new DisconnectedRepository(); var ipDetails = repo.GetIpDetails(); var files = repo.GetLogFiles(); var lines = repo.GetLogLines(); var setting = repo.GetLocalSettings(); var backupWriter = new BackupWriter(ipDetails, lines, files, setting); var time = DateTime.Now.ToString("yyyy.dd.mm.HH.mm"); var path = setting.BackupFolder; var fileName = path + setting.BackupName + "_details_" + time + BackupFormat.Xml; backupWriter.BackupIpDetails(fileName); }
public LocalSetting GetSettings() { var repo = new DisconnectedRepository(); return(repo.GetLocalSettings()); }