[mapguide-users] .NET Objects for working with Mapguide Resources

Kenneth Skovhede, GEOGRAF A/S ks at geograf.dk
Sat May 24 17:22:54 EDT 2008


Yes. I have moved the entire site over on the MapGuide wiki.
Documentation can now be found here:
http://trac.osgeo.org/mapguide/wiki/maestro
And for the API:
http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI

Too bad about the LinQ dependancy, it would be a lot cleaner to do it 
that way.

I have not exposed functionality in the way you ask, but it is there.
You can do it with code like this:
Stream s = ... stream with Xml data ...
LayerDefinition layer = 
(LayerDefinition)con.DeserializeObject(typeof(LayerDefinition), s);
layer.BackgroundColor = Color.White;
s = con.SerializeObject(s);

The methods could actually be static, but they are not because they use 
the server version to restrict/convert the version's of the documents.

It is possible to serialize/deserialise the objects manually, using the 
XmlSerializer from .Net:
XmlSerializer ser = new XmlSerializer(typeof(LayerDefinition));
layer = (LayerDefinition)con.Deserialize(s);
layer.BackgroundColor = Color.Green;
ser.Serialize(s, layer);

There is a function in the Utility class that strips the UTF-8 BOM:
s = Utility.RemoveUTF8BOM(s);


Regards, Kenneth Skovhede, GEOGRAF A/S



