/// <summary> /// Get a list of node ids that satisfy the route type part from the given initial id. /// </summary> /// <param name="dissDatabaseContext">Db context</param> /// <param name="code">Initial node id</param> /// <param name="routeTypePortion">Route type code.</param> /// <returns>A list of unique node ids.</returns> public static async Task <List <string> > GetMatchingIds(DissDatabaseContext dissDatabaseContext, string code, string routeTypePortion) { List <string> output = new List <string>(); switch (routeTypePortion) { case "r": // Room. output.Add(code); return(output); case "b": // Building. // Get entrances. return(await dissDatabaseContext .NodeEdges .AsNoTracking() .Include(e => e.Node1) .Include(e => e.Node2) .Where(edge => edge.Node1.BuildingCode == code && edge.Node1.Type == NodeType.Corridor && edge.Node2.BuildingCode == "out" && edge.Node2.Type == NodeType.Corridor) .Select(e => e.Node1Id).ToListAsync()); } return(output); }
/// <summary> /// Generate all student routes from the timetable data. /// </summary> /// <param name="dissDatabaseContext">Database context.</param> /// <param name="pathfinder">Pathfinder to use.</param> /// <param name="memoryCache">The memory cache to use.</param> /// <param name="accommodations">The list of student accommodations that can be used as home destinations.</param> /// <exception cref="AggregateException"></exception> /// <exception cref="Exception"></exception> public static async Task <StudentRoute[]> GenerateAllStudentRoutes(DissDatabaseContext dissDatabaseContext, Pathfinder pathfinder, IMemoryCache memoryCache, string[] accommodations) { DateTime today = new DateTime(2020, 3, 2); string cacheKey = $"{today.ToString("yyyy.MM.dd")}.studentRoutes"; // Get the routes from the cache if they exist there. if (memoryCache.TryGetValue(cacheKey, out StudentRoute[] studentRoutes))
/// <summary> /// Constructor for a pathfinder. /// </summary> /// <param name="dissDatabaseContext">Db context.</param> /// <exception cref="InvalidCastException"></exception> public Pathfinder(DissDatabaseContext dissDatabaseContext) { // Get all nodes from the database. AllNodes = dissDatabaseContext .Nodes .AsNoTracking() .Include(n => n.OutgoingEdges) .ThenInclude(e => e.Node2) .Include(n => n.IncomingEdges) .ThenInclude(e => e.Node1) .ToDictionary(n => n.NodeId); }
/// <summary> /// Constructor for the routing controller. /// </summary> /// <param name="dissDatabaseContext">Injected database context.</param> /// <param name="memoryCache">Injected memory cache.</param> /// <param name="appSettingsService">Injected app settings.</param> /// <exception cref="InvalidCastException"></exception> public RoutingController(DissDatabaseContext dissDatabaseContext, IMemoryCache memoryCache, AppSettingsService appSettingsService) { DissDatabaseContext = dissDatabaseContext; MemoryCache = memoryCache; AppSettings = appSettingsService; // Does a pathfinder exist in the cache already built? if (!MemoryCache.TryGetValue("pathfinder", out Pathfinder)) { // No, build a new pathfinder and cache it for an hour. Pathfinder = new Pathfinder(DissDatabaseContext); MemoryCache.Set("pathfinder", Pathfinder, new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove).SetAbsoluteExpiration(TimeSpan.FromHours(1))); } }
public HomeController(DissDatabaseContext dissDatabaseContext) { DissDatabaseContext = dissDatabaseContext; }
/// <summary> /// Find all the lifts in the same lift shaft given any lift /// </summary> /// <param name="liftId">ID of lift to start at</param> /// <param name="dbContext">Database context</param> /// <returns>A list of lift nodes in this shaft</returns> /// <exception cref="InvalidOperationException"></exception> public static async Task <List <Node> > GetAllLiftNodesOnThisBranch(string liftId, DissDatabaseContext dbContext) { List <Node> outputLifts = new List <Node>(); Node currentLift = await dbContext.Nodes.AsNoTracking().Include(l => l.IncomingEdges).ThenInclude(l => l.Node2).FirstOrDefaultAsync(node => node.NodeId == liftId); if (currentLift == default(Node)) { return(outputLifts); } outputLifts.Add(currentLift); Queue <Node> liftsToCheck = new Queue <Node>(); bool allLiftsFound = false; while (!allLiftsFound) { // Get all lifts connected to the current one Node[] liftResults = currentLift.IncomingEdges.Where(edge => edge.Node1Id == currentLift.NodeId && edge.Node2Id.StartsWith("l_", StringComparison.OrdinalIgnoreCase)).Select(e => e.Node2).ToArray(); foreach (Node result in liftResults) { // Have we already seen this one? if (!outputLifts.Any(x => x.NodeId == result.NodeId)) { // No, add to check queue liftsToCheck.Enqueue(result); outputLifts.Add(result); } } if (liftsToCheck.Count > 0) { currentLift = await dbContext.Nodes.AsNoTracking().Include(l => l.IncomingEdges).ThenInclude(l => l.Node2).FirstOrDefaultAsync(node => node.NodeId == liftsToCheck.Dequeue().NodeId); if (currentLift == default(Node)) { return(outputLifts); } } else { allLiftsFound = true; } } return(outputLifts); }
/// <summary> /// Constructor for the admin controller with dependency injection parameters. /// </summary> /// <param name="appSettings">Injected settings.</param> /// <param name="dbContext">Injected database context.</param> /// <param name="hostingEnvironment">Injected hosting environment details.</param> public AdminController(AppSettingsService appSettings, DissDatabaseContext dbContext, IWebHostEnvironment hostingEnvironment) { AppSettings = appSettings; DissDatabaseContext = dbContext; WebHostEnvironment = hostingEnvironment; }
/// <summary> /// Constructor for the campus data controller, using dependency injection. /// </summary> /// <param name="dbContext">Injected database context.</param> /// <param name="hostingEnvironment">Injected hosting environment details.</param> public CampusDataController(DissDatabaseContext dbContext, IWebHostEnvironment hostingEnvironment) { DissDatabaseContext = dbContext; HostingEnvironment = hostingEnvironment; }