static Program() { try { ContinuationInfo = RestoreContinuationInfo(); } catch (Exception e) { Console.WriteLine(e); throw; } }
private static ContinuationInfo RestoreContinuationInfo() { var lines = File.ReadAllLines(ContinuationInfoStorePath); if (!lines.Any() || !lines[0].Contains("|")) { return(new ContinuationInfo()); } var words = lines[0].Split('|'); var result = new ContinuationInfo() { LenstraVersion = words[0], ProcessingFileName = words[1] }; var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; var dataDir = Path.GetFullPath(Path.Combine(baseDirectory, @"..\..\Data", result.LenstraVersion)); var lastCreatedFile = Directory.GetFiles(dataDir) .Where(fileName => fileName.EndsWith(".txt")) .OrderBy(File.GetCreationTime) .LastOrDefault(); if (lastCreatedFile == null) { return(result); } var lastHandledNumber = File.ReadAllLines(lastCreatedFile).Last().Split('|')[0]; var lastProcessedLine = File.ReadAllLines(result.ProcessingFileName) .Select(line => line.Split('|')[0]) .TakeWhile(tn => tn != lastHandledNumber) .Count() + 1; result.LastProcessedLine = lastProcessedLine; return(result); }