[MAPSERVER-USERS] mapObject serialization in C# (variant)

Cavalieri Piero Piero.Cavalieri at heidi.it
Wed Jun 11 08:20:44 EDT 2008


I don't know C# mapscript, but are you sure you need to serialize the whole mapObj? At the and I think that in your client, you will use: image, reference map and scalebar urls, an html (or xml) representation of the legend...so why don't to serialize a custom object which contains only these things ? I do so, without using mapscript, it's simple...

Cheers
 Piero

> -----Original Message-----
> From: mapserver-users-bounces at lists.osgeo.org [mailto:mapserver-users-
> bounces at lists.osgeo.org] On Behalf Of Tamas Szekeres
> Sent: martedì 10 giugno 2008 19:58
> To: BrainDrain
> Cc: mapserver-users at lists.osgeo.org
> Subject: Re: [MAPSERVER-USERS] mapObject serialization in C# (variant)
> 
> Hi,
> 
> MapServer currently doesn`t support any other persitence
> representation than the mapfiles. There have been some initial plans
> related to an XML format in this list, but no one had any motivation
> to implement that.
> So I think the best what you can do at the moment is to use reflection
> to access the properties along with some other members of the objects
> and serialize the values manually.
> 
> Best regards,
> 
> Tamas
> 
> 
> 2008/6/9 BrainDrain <paulborodaev at gmail.com>:
> >
> > Is there any 'standart' fast(!) way/method to serialize (xml/json/other
> > markup) mapObj in C#? I need it for using server mapObj as JSON on rich
> > client app running on browser. Look at my method (using reflection):
> >
> > public static ListDictionary PartialSerialize(object instance, Stack
> > callerTypes, Type[] excludeTypes)
> >        {
> >            ListDictionary result = new ListDictionary();
> >            object val;
> >
> >            callerTypes.Push(instance.GetType());
> >            PropertyInfo[] pis = instance.GetType().GetProperties();
> >            foreach (PropertyInfo pi in pis)
> >            {
> >                if (pi.PropertyType.IsSerializable &&
> > !pi.PropertyType.IsArray)
> >                    result[pi.Name] = pi.GetValue(instance, new
> object[0]);
> >                else
> >                {
> >                    //preventing useless nesting
> >                    if (!callerTypes.Contains(pi.PropertyType) &&
> > !((IList)excludeTypes).Contains(pi.PropertyType))
> >                    {
> >                        val = pi.GetValue(instance, new object[0]);
> >                        if (val != null)
> >                            result[pi.Name] = PartialSerialize(val,
> > callerTypes, excludeTypes);
> >                    }
> >                }
> >            }
> >            callerTypes.Pop();
> >            return result;
> >        }
> > ...
> > So I can convert mapObj on serever to hashtable automatically an then
> > populate JSON object
> > (still need to call explicitly getLayer, getClass etc., but this is not
> a
> > problem):
> > ...
> > layers[i].Properties = Tools.PartialSerialize(layer, new Stack(), new
> > Type[3] { typeof(mapObj), typeof(hashTableObj), typeof(colorObj)});
> > ...
> > classes[j].Properties = Tools.PartialSerialize(layerClass, new Stack(),
> new
> > Type[4] { typeof(layerObj), typeof(labelObj), typeof(hashTableObj),
> > typeof(colorObj)});
> > ...
> > styles[k].Properties = Tools.PartialSerialize(classStyle, new Stack(),
> new
> > Type[2]{typeof(hashTableObj), typeof(colorObj)});
> > ...
> > mapStub.Properties = Tools.PartialSerialize(map, new Stack(), new
> Type[11] {
> > typeof(labelObj), typeof(hashTableObj), typeof(fontSetObj),
> > typeof(labelCacheObj), typeof(outputFormatObj[]), typeof(queryMapObj),
> > typeof(referenceMapObj), typeof(scalebarObj), typeof(symbolSetObj),
> > typeof(colorObj), typeof(legendObj)});
> > ...
> > JavaScriptSerializer class object allows to perform convertion to client
> > More often I use script method in my web service that can do it behind
> the
> > scenes.
> >
> > How do you do such kind of operation?
> > --
> > View this message in context: http://www.nabble.com/mapObject-
> serialization-in-C--%28variant%29-tp17739919p17739919.html
> > Sent from the Mapserver - User mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > mapserver-users mailing list
> > mapserver-users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/mapserver-users
> >
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users


More information about the mapserver-users mailing list