public void Start(GeneratorTask task) { if (string.IsNullOrEmpty(task.NodesDescription)) { return; } ThreadCount = task.ThreadsCount; lock (ForcedLock) { LastState = SuperUtilities.RestoreLastState(ConfigurationManager.AppSettings["LastStatePath"]); } var nodes = task.Nodes; if (task.NodesDescription.Equals(LastState.NodesDescription)) { var curN = nodes.SkipWhile(x => x != LastState.CurrentNodesCount).ToList(); nodes = curN.Any() ? curN : nodes; } else { LastState = new LastState(); LastState.NodesDescription = task.NodesDescription; } _report.ReportId = Guid.NewGuid(); _report.ComputerInfo = SuperUtilities.GetProcessorInfo(); _report.ThreadCount = task.ThreadsCount; _report.StudentFullName = task.StudentFullName; _report.ExtendedInfo = new ExtendedInformation { Descriptions = new List <ParametersDescription>() }; foreach (var nodesCount in nodes) { Console.WriteLine($"Synthesis for nodes count: {nodesCount}"); var paramDescription = new ParametersDescription { OptimalCirculants = new List <CirculantParameters>() }; var result = GenerateOptimalCirculants(nodesCount, task.Dimension); if (result == null || ForcedStop) { // _report.TotalTime += result?.FirstOrDefault()?.TotalMilliseconds ?? TotalTime; paramDescription.IsFinished = false; _report.ExtendedInfo.Descriptions.Add(paramDescription); paramDescription.LastState = LastState; break; } paramDescription.IsFinished = true; paramDescription.OptimalCirculants.AddRange(result); _report.TotalTime += result?.FirstOrDefault()?.TotalMilliseconds ?? 0; _report.ExtendedInfo.Descriptions.Add(paramDescription); SuperUtilities.SaveResultsInFolder(result, task.OutputFolderPath); } ReportBuilder.SaveInfo(_report, Path.Combine(task.OutputFolderPath, $"{_report.ValidFullName}-{DateTime.Now:yyyyMMdd.hhmm}.bin")); Console.WriteLine($"Synthesis is ended, type stop (or another chars) for exit."); //Console.In.Close(); //Console.ReadKey(true); }
public static void Main(string[] args) { var file = ReadFileFromFolder(); if (!string.IsNullOrEmpty(file.Item1)) { string xml = null; try { var bytes = Convert.FromBase64String(file.Item1); if (bytes.Any()) { xml = Encoding.UTF8.GetString(bytes); } } catch (Exception ex) { Console.WriteLine("Cant convert from base64. Error message: {0}", ex.Message); } if (!string.IsNullOrEmpty(xml)) { var basicInfo = ReportBuilder.GetBasicWorkInformation(xml); if (basicInfo != null) { var folderName = $"Output\\{basicInfo.ValidFullName}"; var dirInfo = new DirectoryInfo(folderName); if (!dirInfo.Exists) { dirInfo.Create(); } var localPath = Path.Combine(folderName, "total.csv"); if (!File.Exists(localPath)) { File.AppendAllText(localPath, BasicWorkInformation.HeadersString + Environment.NewLine, new UTF8Encoding(true)); } foreach (var desc in basicInfo.ExtendedInfo.Descriptions) { if (desc.IsFinished) { SuperUtilities.SaveResultsInFolder(desc.OptimalCirculants, Path.Combine(folderName, "finish")); } else { SuperUtilities.SaveLastState(desc.LastState, Path.Combine(folderName, "not-finish", $"laststate-{desc.LastState.CurrentNodesCount}.xml")); SuperUtilities.SaveResultsInFolder(desc.OptimalCirculants, Path.Combine(folderName, "not-finish")); } } File.AppendAllText(localPath, basicInfo.ToCsvString(file.Item2), new UTF8Encoding(true)); } } } Console.WriteLine("Application end. Press any button for exit"); Console.ReadKey(false); }