Making a Compact Framework (CF) build for SharpMap
by Roger Bedell (roger@sylvanascent.com) 6/20/2006. I am currently living in Granada,
Spain, ph#(+34)958-487-166
- Remove references that don't exist in CF, and source files that use them.
System.Data.OracleClient: Data\Providers\Oracle.cs No Oracle client in CF.
NCSecWLib,stdole: Layers\EcwRasterLayer.cs I'm not sure the ECW exists in CF land.
stdole no longer needed since no more OLE stuff is used.
Npgsql: Data\Providers\PostGIS.cs Unlikely we will use PostGIS on a CF device
System.Web: Web\HttpHandler.cs System.Web doesn't exist in CF. A number of items
depend on this.
- The WMS server stuff, not really necessary in a CF device.
Web\Wms\capabilities.cs
Web\Wms\WmsException.cs
Web\Wms\WmsServer.cs
- The image caching stuff
Web\cache.cs
- The Shapefile data provider. This is a problem since a CF GIS will need to be
able to read indexed shapefiles. Apparently, HttpHandler is used to cache the shape
index files in the web cache. There is a comment in the code:
//Store the tree in the web cache
//TODO: Remove this when connection pooling is implemented
System.Web.HttpContext.Current.Cache.Insert(_Filename, tree, null, System.Web.Caching.Cache.NoAbsoluteExpiration,
TimeSpan.FromDays(1));
Perhaps this could be removed, or saved in a different place besides the web cache?
It looks like you can already use a file, so there needs to be a compiler directive
to remove all the System.Web stuff from ShapeFile.cs. Added to ShapeFile.cs - compiler
#define CFBuild
Mono.Security - removed since nothing seems to use it.
System.Design - removed since no design time support. (not using Sharpmap.ui)
That done, I created a new CF class project and copied the source tree from Sharpmap
to the new project SharpmapCF (Highlight everything in SharpMap except References
and properties, then drag over to blank class project and drop).
Add all the correct CF references to match the full framework version.
shft-ctrl-b and voila, 80 errors! All, "type or namespace missing". Obviously, some
things are missing, especially the Serialization stuff. So, look for a CF Serialization
library. Apparently in CF2.0 SP1 they are adding this. Downloaded CF2.0, Beta 1,
and these went away. (Note, no longer necessary, DO NOT install SP1, you can never
get rid of it unless you uninstall VS and reinstall!)
I left in SQLClient, but the CF reference to System.Data.SqlClient had to be added
to references.
Had to remove OleDB provider, no System.Data.OleDb in CF - remove Data\Providers\OleDbPoint.cs
There were a lot of "using System.Runtime.Serialization;" in many files. This class
does not exist in CF. I replaced them with:
#if !CFBuild
using System.Runtime.Serialization;
#endif
in the following files:
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Data\FeatureDataSet.cs(21):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Data\Providers\ShapeFile.cs(461):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Data\Providers\ShapeFile.cs(501):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Geometries\Geometry.cs(21):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Geometries\Point.cs(21):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Geometries\Point3D.cs(21):#if
!CFBuild
C:\downloads\Sharpmap\SharpMap_source_v0[1].9.2327\src\SharpMapCF\Utilities\Surrogates.cs(21):#if
!CFBuild
Now, down to 57 errors, mostly GDI and serialization problems.
Many of the GDI issues had to do with the lack of a System.Drawing.PointF class.
These have to be converted to System.Drawing.Point instead. Hopefully this won't
muck up the works too bad.
Many changes to avoid the use of PointF
Drop Surrogates.cs - none of this is in CF
Quite a few changes in the source code to make it compile and work in CF. A number
of them can be folded back into the main source as they are equivalent, just a different
overload or such. Others will require a compiler switch.
Look through the code, looking for #if !CFBuild. There are comments (hopefully meaningful)
for each one. I didn't remove any of the original source code.
PS: Went back and removed all the "Serializable" attributes. Now it works without
using CF 2.0 SP1