public ICollection <int> GetShortestPath(string idFromValue, string idToValue) { Activator.Initialise(); int idFrom, idTo; if (!int.TryParse(idFromValue, out idFrom) || !int.TryParse(idToValue, out idTo)) { return(new List <int>()); } IGraphStorageService storage = ServiceLocator.Current.GetInstance <IGraphStorageService>(); IGraphBuilder builder = ServiceLocator.Current.GetInstance <IGraphBuilder>(); IShortestPathStrategy pathStrategy = ServiceLocator.Current.GetInstance <IShortestPathStrategy>(); Domain.IGraph graph = builder.BuildGraph(storage.RetrieveGraph()); IGraphNode fromNode = graph.GetNode(idFrom); IGraphNode toNode = graph.GetNode(idTo); if (fromNode == null || toNode == null) { return(new List <int>()); } return(pathStrategy.FindShortestPath(graph, fromNode, toNode)); }
public ICollection <Node> GetGraph() { Activator.Initialise(); IGraphStorageService storage = ServiceLocator.Current.GetInstance <IGraphStorageService>(); return(storage.RetrieveGraph()); }
private static void ProcessGraph(IArgumentsParser parser, TextWriter writer) { IGraphLoader loader = ServiceLocator.Current.GetInstance <IGraphLoader>(); IList <Node> graph = loader.LoadGraph(parser.Path, writer); IGraphStorageService storage = ServiceLocator.Current.GetInstance <IGraphStorageService>(); if (parser.UseRecreationMode) { storage.DeleteGraph(); writer.WriteLine("Old graph has been deleted."); } storage.SaveGraph(graph); writer.WriteLine("Graph data has been saved."); writer.Flush(); }