Example #1
0
        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));
        }
Example #2
0
        public ICollection <Node> GetGraph()
        {
            Activator.Initialise();

            IGraphStorageService storage = ServiceLocator.Current.GetInstance <IGraphStorageService>();

            return(storage.RetrieveGraph());
        }
Example #3
0
        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();
        }