/// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestPreprocessing(string name, string pbfFile)
        {
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream stream = testFile.OpenRead();
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(new PBFOsmStreamSource(stream));

            var performanceInfo = new PerformanceInfoConsumer("LivePreProcessor", 20000);
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            // var memoryGraph = new MemoryMappedGraph<LiveEdge>(1000000, @"c:\temp\");
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex);
            targetData.RegisterSource(progress);
            targetData.Pull();

            stream.Dispose();

            performanceInfo.Stop();
            // make sure the router is still here after GC to note the memory difference.
            OsmSharp.Logging.Log.TraceEvent("LivePreProcessor", Logging.TraceEventType.Information, memoryData.ToString());
            memoryData = null;

            GC.Collect();
        }
        static void Main(string[] args)
        {
            // enable logging and use the console as output.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(
                new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());

            // create router.
            using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead())
            {
                var pbfSource = new PBFOsmStreamSource(source);
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(pbfSource);
                var router = Router.CreateCHFrom(progress, new OsmRoutingInterpreter(), Vehicle.Car);

                OsmSharp.Service.Routing.ApiBootstrapper.Add("default", router);
            }

            var uri = new Uri("http://*****:*****@ http://localhost:1234");
                System.Diagnostics.Process.Start("http://localhost:1234/default");

                Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            // enable logging and use the console as output.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(
                new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());

            // create router.
            using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead())
            {
                var pbfSource = new PBFOsmStreamSource(source);
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(pbfSource);
                var router = Router.CreateFrom(progress, new OsmRoutingInterpreter());

                OsmSharp.Service.Routing.ApiBootstrapper.Add("default", router);
            }

            // initialize mapcss interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Routing.Sample.SelfHost.custom.mapcss"),
                new MapCSSDictionaryImageSource());

            using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead())
            {
                var pbfSource = new PBFOsmStreamSource(source);
                var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List<float>(new float[] {
                16, 14, 12, 10 }));
                var target = new StyleOsmStreamSceneTarget(
                    mapCSSInterpreter, scene, new WebMercator());
                var progress = new OsmStreamFilterProgress();
                progress.RegisterSource(pbfSource);
                target.RegisterSource(progress);
                target.Pull();

                // create a new instance (with a cache).
                var instance = new RenderingInstance();
                instance.Map.AddLayer(new LayerScene(scene));

                // add a default test instance.
                OsmSharp.Service.Tiles.ApiBootstrapper.AddInstance("default", instance);
            }

            var uri = new Uri("http://*****:*****@ http://localhost:1234");
                System.Diagnostics.Process.Start("http://localhost:1234/default");

                Console.ReadLine();
            }
        }
        /// <summary>
        /// Executes reading tests.
        /// </summary>
        public static void Test()
        {
            var testFile = new FileInfo(@".\TestFiles\kempen-big.osm.pbf");
            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);
            var completeSource = new OsmSharp.Osm.Streams.Complete.OsmSimpleCompleteStreamSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer("OsmSimpleCompleteStreamSourceTests.Pull");
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var completeObjects = new List<ICompleteOsmGeo>(completeSource);

            stream.Dispose();

            performanceInfo.Stop();
        }
        /// <summary>
        /// Tests interpreting all data from a given pbf source.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="scene"></param>
        /// <param name="interpreter"></param>
        /// <param name="pbfSource"></param>
        public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource)
        {
            StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget(
                interpreter, scene, new WebMercator());
            FileInfo testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource));
            Stream stream = testFile.OpenRead();
            OsmStreamSource source = new PBFOsmStreamSource(stream);
            OsmStreamFilterProgress progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);
            target.RegisterSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString());

            target.Pull();

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
            stream.Dispose();

            return testFile.OpenRead();
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestSerialization(string name, string pbfFile)
        {
            var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));

            var performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);

            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            Stream writeStream = testOutputFile.OpenWrite();

            var tagsIndex = new TagsTableCollectionIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var routingSerializer = new LiveEdgeFlatfileSerializer();

            // read from the OSM-stream.
            using (var fileFactory = new MemoryMappedFileFactory(@"d:\temp\"))
            {
                using (var memoryMappedGraph = new MemoryMappedGraph<LiveEdge>(10000, fileFactory))
                {
                    using (var coordinates = new HugeCoordinateIndex(fileFactory, 10000))
                    {
                        var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(memoryMappedGraph, tagsIndex);
                        var targetData = new LiveGraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);
                        targetData.RegisterSource(progress);
                        targetData.Pull();

                        performanceInfo.Stop();

                        performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
                        performanceInfo.Start();
                        performanceInfo.Report("Writing file for {0}...", testFile.Name);

                        var metaData = new TagsCollection();
                        metaData.Add("some_key", "some_value");
                        routingSerializer.Serialize(writeStream, memoryData, metaData);
                    }
                }
            }
            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
            performanceInfo.Stop();

            performanceInfo = new PerformanceInfoConsumer("LiveSerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Reading file for {0}...", testFile.Name);

            var testInputFile = new FileInfo(@"europe-latest.osm.pbf.routing");
            Stream readStream = testInputFile.OpenRead();

            var deserializedGraph = routingSerializer.Deserialize(readStream, false);

            readStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Read: {0}KB", testInputFile.Length / 1024));

            OsmSharp.Logging.Log.TraceEvent("LiveSerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());

            performanceInfo.Stop();
        }
        /// <summary>
        /// Tests preprocessing data from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pbfFile"></param>
        public static void TestSerialization(string name, string pbfFile)
        {
            var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));

            var performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 2000);
            performanceInfo.Start();
            performanceInfo.Report("Pulling from {0}...", testFile.Name);

            var stream = testFile.OpenRead();
            var source = new PBFOsmStreamSource(stream);
            var progress = new OsmStreamFilterProgress();
            progress.RegisterSource(source);

            var testOutputFile = new FileInfo(@"test.routing");
            testOutputFile.Delete();
            var writeStream = testOutputFile.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite);

            var tagsIndex = new TagsIndex();
            var interpreter = new OsmRoutingInterpreter();
            var graph = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var routingSerializer = new RoutingDataSourceSerializer();

            var memoryMappedGraph = new Graph<Edge>(1024);
            var coordinates = new HugeCoordinateIndex(1024);
            var memoryData = new RouterDataSource<Edge>(memoryMappedGraph, tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, new OsmRoutingInterpreter(), tagsIndex, coordinates);
            targetData.RegisterSource(progress);
            targetData.Pull();

            performanceInfo.Stop();

            memoryData.Compress();

            performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            performanceInfo.Start();
            performanceInfo.Report("Writing file for {0}...", testFile.Name);

            var metaData = new TagsCollection();
            metaData.Add("some_key", "some_value");
            routingSerializer.Serialize(writeStream, memoryData, metaData);
            stream.Dispose();
            writeStream.Dispose();

            OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
                string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024));
            performanceInfo.Stop();

            ////performanceInfo = new PerformanceInfoConsumer("SerializerFlatFile.Serialize", 100000);
            ////performanceInfo.Start();
            ////performanceInfo.Report("Reading file for {0}...", testFile.Name);

            //var testInputFile = new FileInfo(@"test.routing");
            //var readStream = testInputFile.OpenRead();

            //RoutingTest.TestSerialized(readStream);

            ////var deserializedGraph = routingSerializer.Deserialize(readStream, false);

            ////readStream.Dispose();

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", OsmSharp.Logging.TraceEventType.Information,
            ////    string.Format("Read: {0}KB", testInputFile.Length / 1024));

            ////OsmSharp.Logging.Log.TraceEvent("SerializerFlatFile", Logging.TraceEventType.Information, deserializedGraph.ToInvariantString());

            ////performanceInfo.Stop();
        }