private static void Main(string[] args) { Routes = new List<Route>(); Waypoints=new List<Waypoint>(); string path = @"C:\files\avto\"; var carType = CarType.Bus; var directory = new DirectoryInfo(Path.GetDirectoryName(path)); DirectoryInfo[] routeNames = directory.GetDirectories(); foreach (DirectoryInfo routeName in routeNames.Take(10)) // список папок с маршрутами { string routeStringName = routeName.Name; DirectoryInfo[] dayMasks = routeName.GetDirectories(); foreach (DirectoryInfo dayMask in dayMasks) { WeekDays day = dayMask.Name == "0000011" ? WeekDays.Weekend : dayMask.Name == "1111100" ? WeekDays.Daily : dayMask.Name == "0000010" ? WeekDays.Sarturday : WeekDays.Sunday; DirectoryInfo[] directions = dayMask.GetDirectories(); foreach (DirectoryInfo direction in directions) { string directionName = direction.Name; Route currentRoute = Routes.FirstOrDefault( r => r.Name == routeStringName && r.Type == carType && r.DirectionName == directionName); if (currentRoute == null) { currentRoute = new Route(routeStringName, carType, directionName); Routes.Add(currentRoute); } FileInfo[] wayPoints = direction.GetFiles(); // поправить тут foreach (FileInfo wayPoint in wayPoints) { if (wayPoint.Name.Contains(".txt")) continue; Tuple<string, List<DateTime>> tuple = ParseWayPoint(wayPoint.FullName); var selectedWaypoint = Waypoints.FirstOrDefault(w => w.Name == tuple.Item1); if (selectedWaypoint == null) { selectedWaypoint=new Waypoint(tuple.Item1); } var time = new Time(day); time.DateTimes = tuple.Item2; time.Route = currentRoute; selectedWaypoint.Times.Add(time); if (selectedWaypoint.Routes.All(r => r.Name != currentRoute.Name)) { selectedWaypoint.Routes.Add(currentRoute); } if (currentRoute.IsFilled == false) { if (currentRoute.Waypoints.All((w => w.Name != selectedWaypoint.Name))) { currentRoute.Waypoints.Add(selectedWaypoint); } } } } } } }
private static void Recurse(List<Waypoint> totalWaypoints,List<Waypoint> waypointsInRoute, Waypoint start, Waypoint end) { var thisResurseList = new List<Waypoint>(); thisResurseList.AddRange(waypointsInRoute); if (start == end) { Founded(thisResurseList); } foreach (var route in start.Routes) { var thisRouteWaypoints = new List<Waypoint>(); thisRouteWaypoints.AddRange(thisResurseList); } }