Exemple #1
0
        public void Restore(string filePath)
        {
            var repo   = new DisconnectedRepository();
            var reader = new BackupReader();

            var ipDetails = reader.ParseIpDetails(filePath);
            var files     = reader.ParseLogFiles(filePath);
            var lines     = reader.ParseLogLines(filePath);



            repo.ClearTables();

            foreach (var detail in ipDetails)
            {
                repo.AddNewIpDetail(detail);
            }


            foreach (var file in files)
            {
                repo.AddNewLogFile(file);
            }


            foreach (var line in lines)
            {
                repo.AddNewLogLine(line);
            }
        }
Exemple #2
0
        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);
            }
        }