Darrin Maidlow skrev:
>
> Hi Kenneth,
>
>  
>
> Thanks for the feedback.  You are very right in that dual development 
> streams would be a bad thing and a waste of a lot of time.   What I 
> was hoping to accomplish with that XSD codegen was to create a set of 
> relatively light weight objects to roundtrip the xml.  Eliminate the 
> use of XML tools for working with the mapguide entities, then return 
> the entities back to XML for use with the Mapguide API.    I was not 
> planning a full API project.  Again, you are right in that there is 
> still some messing around needed to be done with the linq code -- I 
> had problems with nulls just as you mentioned =)
>
>  
>
> To answer your question, as far as I can see, the linq dll is required 
> for the generated code to function.  A lot of the generated 
> functionality requires methods that exist within the linq to XSD dll file.
>
>  
>
> I spent some time trying to find more info on the MeastroAPI today, 
> but was not able to find much.  Likely because of the move over to 
> osgeo.  I have not had a chance to actually work with the API again 
> yet, but perhaps you could answer a couple questions for me.
>
>  
>
> Does Meastro API come with the abovementioned objects I was looking 
> for?  Can I shove some XML from the repository into a new object, do 
> some work, and then spit the new XML back out?  If so, I'm assuming 
> that I could continue to work with the web tier API from Mapguide?
>
>  
>
> thx
>
> darrin
>
>  
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Kenneth 
> Skovhede, GEOGRAF A/S
> *Sent:* Thursday, May 22, 2008 12:04 PM
> *To:* MapGuide Users Mail List
> *Subject:* Re: [mapguide-users] .NET Objects for working with Mapguide 
> Resources
>
>  
>
> That is a smart way to convert Xsd to classes. Is it possible to 
> extract the generated code and use it without LinQ for .Net 2.0?
>
> I'm not sure what you mean by "wanted to stay closer to the core API". 
> Your generated classes expose the MapGuide Xml as .Net classes.
> You can then use .Net objects "directly" instead of handling Xml. That 
> is exactly what the MaestroAPI does.
>
> I have implemented a connection interface that enables you to 
> communicate with MapGuide either via the MapGuide API, or through Http.
> If you use the LocalNativeConnection exclusively, MaestroAPI is doing 
> the exact same thing your code does.
>
> If you (or someone else) has questions about MaestroAPI usage, please 
> ask away.
> If you (or someone else) find missing functionality, or has 
> improvements for MaestroAPI, let me know.
> I have a short introduction to MaestroAPI usage here:
> http://code.google.com/p/mapstudioos/wiki/HowToUseMapGuideAPI
> (The site is being migrated to here: 
> http://trac.osgeo.org/mapguide/wiki/maestro)
>
> I like your code, and if you are up for it, I think we both could 
> benefit from one great API extension, rather than two good ones.
> I have learned that after you have the serialization in place there 
> are many places where you must handle trivial stuff like
> converting null string to empty string, empty collections to null 
> collections, etc. MaestroAPI handles much of this already,
> and I would be sad to see you spend your time implementing that for 
> another project.
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> Darrin Maidlow skrev:
>
> Hi Maksim,
>
> I looked at early on in my learnage, but wanted to stay closer to the 
> core API provided by Mapguide Project / Autodesk.   ADN support could 
> offer some help with the built in API, and if needed escalate off to 
> the devs.  I did also have some problems getting the Maestro API 
> running -- but that was right around the transition between 1.1 and 
> 2.0 -- and working all night with too much redbull probably didn't 
> help either =)
>
>  
>
> darrin
>
>  
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Maksim 
> Sestic
> *Sent:* Thursday, May 22, 2008 7:40 AM
> *To:* 'MapGuide Users Mail List'
> *Subject:* RE: [mapguide-users] .NET Objects for working with Mapguide 
> Resources
>
>  
>
> Hi Darrin,
>
>  
>
> Thanks for the tip. Please take a look at Kenneth's Meastro API:
>
>  
>
> http://trac.osgeo.org/mapguide/browser/trunk/Tools/Maestro/MaestroAPI
>
>  
>
> It relies on .NET 2.0 for MG types (de)serialization.
>
>  
>
> Regards,
>
> Maksim Sestic
>
>  
>
> ------------------------------------------------------------------------
>
> *From:* mapguide-users-bounces at lists.osgeo.org 
> <mailto:mapguide-users-bounces at lists.osgeo.org> 
> [mailto:mapguide-users-bounces at lists.osgeo.org] *On Behalf Of *Darrin 
> Maidlow
> *Sent:* Thursday, May 22, 2008 15:28
> *To:* mapguide-users at lists.osgeo.org 
> <mailto:mapguide-users at lists.osgeo.org>
> *Subject:* [mapguide-users] .NET Objects for working with Mapguide 
> Resources
>
> Hi List,
>
>  
>
> I've written two posts I thought I would share with you on the topic 
> of .NET based MG dev.  The first describes a method I've worked out to 
> create relatively robust .NET based objects based on the Xml Schema 
> Definitions provided with the server.    Please note, I currently am 
> only working with MGE 2009.  I have not tried this code on MGOS.  If 
> you do try them on MGOS, please let me know what results have.
>
>  
>
> In a nutshell, one can get the resource XML from the resource service, 
> load it into the object with the provided .parse method, manipulate 
> the object (without having to use xml) e.g. add child objects, change 
> properties etc, and finally spit it back out to XML for saving back to 
> the repository.  Yay no longer need to be jealous of the PHP guys and 
> their object factories =D
>
>  
>
> The second is a dynamic authoring example using these objects, 
> manipulating the MapDefinition before the viewer has loaded it.
>
>  
>
> Both come with full source code, and Visual Studio 2008 projects.   I 
> hope they are helpful to the other .NET devs out there.
>
>  
>
> http://www.webrade.com/blogs/darrin/2008/05/16/CreatingNETObjectsForMapguideXMLSchemaDefinitionsXSDUsingLINQ.aspx
>
> http://www.webrade.com/blogs/darrin/2008/05/21/DynamicAuthoringInMapguideEnterpriseBeforeTheViewerHasLoaded.aspx
>
>  
>
> Enjoy.
>
> darrin
>
>  
>
>
>
> __________ NOD32 3118 (20080521) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>  
> ------------------------------------------------------------------------
>
>
>   
>  
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org <mailto:mapguide-users at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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/20080524/74388a55/attachment.html


More information about the mapguide-users mailing list