public void Stop()
        {
            ForcedStop = true;

            lock (ForcedLock)
            {
                SuperUtilities.SaveLastState(LastState, ConfigurationManager.AppSettings["LastStatePath"]);
            }
        }
Exemplo n.º 2
0
        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);
        }