private void SetNonLaneDetectors() { List <Models.DirectionType> directions = db.DirectionTypes.ToList(); var detectionstypeslist = db.DetectionTypes.ToList(); foreach (MOE.Common.Data.Signals.Graph_DetectorsRow row in DetectorsTable) { if (row.Det_Channel > 0) { var detector = CreateNewDetector(row, detectionstypeslist); var signal = SignalsList.Where(s => s.SignalID == row.SignalID).FirstOrDefault(); if (signal != null) { var approach = signal.Approaches .Where(a => a.DirectionType.Description == row.Direction && a.ProtectedPhaseNumber == Convert.ToInt32(row.Phase)) .FirstOrDefault(); if (approach == null) { approach = CreateNewApproach(row, directions); signal.Approaches.Add(approach); } if (approach.Detectors == null) { approach.Detectors = new List <Models.Detector>(); } approach.Detectors.Add(detector); } } } }
private void SetApproaches() { Console.WriteLine("Setting up New Approaches"); List <Models.DirectionType> directions = (from r in db.DirectionTypes select r).ToList(); foreach (MOE.Common.Data.Signals.Graph_DetectorsRow row in DetectorsTable) { var signal = SignalsList.Where(s => s.SignalID == row.SignalID).First(); if (signal.Approaches == null) { signal.Approaches = new List <MOE.Common.Models.Approach>(); } Models.Approach approach; if (row.Phase == "0") { approach = signal.Approaches .Where(s => s.DirectionType.Description == row.Direction) .FirstOrDefault(); } else { approach = signal.Approaches .Where(s => s.DirectionType.Description == row.Direction && s.ProtectedPhaseNumber == Convert.ToInt32(row.Phase)) .FirstOrDefault(); } if (approach == null) { signal.Approaches.Add(CreateNewApproach(row, directions)); } else if (approach.ProtectedPhaseNumber == 0 && row.Phase != "0") { approach.ProtectedPhaseNumber = Convert.ToInt32(row.Phase); approach.Description = approach.DirectionType.Description + " Phase " + approach.ProtectedPhaseNumber.ToString(); } else if (approach.ProtectedPhaseNumber != 0 && row.Phase != "0" && approach.ProtectedPhaseNumber != Convert.ToInt32(row.Phase)) { signal.Approaches.Add(CreateNewApproach(row, directions)); } foreach (Models.DirectionType direction in directions) { int maxMPH = (from r in signal.Approaches where r.DirectionTypeID == direction.DirectionTypeID select r.MPH).Max() ?? 0; foreach (Models.Approach a in signal.Approaches) { if (a.DirectionTypeID == direction.DirectionTypeID) { a.MPH = maxMPH; } } } } }