November 4, 2011

Introducing Question of the Week for ObjectARX.NET and Mapguide

Filed under: AutoCAD,Development,Mapguide — Tags: , , , — Darrin Maidlow @ 11:32 pm

Every good developer is constantly evolving and learning new technologies.  This can be a challenge when you’re hard at work in maintenance mode on familiar technology or when your every day needs don’t go as deeply into topics as you would like. 

If you take a step back and look at AutoCAD and – its a huge body of work and it is a challenge to get experience in all the various parts of it.  The recent request I received on how to or the command line and the subsequent research, code and blog post I wrote made me think,  what if I solicited small problems from the AutoCAD community that could make fun little 4 hour research projects.  These would allow me to dig into various portions of ObjectARX.NET once a week, write some fun code, and give me things to write about.  Everybody wins!

I’m looking to spend about 4-6 hours on each question.  I’m hoping to do one question per week, assuming I get enough requests.  I’ll provide the full source and project with each post.  All code will be written in c#.  Some examples of valid requests would be:

  • Submit a Visual Lisp routine to convert to ObjectARX.NET.
  • Request a particular routine that does some sort of drawing clean up or modifies something.
  • Identify some functionality that is missing in AutoCAD.
  • Request a piece of sample code explaining how to use API x of ObjectARX.NET or Mapguide Enterprise/Open Source.

The Do’s

  • Please keep your request realistic.   I’ve only got 4 to 6 hours and you’re not paying me =)
  • Please submit specific functionality along with sample data.
  • Please be available to answer any questions  I might have via e-mail, phone/skype or possibly gotomeeting.
  • Please keep the underlying technology somewhat current.  Don’ t request AutoCAD/Mapguide 2007.
  • Please review my code and comment if you see something wrong or that I could do more efficiently.  This is about me learning and I’m gonna make mistakes.

The Don’ts

  • Don’t expect days worth of work, I just don’t have that much spare time.
  • Don’t ask me to work on your project (unless of course you want to hire my team via ).
  • Please don’t get upset if I don’t pick your question.
  • I did my ten odd years in the trenches writing Visual Lisp – I don’t really want to write any more, so please don’t ask for lisp code.
  • Don’t be a ass.  I don’t have time for asses.

Let’s See What Happens

So I have no idea how this will play out.  I don’t know if 4-6 hours is a reasonable amount of time to allocate each week to do this right.   I don’t know if I will be able to make the time every week.  Maybe I’ll change it from “Question of the Week” to “Question of the Every Second Week”.  I’m going to put this out there and see what happens.   I reserve the right to change anything and everything! s  E-mail your requests to contact ~@~ geospecialling dot com.

September 15, 2010

Mapguide Enterprise 2011 – Fusion and Selection XML

Filed under: Mapguide,RADE — Tags: , , — Darrin Maidlow @ 3:00 pm

I’ve been working to migrate the  Mapguide 2010 code to work with 2011.  In 2010, I only implemented support for the DWF and Ajax viewer.  With the release of 2011, the new  ability to include mapping data from Google, Yahoo and Microsoft in Fusion are huge so I opted to migrate everything over.  The DWF viewer is already deprecated and I suspect the Ajax viewer will likely go next.

With 2010 and the Ajax viewer we had to get the selection from the MapFrame using the GetSelectionXML() method.  Then we had to encode, and send this value up to the web tier for processing.  I had all kinds of business logic that I was hoping to re-use with a minimal amount of modifications so I was trying to find how to recreate this functionality with Fusion.  I figured out how the selections worked on the client side using the new callback system and was getting the selection object – but I could not find anything definitively saying “There is no selection XML on the client side anymore”.    So…

There is no selection XML on the client side any more when using Fusion.

There I said it.  It makes sense too – first getting this large XML string and sending it up was a pain in the ass.  Encoding it, creating a form to submit it, etc.   I should have clued into this sooner – Fusion is updating the selection on the server side as needed. 

So in order to minimally impact the existing code – I added an additional check to some of the calls that looks a little something like this:

   1: if (String.IsNullOrEmpty(selectionXml))
   2: {
   3:     MgResourceService resSvc = (MgResourceService)siteConn.CreateService(MgServiceType.ResourceService);
   4:     sel.Open(resSvc, map.GetName());
   5:     selectionXml = sel.ToXml();
   6: }

Those four lines of code are a lot easier than all the screwing around needed in 2010 to get the selection XML.   With that small modification my existing code is working perfectly!

hope this helps someone =)

July 24, 2010

Creating .NET objects for Mapguide Enterprise 2011

Filed under: Development,Mapguide,RADE — Tags: , — Darrin Maidlow @ 11:15 pm

Better late than never…  I’ve updated my Mapguide Enterprise .NET objects to work with 2011.  The steps in my   have been modernized and simplified significantly.   This post will show you how to create (or re-create) these objects for the 2011 release of Mapguide.  Sorry for skipping 2010 =)

