// constructors public Demographic(DemoType myType, int NumPeopleIn = 0) { MyDemoType = myType; NumPeople = NumPeopleIn; MyBaseTargetPop = (BaseTargetPop)Enum.Parse(typeof(BaseTargetPop), MyDemoType.ToString("g")); goodConsumeWeights = new Dictionary <GoodType, float>(); foreach (KeyValuePair <GoodType, float[]> goodPair in PeopleConsumptionWeights) { goodConsumeWeights.Add(goodPair.Key, goodPair.Value[(int)MyDemoType]); } goodProduceWeights = new Dictionary <GoodType, float>(); foreach (KeyValuePair <GoodType, float[]> goodPair in PeopleProductionWeights) { goodProduceWeights.Add(goodPair.Key, goodPair.Value[(int)MyDemoType]); } lastTickConsumed = new Dictionary <GoodType, float>(); lastTickProduced = new Dictionary <GoodType, float>(); Happiness = 100; Satisfaction = 100; Health = 100; Security = 100; Oppression = 0; TargetPop = 100; }
/// <summary> /// Builds a top level node in the tree for a DemoType. /// </summary> /// <param name="type">The type of demo.</param> private void buildPrimaryNode(DemoType type) { TreeNode currNode = new TreeNode(type.ToString()); typeToNodeTable[type] = currNode; this.demoTree.Nodes.Add(currNode); }
public void ToString_IsOverriden() { var demoValue = new DemoType() { Id = 1, Text = "Some text", Password = "******", Time = DateTime.Now.Date.Add(TimeSpan.Parse("12:34:56")) }; Assert.Equal("Id: 1, Text: \"Some text\", Time: \"12:34\"", demoValue.ToString()); }
public static void Main(string[] args) { OscServer oscServer; DemoType demoType = GetDemoType(); //IPAddress ipAddress = IPAddress.Loopback; //IPAddress ipAddress = IPAddress.Parse("192.168.1.118"); IPAddress ipAddress = IPAddress.Parse(Properties.Settings.Default.IPAddress); switch (demoType) { case DemoType.Udp: oscServer = new OscServer(TransportType.Udp, ipAddress, Properties.Settings.Default.Port); break; case DemoType.Tcp: oscServer = new OscServer(TransportType.Tcp, ipAddress, Properties.Settings.Default.Port); break; case DemoType.Multicast: oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Properties.Settings.Default.Port); break; default: throw new Exception("Unsupported receiver type."); } oscServer.FilterRegisteredMethods = false; oscServer.RegisterMethod(AliveMethod); oscServer.RegisterMethod(TestMethod); oscServer.RegisterMethod(PingMethod); // used by TouchOSC oscServer.BundleReceived += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived); oscServer.MessageReceived += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived); oscServer.ReceiveErrored += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored); oscServer.ConsumeParsingExceptions = false; oscServer.Start(); Console.WriteLine("Osc Receiver: " + demoType.ToString()); Console.WriteLine("with IP Address={0} on Port={1}", ipAddress, Properties.Settings.Default.Port); Console.WriteLine("Press any key to exit."); Console.ReadKey(); oscServer.Stop(); }
public static void Main(string[] args) { OscServer oscServer; DemoType demoType = GetDemoType(); switch (demoType) { case DemoType.Udp: oscServer = new OscServer(TransportType.Udp, IPAddress.Loopback, Port); break; case DemoType.Tcp: oscServer = new OscServer(TransportType.Tcp, IPAddress.Loopback, Port); break; case DemoType.Multicast: oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Port); break; default: throw new Exception("Unsupported receiver type."); } oscServer.FilterRegisteredMethods = false; oscServer.RegisterMethod(AliveMethod); oscServer.RegisterMethod(TestMethod); oscServer.BundleReceived += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived); oscServer.MessageReceived += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived); oscServer.ReceiveErrored += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored); oscServer.ConsumeParsingExceptions = false; oscServer.Start(); Console.WriteLine("Osc Receiver: " + demoType.ToString()); Console.WriteLine("Press any key to exit."); Console.ReadKey(); oscServer.Stop(); }
public static void Main(string[] args) { OscServer oscServer; DemoType demoType = /*GetDemoType();*/ DemoType.Udp; switch (demoType) { case DemoType.Udp: oscServer = new OscServer(TransportType.Udp, IPAddress.Any, Port); break; case DemoType.Tcp: oscServer = new OscServer(TransportType.Tcp, IPAddress.Loopback, Port); break; case DemoType.Multicast: oscServer = new OscServer(IPAddress.Parse("224.25.26.27"), Port); break; default: throw new Exception("Unsupported receiver type."); } oscServer.FilterRegisteredMethods = false; oscServer.RegisterMethod(AliveMethod); oscServer.RegisterMethod(TestMethod); oscServer.RegisterMethod(MouseMethod); oscServer.BundleReceived += new EventHandler <OscBundleReceivedEventArgs>(oscServer_BundleReceived); oscServer.MessageReceived += new EventHandler <OscMessageReceivedEventArgs>(oscServer_MessageReceived); oscServer.ReceiveErrored += new EventHandler <ExceptionEventArgs>(oscServer_ReceiveErrored); oscServer.ConsumeParsingExceptions = false; handsets = new VirtualHandset[HANDSET_COUNT]; motorMin = new int[HANDSET_COUNT]; motorMax = new int[HANDSET_COUNT]; String[] comPorts = { "COM9", "COM4", "COM5", "COM6", "COM7", "COM8" }; for (int i = 0; i < HANDSET_COUNT; i++) { VirtualHandset handset = new VirtualHandset(); int result = handset.Connect(comPorts[i]); if (result != 0) { // -20 = virtual com port device not found (USB unplugged) // -30 = com port found but couldn't connect to hardware Console.WriteLine("error " + result + " opening " + comPorts[i]); continue; } VirtualHandset.ControlUnitSettings settings = new VirtualHandset.ControlUnitSettings(); result = handset.GetAllSettings(ref settings); if (result == 0) { Console.Write(comPorts[i] + ": OEM Information: " + (char)settings.OEMInformation[0] + " " + (char)settings.OEMInformation[1] + " " + (char)settings.OEMInformation[2] + " " + (char)settings.OEMInformation[3] + " (" + (settings.OEMInformation.Length - 4) + " more) "); } else { Console.WriteLine("error " + result + " getting control unit settings for " + comPorts[i]); continue; } int handsetIndex = 0; if ((char)settings.OEMInformation[0] == 'L') { handsetIndex = 0; } else if ((char)settings.OEMInformation[0] == 'R') { handsetIndex = 3; } else { Console.WriteLine(comPorts[i] + ": invalid OEMInformation[0] '" + (char)settings.OEMInformation[0] + "' (should be 'L' or 'R')"); continue; } if ((char)settings.OEMInformation[1] == '1') { handsetIndex += 0; } else if ((char)settings.OEMInformation[1] == '2') { handsetIndex += 1; } else if ((char)settings.OEMInformation[1] == '3') { handsetIndex += 2; } else { Console.WriteLine(comPorts[i] + ": invalid OEMInformation[1] '" + (char)settings.OEMInformation[1] + "' (should be '1', '2' or '3')"); continue; } handsets[handsetIndex] = handset; motorMin[handsetIndex] = settings.LowerLimit[0] + 1; // don't drive right to the very limit motorMax[handsetIndex] = settings.UpperLimit[0] - 1; // don't drive right to the very limit Console.WriteLine(" lower " + motorMin[handsetIndex] + " upper " + motorMax[handsetIndex]); Console.WriteLine(" -> assigning handset to index " + handsetIndex); // add event-handler for synchronizing the PC after driving //handsets[handsetIndex].OnSynchronizeAfterDriving += new VirtualHandset.OnSynchronizeAfterDrivingDelegate(onSynchronizeAfterDriving); } for (int i = 0; i < HANDSET_COUNT; i++) { if (handsets[i] == null) { Console.WriteLine("handset " + i + " missing, filling in with dummy"); handsets[i] = new VirtualHandset(); } // moveMotorToPosition(i, INITIAL_POS); } oscServer.Start(); // figure out my ip address IPHostEntry host; string localIP = "?"; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily.ToString() == "InterNetwork") { localIP = ip.ToString(); } } Console.WriteLine("Osc Receiver: " + demoType.ToString() + " listening on address " + localIP + " port " + Port); Console.WriteLine("Press any key to exit."); Console.ReadKey(); oscServer.Stop(); for (int i = 0; i < HANDSET_COUNT; i++) { if (handsets[i] == null) { continue; } handsets[i].Disconnect(); handsets[i].Dispose(); } }