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

 

July 9, 2010

A breakthrough in the war on phone spam

Filed under: General — Tags: — Darrin Maidlow @ 2:22 pm

One of the things that absolutely drives me insane is phone spam.  Nothing like being deep in concentration inside some algorithm and have the damn phone ring with a phone spammer on the line.  A lot of days, I’ll just turn off all the phones in an effort to get shit done… I’m on both the US and Canadian “Do Not Call” lists.  I report every single unsolicited call, yet they keep on coming…

Came across this blog post today detailing an .  They’re turning the tides on phone spammers.   There are some hilarious mp3’s on the site where you can hear the “conversation” between the honey pot and one of the “moron” phone spammers.  They’re keeping some of these calls on the line for 4+ minutes.  Totally awesome.

I hope someone can take initiative and setup something similar in North America.  If I had the resources I would take this on in a heartbeat…

Hats off to you guys.. =)

June 7, 2010

Effortlessly map domain and DTO entities

Filed under: Development — Tags: , — Darrin Maidlow @ 10:19 pm

I recently created a set of objects to complement the domain entities we use for our data access layer for a new project we’re working on.  I immediately set out to write a mapping utility.  After a bit of thought pondering the complexity of the problem I decided to look around on the magical internets to see what options were available.

Came across .   This is a perfect match for my needs:

AutoMapper uses a fluent configuration API to define an object-object mapping strategy.   AutoMapper uses a convention-based matching algorithm to match up source to destination values. Currently, AutoMapper is geared towards model projection scenarios to flatten complex object models to DTOs and other simple objects, whose design is better suited for serialization, communication, messaging, or simply an anti-corruption layer between the domain and application layer.

It was quick to setup, and painless to use.  First define your object to object mappings:

   1: Mapper.CreateMap<RADE.BO.Domain.Application, RADE.BO.Entity.Application>();

 
Next, whip up a small conversion function:
   1: /// <summary>
   2: /// Convert a DTOApplication to abnd 
   3: /// </summary>
   4: /// <param name="app"></param>
   5: /// <returns></returns>
   6: public static RADE.BO.Domain.Application Convert(Application app)
   7: {
   8:   if (app == null) return null;
   9:   LoadDtoMappings();
  10:   return AutoMapper.Mapper.Map<Application, RADE.BO.Domain.Application>(app);
  11: }
  12:  
  13: /// <summary>
  14: /// Convert a list of domain Application objects to DTO Application objects
  15: /// </summary>
  16: /// <param name="apps">List of domain Application objects</param>
  17: /// <returns>List of DTO Application objects</returns>
  18: public static List<Application> Convert(List<RADE.BO.Domain.Application> apps)
  19: {
  20:     LoadDtoMappings();
  21:     return apps.Select(AutoMapper.Mapper.Map<RADE.BO.Domain.Application, Application>).ToList();
  22: }

It’s important to note that if your source object contains nested objects – a mapping for each nested object must also be defined.  This goes on recursively through nested objects.  My domain Application object contains some numerous sub objects – Map, Layer etc.  In this case rather than establish mappings for these child objects – I removed these objects from my DTO as the client consuming these objects would never need that data.  This also keeps the size of any data possibly being serialized down.   Automapper dealt with this automatically.

I’ve only scratched the surface of what Automapper can do.  Next step is to define unit test coverage using the , but it’s sleep time now… =)

April 28, 2010

Please be specific when talking to your developers

Filed under: General — Tags: — Darrin Maidlow @ 4:46 pm

In the tabular reports we have the ability to format the output of a column using a standard String.Format syntax.   This is used often in the reports to convert string data containing URLs to clickable links when the page is rendered:

   1: "<a href=”{0}” target=”_blank”>{0}</a>"

This format string of course when applied to the source data would result in a hyperlink being created with the URL in both the href property of the link as well as the  visible link text.  called and asked if it would be possible to change the report so that it showed simply the word “View” instead of the url.  We already had a remote control session running so I opened up his RADE and changed the format string to:

   1: "<a href=”{0}” target=”_blank”>View</a>"

He saw this small change and I heard him slap his forehead, and he asked “Why didn’t you tell me this sooner, I’ve wanted to do this forever!”.  To this I responded “You never asked…”