First, download the actual non-aplha release of and extract it.  You will need to have .NET 3.5 installed to run LINQ to XSD.  The project itself is a Visual Studio 2010, .NET 4.0 project.  You should be able to change it to .NET 3.5 with no problems.  I’m not sure about using .NET 2.0.   I still assume these steps should work with Mapguide Open Source 2.2 given its pretty much the same thing as MGE 2011.  Please let me know if you try it and that is not the case.

Building the classes

Last time around we had to mess around with Visual Studio projects, building temporary code, finding and extracting that code from temporary files.  This time around, we’re given a nice little executable that can be run in a batch file.   I’ve posted a copy of my batch file below but it was simply made using a dir /b > CreateMapguideNetObjects.cmd in the Mapguide server schema folder (which by default is to c:\Program Files\Autodesk\MapGuideEnterprise2011\Server\Schema) .  I then edited that file with a text editor that support macros and removed the following schema files:

  • FdoProviderCapabilities-1.0.0.xsd
  • LoadProcedure-1.0.0.xsd
  • LoadProcedure-1.1.0.xsd
  • LayerDefinition-1.0.0.xsd
  • LayerDefinition-1.1.0.xsd
  • LayerDefinition-1.2.0.xsd
  • SiteInformation-1.0.0.xsd
  • SiteVersion-1.0.0.xsd
  • SymbolDefinition-1.0.0.xsd
  • WebLayout-1.0.0.xsd

These files are deprecated object definitions from previous Mapguide releases.  In the end each line in the batch file looks a little like this:

LinqToXsd ApplicationDefinition-1.0.0.xsd /filename:ApplicationDefinition.cs

Executing the batch file will create a number of C# files containing appropriately named classes.

Setting up your project

At this point you should be able to fire up Visual Studio and create a new C# project.   If you have an existing project from a previous version of Mapguide its good to start fresh.  Also, don’t try this in an existing solution that is dependant on the project that contains the Mapguide objects.  This will just result in a bunch of extra screwing around to avoid compiler errors from missing code during the process.    This time around its a lot easier.  Create a new DLL project.  Add a reference to the Xml.Schema.Linq.dll file that was included with LinqToXsd.exe.   Add a reference to the following Mapguide dlls:

  • OSGeo.Mapguide.Foundation
  • OSGeo.Mapguide.Geometry
  • OSGeo.Mapguide.MapguideCommon
  • OSGeo.Mapguide.PlatformBase
  • OSGeo.Mapguide.Web

You’ll also need to ensure that the appropriate unmanaged assemblies are available in the calling applications bin folder when you go to run this stuff. 

Next place all of the generated C# files in the new project.  Once you build you’re going to see a ton of errors.  We’ll clean those up.

To resolve a lot of these errors I did a global search and replace on “global::” and replaced it with nothing.  Also, I wrapped each class in a unique wrapper classes to prevent duplicate type errors.  Finally, the case issue with DataType was still an issue – and I resolved it by changing the case on DataType to be Datatype:

   1: public string DataType {
   2: public string Datatype {

For a complete view of the changes I made do a file compare between the code in the attached zip file and your newly generated code.

<insert 3 week gap here, wherein I had so that I could actually test this newly created code, oh and I also went on vacation for a few days too =)/>

And back.  The best part about this is that it seems ALL my old code just worked with upgraded basic layouts after changing it to look for the object definitions within the new wrapper classes.   Now I just need to add support for flexible layouts and we’ll be laughing.

The Code

Please note – I didn’t rebase the code.  It’s all in the RADE.MGE namespace.  If you would like to use it, feel free to re-base it – or just leave it as is.  Also, if you create any unit tests or enhancements and would like to share them – please feel free!  

As I update the project myself, or receive updates I will update this file.

Finally, the will still work with this new project.  Perhaps one day, I’ll post some fancy new code in C# =)

Hope this comes in handy, I welcome your comments.

July 20, 2010

Mapguide 2011 Javascript error ‘OpenLayers.Lang’ is null or not an object

Filed under: Mapguide — Tags: , — Darrin Maidlow @ 10:33 pm

We’ve finally moved Mapguide Enterprise support back up the list of priorities for =)  The ability to add Google, Yahoo, and Bing data into the map with OpenLayers is very compelling.  So I’ve spent a little time (actually kind of a lot of time)  in the past little bit trying to get my Mapguide development environment setup.   To avoid cross site scripting (xss) errors when developing on my workstation I needed to install the web tier locally.   After muchos problems with license servers and the likes I came across an annoying javascript error whenever I would load a using  the local web tier:

   1: Line: 2
   2: Char: 2498
   3: Error: 'OpenLayers.Lang' is null or not an object
   4: Code: 0

