Beispiel #1
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);
            }
        }