Beispiel #1
0
        public void readListFromDatabase(string connectionstring)
        {
            using (var conn = new NpgsqlConnection(connectionstring))
            {
                conn.Open();
                conn.TypeMapper.UseNetTopologySuite();
                CMapTileList aMapTileList = new CMapTileList();

                // note that it is overkill to do bulk import for two objects, but as example...
                using (var reader = conn.BeginBinaryExport("COPY public.tiletest(id_tile_250, the_geom ) TO STDOUT (FORMAT BINARY)"))
                {
                    while (reader.StartRow() > 0)
                    {
                        long       aMapId      = reader.Read <long>(NpgsqlDbType.Bigint);
                        Polygon    aPolygon    = reader.Read <Polygon>(NpgsqlDbType.Geometry);
                        Coordinate aCoordinate = aPolygon.Coordinates[0];
                        CMapTile   aCmapTile   = new CMapTile((long)aCoordinate.X, (long)aCoordinate.Y);
                        aCmapTile.TileID = aMapId;
                        aMapTileList.theMapList.Add(aCmapTile);
                    }
                    reader.Cancel();
                }
                conn.Close();
            }
        }
Beispiel #2
0
        public static void readListToFileToDiskBinary(Stopwatch sw, string pathToFile, CStartParameters aStartParameters)
        {
            CMapTileList aMapaMapTileList = null;

            using (FileStream fs = new FileStream(pathToFile, FileMode.Open))
                using (var memoryStream = new MemoryStream())
                {
                    sw.Start();
                    fs.CopyTo(memoryStream);
                    sw.Stop();
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    IFormatter formatter = new BinaryFormatter();
                    aMapaMapTileList = (CMapTileList)formatter.Deserialize(memoryStream);
                }

            if (aStartParameters.removeTestFile_DatabaseAfterTest)
            {
                File.Delete(pathToFile);
            }
        }
Beispiel #3
0
        public static void writeListToFileToDiskBinary(Stopwatch sw, string pathToFile, CMapTileList aMapTileList)
        {
            IFormatter formatter = new BinaryFormatter();

            using (var memoryStream = new MemoryStream())
                using (var stream = new FileStream(pathToFile, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    formatter.Serialize(memoryStream, aMapTileList);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    sw.Start();
                    memoryStream.CopyTo(stream);
                    stream.Flush();
                    sw.Stop();
                }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();

            // Read start parameter file
            CStartParameters aStartParColl = new CStartParameters("StartParamsPiposBenchmark.txt");

            //construct testdata
            Console.WriteLine("Starts performance test");
            Console.WriteLine("Creates testtiles");
            sw.Start();
            CMapTileList aMaptileList = new CMapTileList(aStartParColl);

            sw.Stop();
            Console.WriteLine("It took {0} to create testdata", sw.Elapsed);
            Console.WriteLine();
            sw.Reset();


            //Test disk performace
            // 10 possible test slots
            Console.WriteLine();
            Console.WriteLine("Test performace of diskconnection.");
            for (int i = 0; i < 10; i++)
            {
                if (aStartParColl.targetFolders[i] != null)
                {
                    CMapTileList.writeListToFileToDiskBinary(sw, aStartParColl.targetFolders[i], aMaptileList);
                    Console.WriteLine("{0}   Write Timemeasure={1}", aStartParColl.targetFoldersName[i], sw.Elapsed);
                    sw.Reset();
                    FileInfo fi = new FileInfo(aStartParColl.targetFolders[i]);
                    Console.WriteLine("File Size in Megabytes: {0}", ((Int64)(fi.Length / 1024f) / 1024f));
                    CMapTileList.readListToFileToDiskBinary(sw, aStartParColl.targetFolders[i], aStartParColl);
                    Console.WriteLine("{0}   Read Timemeasure={1}", aStartParColl.targetFoldersName[i], sw.Elapsed);
                    Console.WriteLine();
                    sw.Reset();
                }
            }
            //Test database performace
            // 10 possible test slots
            Console.WriteLine("Test performace of databaseconnection.");
            for (int i = 0; i < 10; i++)
            {
                if (aStartParColl.connectStrings[i] != null)
                {
                    sw.Start();
                    aMaptileList.writeListToDatabase(aStartParColl.connectStrings[i]);
                    sw.Stop();
                    Console.WriteLine("{0}   Write Timemeasure={1}", aStartParColl.connectStringsName[i], sw.Elapsed);
                    sw.Reset();
                    CMapTileList.GetSizeOfTable(aStartParColl.connectStrings[i]);
                    sw.Start();
                    aMaptileList.readListFromDatabase(aStartParColl.connectStrings[i]);
                    sw.Stop();
                    Console.WriteLine("{0}   Read Timemeasure={1}", aStartParColl.connectStringsName[i], sw.Elapsed);
                    Console.WriteLine();
                    sw.Reset();
                }
            }
            Console.WriteLine();
            Console.WriteLine("Done! Press any key to close.");
            Console.ReadKey();
        }