So the moral of this story is directed to managers, sales types, or any other person who works with software developers.   We’re incredibly smart, and there is far too much good stuff inside our heads for us to just “tell you everything”.  If we were to try, you would either fall asleep or your head would pop.   So please, rather than expect us to tell you what you want to know – just ask. =)

April 26, 2010

No catapults allowed in carry-on or checked luggage

Filed under: General — Tags: — Darrin Maidlow @ 8:20 am

In preparation for our vacation to Costa Rica I was reviewing the Canadian government’s list of  items that in your carry-on or checked luggage.  I was shocked to find out that catapults are not allowed in either your carry on or checked luggage!  Catapults are so bad, they’ve made the list twice!

catapults need not apply

slingshots and catapults forbidden!

Other honorable mentions include:

  • Hand Grenades
  • Molotov Cocktails
  • Nitroglycerin (this is OK when in medication format)

If you’re planning some air travel in the near future – leave your catapult at home!  Maple Syrup and spread is completely OK though!

maple products

April 23, 2010

Who owns the most servers

Filed under: General — Tags: — Darrin Maidlow @ 2:49 pm

Did you think you’d see Google on this?  Scroll down…

WhoOwnsTheMostServers

April 22, 2010

Visual Studio 2010 keyboard shortcut posters

Filed under: General — Tags: — Darrin Maidlow @ 10:53 am

Using keyboard shortcuts will speed up your development big time once you get used to them.  Microsoft released charts for VB, C#,  F# and C++ 2010.   They print OK on 8.5×11 (not great).  Sucks that Microsoft put scary stock imagery on the sheets though.  These shortcuts are only partially accurate if you’re using ReSharper, here is a – and look, no scary stock imagery in this one.

April 16, 2010

Windows Vista won’t let me browse my iPhone when I plug it in

Filed under: General — Tags: — Darrin Maidlow @ 8:18 am

I was trying to get some images off my iPhone this morning, but the thing wouldn’t show up in Windows explorer.   ITunes was doing the backup and sync no problem – but the phone would not mount as a usb device.  Usually the phone shows up in explorer under the Computer section as “Apple iPhone”.  Unplugging and reconnecting the thing would just cause a re-sync.

After much mucking around the best solution I could find was to disconnect the iPhone from the usb cable, start the windows Device Manager and un-install the Apple iPhone driver from the Portable Devices section of the devices.  Make sure you check the delete driver checkbox.  Finally, re-connect your iPhone and the driver should re-install allowing you to see your device in Windows Explorer again.

No images on device

So now I can see my phone in Vista – but when I browse to the device the internal storage folders are empty.  There are tons of images in the “Camera Roll” when looking at the phone.  After much more muckery – I found one image that was saved from the interwebs rather than taken with the phones’ camera.  Once I deleted this image, and reconnected the phone all the images showed up no problem.

April 15, 2010

Deployment project crashes on execution with .NET version error

Filed under: Development — Tags: — Darrin Maidlow @ 2:47 pm

This week I jumped on the bandwagon.  I had a proof of concept project that I wanted to bring up to the “real product” level.   This new product consists of a console application, a windows service, and some business logic and data access assemblies.  During the development of my proof I created a small deployment project to build a quick and dirty installer.  

I’ve upgraded the solution to 2010.  I’ve done all the refactoring and finished my work.  Everything tests out great in both unit tests and “developers computer” tests.  Just need to get the installer updated and get the pesky “other peoples computers” thing out of the way. 

I’ve updated the pre-requisites on my installer to include .NET 4.0 – rebuilt the installer and boom. 

Error 1001.  Exception occurred while initializing the installation.  System.BadImageFormatException: Could not load file or assembly ‘file:///C:\Program Files\Landor\ … \RADE.Connect.Service.exe’ or one of its dependencies.  This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

After much mucking around I found the hidden property that I needed to change.  I needed to change the .NET version of the .NET Launch Condition.  To find this gem right click on the deployment project in the solution explorer and choose View\Launch Conditions.  Next right click on the “.NET Framework” under “Launch Conditions” and choose “properties”.  In the properties dialog change the Version to be “.NET Framework 4”.

Update 4/20/2010

Don’t forget to edit the .NET version for both Release and Debug configurations.

Older Posts »

Powered by WordPress