public MainForm() { InitializeComponent(); canNetwork.Sorter = new NetMLSorter(); NetworkParameters = new SimulationParameters { Name = "unnamed", ComponentLogs = new List <ComponentLog>(), ObservationStartTime = 0.1f, ObservationStopTime = 10.0f, PrintAttributes = false, Traces = new List <Trace>() }; SetTitle(); ContextMenu = new ContextMenu(); DisplayProperties.Reset(); if (Properties.Settings.Default.NS3Dir == "<unset>") { var folderPicker = new FolderPicker("Select NS3 root", "Select the root for NS3, this is the folder that contains waf, using the Windows path.", $"C:\\cygwin64\\home\\{Environment.UserName}\\ns-allinone-3.22\\ns-3.22"); if (folderPicker.ShowDialog() == DialogResult.OK) { Properties.Settings.Default.NS3Dir = folderPicker.ChosenFolder; } else { MessageBox.Show("You know it won't work if you don't tell the program where NS3 is."); } } if (Properties.Settings.Default.CygwinDir == "<unset>") { var folder = Apex.Prompt.Prompt.ShowStringDialog("Select the root for NS3, this is the folder that contains waf, using the Cygwin path.", "Select NS3 root", $"/home/{Environment.UserName}/ns-allinone-3.22/ns-3.22"); if (folder == null) { MessageBox.Show("You know it won't work if you don't tell the program where NS3 is."); } else { Properties.Settings.Default.CygwinDir = folder; } } if (Properties.Settings.Default.BashPath == "<unset>") { var filePicker = new FilePicker("Select bash executable", "Select the bash executable, using the Windows path.", "C:\\cygwin64\\bin\\bash.exe", "Executable files (*.exe)|*.exe"); if (filePicker.ShowDialog() == DialogResult.OK) { Properties.Settings.Default.BashPath = filePicker.ChosenFile; } else { MessageBox.Show("You know it won't work if you don't tell the program where bash is."); } } Properties.Settings.Default.Save(); }
private void Load(string Path) { if (File.Exists(Path)) { canNetwork.Items.Clear(); NetworkParameters = Newtonsoft.Json.JsonConvert.DeserializeObject <SimulationParameters>(File.ReadAllText(Path)); var networkDir = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Path), System.IO.Path.GetFileNameWithoutExtension(Path)); try { var nodes = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Node> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "nodes.json"))); canNetwork.AddItems(nodes); NodeStore.Nodes = nodes; try { var links = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Link> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "links.json"))); canNetwork.AddItems(links); } catch (Exception) { MessageBox.Show("Links are corrupt."); } try { var streams = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Stream> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "streams.json"))); canNetwork.AddItems(streams); } catch (Exception) { MessageBox.Show("Streams are corrupt."); } try { var domains = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Domain> >(File.ReadAllText(System.IO.Path.Combine(networkDir, "domains.json"))); canNetwork.AddItems(domains); } catch (Exception) { MessageBox.Show("Domains are corrupt."); } } catch (Exception) { MessageBox.Show("Nodes are corrupt."); } try { DisplayProperties.Reset(); var displayProperties = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Tuple <Type, object> > >(File.ReadAllText(System.IO.Path.Combine(networkDir, "display.json"))); foreach (var property in displayProperties) { if (property.Value.Item1.IsEnum) { dynamic value = Enum.ToObject(property.Value.Item1, property.Value.Item2); var field = typeof(DisplayProperties).GetField(property.Key); field.SetValue(null, value); } else { var field = typeof(DisplayProperties).GetField(property.Key); field.SetValue(null, property.Value.Item2); } } } catch (Exception) { MessageBox.Show("Display properties are corrupt."); } // JSON can't store circular reference to parent or reference to actual Node / Link / Stream / Domain object. foreach (var trace in NetworkParameters.Traces) { foreach (var attribute in trace.Attributes) { attribute.Parent = trace; if (attribute.Element is Node) { attribute.Element = NodeStore.Nodes.First((x) => x.Name == (attribute.Element as Node).Name); } else if (attribute.Element is Link) { attribute.Element = Links.First((x) => x.Name == (attribute.Element as Link).Name); } else if (attribute.Element is Stream) { attribute.Element = Streams.First((x) => x.Name == (attribute.Element as Stream).Name); } else if (attribute.Element is Domain) { attribute.Element = Domains.First((x) => x.Name == (attribute.Element as Domain).Name); } } } // Fix up the links in plot attributes. foreach (var plot in NetworkParameters.Plots) { foreach (var attribute in plot.Attributes) { attribute.TraceParameter = NetworkParameters.Traces.First((x) => x.Name == attribute.TraceParameter.Name); } } canNetwork.Invalidate(); NodeStore.Nodes = null; SetTitle(); } else { MessageBox.Show($"Cannot find file \"{Path}\""); } }