public SelectGame_Screen() { InitializeComponent(); CycleCollection<Uri> collection = new CycleCollection<Uri>(); var maps = Directory.EnumerateFiles(Directory.GetCurrentDirectory() + @"\Maps", "*.*", SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")); foreach(string map in maps) collection.Add(new Uri(map, UriKind.Relative)); CarouselMenu.ItemsSources = collection; }
public void Load(string[] bindings) { m_pDefaultBindings = new CycleCollection <string>(); foreach (var remoteRule in m_pRemoteRules) { remoteRule.LocalBindings.Clear(); } foreach (string binding in bindings) { var items = binding.Split(":", true, true, "[]"); string addr = items[0].TrimStart('[').TrimEnd(']'); string port = items[1]; var ip = IPAddress.Parse(addr); if (ip.AddressFamily != AddressFamily.InterNetwork) { continue; } foreach (var localRule in m_pLocalRules) { if (!localRule.LocalRule.Contains(ip)) { continue; } if (localRule.IsDefaultRule) { m_pDefaultBindings.Add(binding); } foreach (var remoteRule in localRule.RemoteRules) { remoteRule.LocalBindings.Add(binding); } } } }
private void GetGreenYellowRedCycle(DateTime start_time, DateTime end_time, List <SignalPhaseEventsUDOT> cycleEvents, List <DetectorEventsUDOT> detectorEvents, List <SignalPhaseEventsUDOT> preemptEvents) { Cycle pcd; pcd = null /* TODO Change to default(_) if this is not a reference type */; // use a counter to help determine when we are on the last row int counter = 0; foreach (SignalPhaseEventsUDOT row in cycleEvents) { // use a counter to help determine when we are on the last row counter += 1; if ((row.TimeStamp >= start_time & row.TimeStamp <= end_time)) { // if this is the first PCD group we need to handle a special case // where the PCD starts at the start of the requested period to // make sure we include all data if (pcd != null) { // make the first group start on the exact start of the requested period pcd = new Cycle(start_time); // add a green event if the first event is yellow if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToYellow) { pcd.NextEvent(Cycle.EventType.ChangeToGreen, start_time.AddMilliseconds(1)); } else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToRed) { pcd.NextEvent(Cycle.EventType.ChangeToGreen, start_time.AddMilliseconds(1)); pcd.NextEvent(Cycle.EventType.ChangeToYellow, start_time.AddMilliseconds(2)); } } // check to see if the event is a change to red // the 64 event is for overlaps if (row.EventCode == 10 | row.EventCode == 64) { // if it is red and the pcd group is empty create a new one if (pcd != null) { pcd = new Cycle(row.TimeStamp); } else { pcd.NextEvent(GetEventType(row.EventCode), row.TimeStamp); // if the next event response is complete add it and start the next group if (pcd.Status == Cycle.NextEventResponse.GroupComplete) { CycleCollection.Add(pcd); pcd = new Cycle(row.TimeStamp); } } } else if (pcd != null) { // if the event is not red and the group is not empty // add the event and set the next event pcd.NextEvent(GetEventType(row.EventCode), row.TimeStamp); if (pcd.Status == Cycle.NextEventResponse.GroupComplete) { CycleCollection.Add(pcd); pcd = new Cycle(row.TimeStamp); } } if (pcd != null & pcd.Status == Cycle.NextEventResponse.GroupMissingData) { pcd = null /* TODO Change to default(_) if this is not a reference type */; } } else if (counter == cycleEvents.Count & pcd != null) { // if the last event is red create a new group to consume the remaining time in the period if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToRed) { pcd.NextEvent(Cycle.EventType.ChangeToGreen, end_time.AddMilliseconds(-2)); pcd.NextEvent(Cycle.EventType.ChangeToYellow, end_time.AddMilliseconds(-1)); pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToGreen) { pcd.NextEvent(Cycle.EventType.ChangeToYellow, end_time.AddMilliseconds(-1)); pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } else if (GetEventType(row.EventCode) == Cycle.EventType.ChangeToYellow) { pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } if (pcd.Status != Cycle.NextEventResponse.GroupMissingData) { CycleCollection.Add(pcd); } } } // if there are no records at all for the selected time, then the line and counts don't show. // this next bit fixes that if ((CycleCollection.Count == 0 & start_time != end_time)) { // then we need to make a dummy PCD group // then PCD assumes it starts on red pcd = new Cycle(start_time); // and find out what phase state the controller was in by looking for the next phase event // after the end of the plan List <SignalPhaseEventsUDOT> eventTable = new List <SignalPhaseEventsUDOT>(); SignalPhaseEventsUDOT eventBeforePattern = new SignalPhaseEventsUDOT(); eventBeforePattern = null /* TODO Change to default(_) if this is not a reference type */; IEnumerable <ControllerEvent> TempEvents; DateTime yesterday; yesterday = start_time.AddDays(-1); TempEvents = Globals.UDOTEventLog.Where(a => a.SignalID == SignalID & a.TimeStamp >= yesterday & a.TimeStamp <= start_time & a.EventParam == PhaseNumber & (a.EventCode == 1 | a.EventCode == 8 | a.EventCode == 10)).OrderByDescending(a => a.TimeStamp); foreach (ControllerEvent x in TempEvents) { SignalPhaseEventsUDOT tempRow = new SignalPhaseEventsUDOT(); tempRow.EventCode = (byte)x.EventCode; tempRow.EventParam = (byte)x.EventParam; tempRow.TimeStamp = x.TimeStamp; eventTable.Add(tempRow); } eventTable.OrderByDescending(a => a.TimeStamp); eventBeforePattern = eventTable.FirstOrDefault(); if (eventBeforePattern != null) { if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToRed) { // let it dwell in red (we don't have to do anything) // then add a green phase, a yellow phase and a red phase at the end to complete the cycle pcd.NextEvent(Cycle.EventType.ChangeToGreen, end_time.AddMilliseconds(-2)); pcd.NextEvent(Cycle.EventType.ChangeToYellow, end_time.AddMilliseconds(-1)); pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } else if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToYellow) { // we were in yellow, though this will probably never happen // we have to add a green to our dummy phase pcd.NextEvent(Cycle.EventType.ChangeToGreen, start_time.AddMilliseconds(1)); // then make it dwell in yellow pcd.NextEvent(Cycle.EventType.ChangeToYellow, start_time.AddMilliseconds(2)); // then add a red phase at the end to complete the cycle pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } else if (GetEventType(eventBeforePattern.EventCode) == Cycle.EventType.ChangeToGreen) { // make it dwell in green pcd.NextEvent(Cycle.EventType.ChangeToGreen, start_time.AddMilliseconds(1)); // then add a yellow phase and a red phase at the end to complete the cycle pcd.NextEvent(Cycle.EventType.ChangeToYellow, end_time.AddMilliseconds(-1)); pcd.NextEvent(Cycle.EventType.ChangeToRed, end_time); } } if (pcd.Status == Cycle.NextEventResponse.GroupComplete) { // If pcd.EndTime = DateTime.MinValue Then pcd.EndTime = Me.EndTime CycleCollection.Add(pcd); } } AddDetectorData(detectorEvents); AddPreemptData(preemptEvents); }
private void StartListen() { try { // Dispose all old receivers. foreach (var receiver in m_pDataReceivers.ToArray()) { try { receiver.Dispose(); } catch (Exception ex) { OnError(ex); } } m_pDataReceivers.Clear(); // Dispose all old sockets. foreach (var socket in m_pSockets.ToArray()) { try { socket.Dispose(); } catch (Exception ex) { OnError(ex); } } m_pSockets.Clear(); m_pSocketsIPv4.Clear(); m_pSocketsIPv6.Clear(); m_pBindSockets.Clear(); // We must replace IPAddress.Any to all available IPs, otherwise it's impossible to send // reply back to UDP packet sender on same local EP where packet received. // This is very important when clients are behind NAT. var listeningEPs = new List <IPEndPoint>(); foreach (var ep in m_pBindings) { if (ep.Address.Equals(IPAddress.Any)) { // Add localhost. var localEP = new IPEndPoint(IPAddress.Loopback, ep.Port); if (!listeningEPs.Contains(localEP)) { listeningEPs.Add(localEP); } foreach (var ip in NetworkUtil.GetIPAddresses()) { if (ip.AddressFamily == AddressFamily.InterNetwork) { localEP = new IPEndPoint(ip, ep.Port); if (!listeningEPs.Contains(localEP)) { listeningEPs.Add(localEP); } } } } else if (ep.Address.Equals(IPAddress.IPv6Any)) { foreach (var ip in NetworkUtil.GetIPAddresses()) { if (ip.AddressFamily == AddressFamily.InterNetworkV6) { IPEndPoint localEP = new IPEndPoint(ip, ep.Port); if (!listeningEPs.Contains(localEP)) { listeningEPs.Add(localEP); } } } } else { if (!listeningEPs.Contains(ep)) { listeningEPs.Add(ep); } } } // Create sockets. m_pSockets = new List <Socket>(); m_pBindSockets = new Dictionary <string, Socket>(); foreach (var ep in listeningEPs) { try { var socket = NetworkUtil.CreateSocket(ep, ProtocolType.Udp); m_pSockets.Add(socket); if (!ep.Address.Equals(IPAddress.Loopback)) { m_pBindSockets[ep.ToString()] = socket; } // Create UDP data receivers. for (int i = 0; i < m_ReceiversPerSocket; i++) { var receiver = new UDP_DataReceiver(socket, m_MTU); receiver.PacketReceived += (sender, e) => { try { ProcessUdpPacket(e); } catch (Exception ex) { OnError(ex); } }; receiver.Error += (sender, e) => { OnError(e.Exception); }; m_pDataReceivers.Add(receiver); receiver.Start(); } } catch (Exception ex) { OnError(ex); } } // Create round-robin send sockets. // NOTE: We must skip localhost, it can't be used for sending out of server. m_pSocketsIPv4 = new CycleCollection <Socket>(); m_pSocketsIPv6 = new CycleCollection <Socket>(); foreach (Socket socket in m_pSockets) { if (((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetwork) { if (!((IPEndPoint)socket.LocalEndPoint).Address.Equals(IPAddress.Loopback)) { m_pSocketsIPv4.Add(socket); } } else if (((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetworkV6) { m_pSocketsIPv6.Add(socket); } } if (m_pBindSelector != null) { m_pBindSelector.Load(m_pBindSockets.Keys.ToArray()); } } catch (Exception ex) { OnError(ex); } }