[mapguide-users] Sessions on server side

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Tue Feb 23 03:54:16 EST 2010


I see that you have found the problem with the selection object as well :).
I have been quite annoyed with that many times myself.

You can actually save and restore the RuntimeMap (and selection data).
If you do this, a side effect is that the object id's are not re-generated.
I use this frequently, because MgMap.Create takes too long in my solutions.

To do this, you need to convert the name of the map into a resource id,
eg. mapName = "MAP", the resource id becomes:
Session:<session-id>//MAP.Map

If you apply GetResourceContent to this, you get an xml document with 
"<Map />"
as the only content.

You must then issue the EnumerateResourceData on the resourceId,
and you should be able to see the map, the layers and the darned 
selection resource.

You can download these with GetResourceData. They are binary objects,
and internal to MapGuide. I have written a helper class to read/write 
them here:
http://trac.osgeo.org/mapguide/browser/trunk/Tools/Maestro/MaestroAPI/RuntimeClasses
http://trac.osgeo.org/mapguide/browser/trunk/Tools/Maestro/MaestroAPI/BinarySerializer

You can simply store these files on disk.
When you start a session, you can revert the process, and create the 
"<Map />" resource,
and call SetResourceData to upload the files.

The binary files are a copy of the MapDefinition (and some of the 
FeatureSource/LayerDefinition stuff),
so if you change the MapDefinition/LayerDefinition/FeatureSource, you 
must re-generate the binary files.

Using this approach, you can skip the _map.Create call, and thus get 
"static" object id's.
If you use the MaestroAPI reader/writer, you can also set the object id's.

Regards, Kenneth Skovhede, GEOGRAF A/S

On 22-02-2010 22:08, Pietro Ianniello wrote:
> "Ok, I can see that I misjudged your experience level completely"
> No problem :-), I see that there are many questions about things such 
> as "Can I use images in MapGuide" and such, wich are all answered in 
> MapGuide developer guide [wich should be printed and read ,and 
> re-read... and re-re-read!].
>
> If you are intersted, you can download the attachment from
> http://n2.nabble.com/Sessions-on-server-side-td4612873.html
>
> It assumes MapGuide OS installed in "C:\OSGeo"
> so "webconfig.ini" in "*C:\OSGeo\MapGuide\Web\www*",
> with the .NET viewer.
>
> If it is in another place, the file "*MgSheboyganCacheHelper.cs*" at 
> line 61 bust be accordingly changed.
>
> A better approach is to use the following function (as I do in my 
> assembly that controls MapGuide):
>
>    //call CLASSNAME.SetIniPath("/mapguide/");
> public static void SetIniPath(string strMGVirtualDirectoryPath)
>    {
>             string physicalpath =
>                      
> HttpContext.Current.Server.MapPath(strMGVirtualDirectoryPath);
>             _strWebconfigPhysicalInipath = physicalpath + "webconfig.ini";
>             _strIniBasePhysicalPath = physicalpath;
>             _strWebconfigWebInipath = strMGVirtualDirectoryPath + 
> "webconfig.ini";
>             _strIniBaseWebPath = strMGVirtualDirectoryPath;
>    }
>
> wich assumes the following members [default initialized]:
>
> protected static string _strWebconfigPhysicalInipath = 
> "C:\\OSGeo\\MapGuide\\Web\\www\\webconfig.ini";
> protected static string _strIniBasePhysicalPath = 
> "C:\\OSGeo\\MapGuide\\Web\\www\\";
> protected static string _strWebconfigWebInipath = 
> "http://localhost/mapguide/webconfig.ini";
> protected static string _strIniBaseWebPath = 
> "http://localhost/mapguide/";
>
> My solution works, and I like it.
> I only have concerns about scalability: what will MapGuide do when 
> there are multiple requests with the same session? Will it queue them 
> properly as if sessons where al different?
>
> A further explanation on why I use such a thing.
>
> I use MapGuide with Openlayers. OpenLayers can request 
> "showLayers","hideLayers". I set up maps with all layers default 
> invisible. The I "activate" the layers I want to see in javascript 
> using the two OpenLayers option just mentioned. This could be done on 
> server side, but in this case the state of the map would be stored in 
> session [/layer.SetVisible(true);map.Save();/], and, furthermore, my 
> idea is that if something can be done on the client, do it on the 
> client and save computation on the server.
>
> The proble with "showLayers/hideLayers" is that they need "ObjectId" 
> of the layer. So to give that id you must do something like:
> /_map.GetLayers().GetItem("<LAYER NAME>").GetObjectId();/
> and this must be done on every session expiration.
> So when in my solution [the real, not the posted one] I recreate the 
> server side mantained "cache" of session, I recreate a list with these 
> ObjectId.
>
> If my solution doesn't scale well, the alternative is to recreate 
> OpenLayers' layers with a new session and store in javascript the new 
> ObjectIds. This is a lot of work for many reasons it's off topic to 
> expose.
>
> I prefer my solution even because shelds me from exposing sessions, 
> and with "MgSheboyganCacheHelper.cs" I could one day [time permitting] 
> expose MapGuide only to localhost, using a proxy to access it - 
> something like "MgSheboyganCacheHelper.cs" but more general.
>
> This for Anonymous users, and for publicly available sites.
>
> If one wants to use MapGuide in intranet or to do editing, it's a 
> different story.
>
> Regard,
>     Pietro Ianniello
>
> P.S.: I could answer to my question by downloading MapGuide sources... 
> even though I am programming in C#, I come from C++, so it would not 
> be a problem, but I think it would requre HUGE ammount of time! And 
> now I don't have it...
>
> P.P.S.: [out of topic] It would be nice if somwhere there is some info 
> about updating FDO with the current MG OS. For example usng FDO 3.4.1 
> instead of 3.4.0... I say this in perspective... I am very intersted 
> in PostGIS, and anxious to see and test a good implementation, because 
> now it's not usable [seems FDO 4.5 will, If I understand  - 
> http://trac.osgeo.org/fdo/wiki/FDORfc45 - if that 45 stands for 4.5].
>
> P.P.P.S.: I anwered 2 times before, because Mail Delivery System 
> <MAILER-DAEMON at lists.osgeo.org <mailto:MAILER-DAEMON at lists.osgeo.org>> 
> continues to tell me that:
>              I'm sorry to have to inform you that your message could not
>              be delivered to one or more recipients. It's attached below.
> Don't know why...
>
>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>    
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20100223/93aedc97/attachment.html


More information about the mapguide-users mailing list