// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var cmdArgs = Environment.GetCommandLineArgs(); if (cmdArgs.Length >= 2) { if (!int.TryParse(cmdArgs[1], out AutomatonProblemSize)) { throw new Exception("Incorrect automaton problem size"); } if (cmdArgs.Length >= 3) { if (!int.TryParse(cmdArgs[2], out maximumCount)) { throw new Exception("Incorrect maximal found automata."); } if (cmdArgs.Length >= 5) { readAddress = cmdArgs[4]; } } } services.AddMvc(); services.AddSignalR(opts => opts.EnableDetailedErrors = true).AddMessagePackProtocol(); Console.WriteLine($"Automata size: {AutomatonProblemSize}"); Console.WriteLine($"Maximum count of interesting automata: {maximumCount}."); Console.WriteLine("Please note that some automata including those violating Cerny Conjecture are collected without limits."); var database = new UnaryAutomataDB(AutomatonProblemSize, maximumCount); ProgressIO.ProgressIO.ImportStateIfPossible(database, readAddress); services.AddSingleton(database); }
public static void ImportStateIfPossible(UnaryAutomataDB database, string address) { if (address != null && address != string.Empty && File.Exists(address)) { try { var serializer = new XmlSerializer(typeof(DBSerialized)); using (var sr = new StreamReader(address)) { var obj = serializer.Deserialize(sr); var data = (DBSerialized)obj; if (database.Size == data.Size) { database.ImportShallow(data); } } } catch (Exception e) { Console.WriteLine("error importing database!"); Console.WriteLine(e.Message); } } else { Console.WriteLine("no computation history or corrupt"); } }
public async static Task ExportStateAsync(UnaryAutomataDB database) { var exported = database.ExportAsXMLString(); var serializer = new XmlSerializer(exported.GetType()); using (var sw = new StringWriter()) { using (var w = XmlWriter.Create(sw)) { serializer.Serialize(w, exported); var found = exported.finishedStatistics.Count(finished => finished.solved); var detailedAddress = GetDetailedAddress(exported.Size, exported.MaximumLongestAutomataCount, found); var swString = sw.ToString(); var toDelete = new List <int>(); try { lock (syncObject) { File.WriteAllTextAsync(detailedAddress, swString).Wait(); foreach (var address in stillAvailable) { if (File.Exists(address)) { File.Delete(address); } } stillAvailable.Clear(); if (found < database.Total) { stillAvailable.Add(detailedAddress); } } Console.WriteLine($"Successfully exported database having computed {database.Found} unary automata at {DateTime.Now} to a file {detailedAddress}. Deleted the rest"); } catch (Exception e) { Console.WriteLine(e); } } } }
public UnaryAutomataHub(UnaryAutomataDB database) => this.database = database;