public WirelessNetworkSimulation(WirelessNetwork baseNetwork, int?seed = null) { RandomSeed = seed == null?SeedingRandom.Next() : seed.Value; r = new Random(RandomSeed); Network = baseNetwork; foreach (var n in Network.Nodes) { Type t = Assembly.GetExecutingAssembly().GetType(n.NodeType); SimulatedNode simNode = (SimulatedNode)t.GetConstructor(new Type[] { }).Invoke(new object[] { }); simNode.ParentSimulation = this; simNode.SourceNode = n; simNode.MyID = SimulationNodes.Count; WirelessSimulationNode sn = new WirelessSimulationNode() { NetworkNode = n, Node = simNode }; SimulationNodes.Add(sn); } }
private static WirelessNetwork LoadNetwork(string filename) { FileStream fs = File.OpenRead(filename); XmlSerializer xs = new XmlSerializer(typeof(WirelessNetwork)); WirelessNetwork wn = (WirelessNetwork)xs.Deserialize(fs); fs.Close(); return(wn); }
public void SetNetwork(WirelessNetwork wn) { Network = wn; Images.Clear(); foreach (var img in Network.Images) { RealizedNetworkImage ri = new RealizedNetworkImage(); ri.SourceImage = img; ri.FullFilename = img.Filename; ri.Bitmap = new BitmapImage(new Uri(ri.FullFilename)); Images.Add(ri); } InvalidateVisual(); }
private WirelessUnitTestInstance(WirelessNetwork net, int?seed = null) { if (seed == null) { RandomSeed = seedingRandom.Next(); } else { RandomSeed = seed.Value; } r = new Random(RandomSeed); Network = net; Simulation = new WirelessNetworkSimulation(Network, r.Next()); Simulation.StartSimulation(); }
public static WirelessUnitTestInstance RunUnitTest(WirelessNetwork net, WirelessUnitTest test) { WirelessUnitTestInstance instance = new WirelessUnitTestInstance(net); instance.TestPassed = false; try { UnitTestDelegate d = (UnitTestDelegate)Delegate.CreateDelegate(typeof(UnitTestDelegate), test.UnitTestMethod); d(instance); instance.TestPassed = true; } catch (Exception ex) { instance.TestException = ex; } return(instance); }
void TryAutoload() { // Try to load the autoload file. If it fails, just silently give up string autoload = Properties.Settings.Default.AutoloadFile; if (!string.IsNullOrEmpty(autoload)) { try { WirelessNetwork wn = LoadNetwork(autoload); StopSimulation(); SetupWirelessNetwork(wn); } catch { } } }
private void mnuLoad_Click(object sender, RoutedEventArgs e) { string filename = FileDialog.GetOpenFilename("Load Project...", "ws", "Wireless Simulator File"); if (filename != null) { // Try to load it try { WirelessNetwork wn = LoadNetwork(filename); StopSimulation(); SetupWirelessNetwork(wn); SetAutoload(filename); } catch (Exception ex) { MessageBox.Show("Exception while trying to Load file.\n" + ex.ToString()); } } }
void SetupWirelessNetwork(WirelessNetwork wn) { Network = wn; boxRange.Text = Network.BaseTransmitRange.ToString(); NetworkControl.SetNetwork(wn); }