Skip to content

Commit

Permalink
Apply recent changes in mapscript to make mapObj serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
szekerest committed Dec 1, 2015
1 parent 617f146 commit b74b1ce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
18 changes: 16 additions & 2 deletions mapscript/csharp/csmodule.i
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static SWIG_CSharpByteArrayHelperCallback SWIG_csharp_bytearray_callback = NULL;

%ignore imageObj::write;

%typemap(cscode) imageObj %{
%typemap(cscode) imageObj, struct imageObj %{
private byte[] gdbuffer;
private void CreateByteArray(IntPtr data, int size)
{
Expand All @@ -290,7 +290,9 @@ static SWIG_CSharpByteArrayHelperCallback SWIG_csharp_bytearray_callback = NULL;
%csmethodmodifiers processLegendTemplate "private";
%csmethodmodifiers processQueryTemplate "private";

%typemap(cscode) mapObj %{
%typemap(csinterfaces) mapObj "IDisposable, System.Runtime.Serialization.ISerializable";
%typemap(csattributes) mapObj "[Serializable]"
%typemap(cscode) mapObj, struct mapObj %{
public string processTemplate(int bGenerateImages, string[] names, string[] values)
{
if (names.Length != values.Length)
Expand All @@ -311,6 +313,18 @@ static SWIG_CSharpByteArrayHelperCallback SWIG_csharp_bytearray_callback = NULL;
throw new ArgumentException("Invalid array length specified!");
return processQueryTemplate(names, values, values.Length);
}

public mapObj(
System.Runtime.Serialization.SerializationInfo info
, System.Runtime.Serialization.StreamingContext context) : this(info.GetString("mapText"), 1)
{
//this constructor is needed for ISerializable interface
}

public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
{
info.AddValue( "mapText", this.convertToString() );
}
%}


Expand Down
5 changes: 5 additions & 0 deletions mapscript/mapscript.i
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
#include "pygdioctx/pygdioctx.h"
#endif

#if defined(WIN32) && defined(SWIGCSHARP)
/* <windows.h> is needed for GetExceptionCode() for unhandled exception */
#include <windows.h>
#endif

%}

/* Problem with SWIG CSHARP typemap for pointers */
Expand Down
17 changes: 17 additions & 0 deletions mapscript/swiginc/map.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
return msNewMapObj();
}
}

#ifdef SWIGCSHARP
mapObj(char *mapText, int isMapText /*used as signature only to differentiate this constructor from default constructor*/ )
{
return msLoadMapFromString(mapText, NULL);
}
#endif

~mapObj()
{
Expand Down Expand Up @@ -192,7 +199,17 @@

%newobject draw;
imageObj *draw() {
#if defined(WIN32) && defined(SWIGCSHARP)
__try {
return msDrawMap(self, MS_FALSE);
}
__except(1 /*EXCEPTION_EXECUTE_HANDLER, catch every exception so it doesn't crash IIS*/) {
msSetError(MS_IMGERR, "Unhandled exception in drawing map image 0x%08x", "msDrawMap()", GetExceptionCode());
}
#else
return msDrawMap(self, MS_FALSE);
#endif

}

%newobject drawQuery;
Expand Down

0 comments on commit b74b1ce

Please sign in to comment.