Loading the web tier on the Mapguide server worked fine.  Very odd.  I ended up doing a file comparison between the two web tiers and noticed the only significant difference was this in the web.config:

   1: <staticContent>
   2:     <mimeMap fileExtension=".json" mimeType="application/json" />
   3: </staticContent>

Adding this tag to IIS 7 on Vista resulted in an error, the tag must be something new in IIS 7.5.  However, after manually adding the mime type mapping to the server – my flexible layout now loads perfectly on the local Vista web tier.SNAGHTML15f08bbe

This mime type mapping can be added on either the virtual directory, or the server level.  I chos to add it to the server.  Either way, to add it select the appropriate level in IIS manager.  In the right hand window double click “Mime Types”.  Click Add and you can enter the .json extension and the mime type.  Once this is added, Vista/IIS7 was now properly serving out flexible layers

 

August 6, 2009

Configuring Mapguide Enterprise 2009 and 2010 on the same machine

Filed under: Mapguide — Tags: — Darrin Maidlow @ 1:57 pm

So I’m a little behind on the times.  Yes I’ve finally started making the switch from Mapguide Enterprise 2009 to MGE 2010.   However, I need to keep 2009 around a little bit longer.  This resulted in wanting to configure both 2009 and 2010 on the same server.  Configuring Mapguide enterprise 2009 and 2010 on the same machine is possible, and even beneficial in a development environment.  Less VMs or servers can be a good thing in these days of crazy .  Autodesk however, recommends against doing this in a production environment.   You should probably heed this advice if this Mapguide installation is important – even from a workgroup development point of view.   Note, these steps should be relevant for the Mapguide Open Source equivalents – though I have not tried it.

After installing Mapguide 2010 (both server and web tier) on a server running 2009 and updating the license manager appropriately, you’ll notice that the service is not running.  Attempts to start the service will result in an error message logged in the Windows Application Log that looks a little bit like this:

The description for Event ID ( 0 ) in Source ( MapGuide Enterprise 2010 Server ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Port 2801 is not available, please try using a different port.

So we need to setup one of the Mapguide installations to use a different set of ports.  I’ve chosen to modify the behavior of Mapguide 2010, though these changes could be made for Mapguide 2009 instead.   For this process we’ll need three free ports.  For simplicity its nice to keep these ports sequential.  You will need to ensure that the ports you choose are available on your system.

First we need to edit the serverconfig.ini in the C:\Program Files\Autodesk\MapGuideEnterprise2010\Server\Bin folder.   First lets change the Port in the AdministrativeConnectionProperties section from 2800 to lets say 3800.   Next in the ClientConnectionProperties section change the port to 3801.  Finally change the port in SiteConnectionProperties to 3802.

Next we need to edit the webconfig.ini in the C:\Program Files\Autodesk\MapGuideEnterprise2010\WebServerExtensions folder.  We need to update the port numbers in this config to match the numbers in the server config.  Remember the web config is the client that will usually be consuming the server service.  Finally, as the configuration settings for the web tier may be cached you should restart IIS using iisreset.exe.  This will clear the cached port configurations and Mapguide Studio / Mapguide Administration will now work properly.

Once that is done, the 2009 repository can be migrated to 2010 by following the steps included in the Help/MGE2010UpgradingWindows.htm file on your installation disc/folder.

PHP Problems

Once MGE 2010 has been installed I had a problem with PHP.  Multiple PHPs can be bad news.  I’ve found that running both MGE 2009 and 2010 using the PHP provided with 2010 seems to do the trick.  First you will need to edit the Windows system path.  Update the path variable there to point to the 2010 PHP installation.  If a 2010 path variable exists already – remove the 2009 path.  Next open the IIS manager and ensure that both the MGE 2009 and MGE 2010 virtual directory trees are pointing to the MGE 2010 php extension in the Application Extension Mappings.

Once these changes have been made, do a quick IISreset and you should now be able to login to both the Mapguide admins, as well as have Mapguide Studio connect to the appropriate servers.  Again – this setup could have issues – so consider your environment and needs before configuring a server with both releases of Mapguide.

Remote Web Tiers

If you need to run a shared Mapguide server with web tiers installed on individual development machines don’t forget to set the ports on each development machine.   The Mapguide installer will prompt for the Mapguide server IP address – but the webconfig.ini will need to be updated with the appropriate ports manually.  Not doing do will result in your web tier talking to the 2009 server – and much confusion =)

Finally one note on IP addressees and remote web tiers.  If you plan to use a remote web tier – make sure your Mapguide server is setup using the actual IP address of the server and not 127.0.0.1.  If your Mapguide server is configured with 127.0.0.1, you will get a “Cannot establish connection.” error on the remote web tiers when attempting to create and use a session.  Using real IP addresses (either internal or external) will prevent this error from occurring.

Technorati Tags:

Powered by WordPress

Switch to our mobile site