January 11, 2013

A .NET-based user interface for MATLAB applications

Filed under: Development — Tags: , , , — Arne Joris @ 6:58 pm

logo_matlab MATLAB is a numerical computing environment for engineering applications. It supports communicating with and controlling hardware and processing and visualizing data from that hardware, which makes it a very popular platform for writing the software that goes with custom hardware solutions.  It also supports creating user interfaces too, but they tend to look outdated and clunky. matlabGUI_example1a

For example, the control and display software for your custom pump controller system can easily be written in MATLAB. It would run on a PC that is connected to your hardware, lets the user turn the system on and off, set parameters such as pump cycle delays and display graphs showing overall efficiency or total energy input. You can compile all the MATLAB code and sell it, along with your hardware and the MATLAB compiler runtime, as a product.

But what are your options when you want a sleeker, more modern UI with a ribbon bar, interactive graphs and UI themes or skins?  The most economic solution with a relatively short time-to-market, is to create a .NET based UI which connects to your MATLAB functions. In this article, I’ll elaborate on how exactly this works.

(more…)

August 13, 2012

Unique number counter system using SQL Server identity fields and Fluent NHibernate

Filed under: Development,NHibernate,SQL Server — Tags: , , — Darrin Maidlow @ 6:00 am

**UPDATE – As we moved forward with our project this method turned out to be a little less awesome than I thought when I put it together.   I’ve left this post here though as I am not ashamed of my failures! There is also some neat stuff in here with setting up the identity fields using nHibernate.

Recently I needed to create a generic re-usable system to generate system wide unique counters using SQL server tables and identity fields to handle the number generation.  One of the key requirements was to be able to specify the identity seed, but in a re-usable way of course.

Generic Class and Class Map

So lets start this off with a base class to define the counter object:

(more…)

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.

November 2, 2011

Remotesoft Protector Runtime Error – yet to handle multiple .NET framework runtime

Filed under: Development — Tags: , , — Darrin Maidlow @ 9:07 pm

Remotesoft protector is one of the out there.  In fact, its pretty much the only one that really works.  Since I moved to .NET 4.0 I’ve been getting an annoying error when attempting to protect my binaries using the 4.0 suite of tools (with the ).  Everything still runs – it just pops up nasty alert boxes on load which is no good :)

Remotesoft Protector Runtime Error – yet to handle multiple .NET framework runtime

One other symptom of this was that .exe files would just blow chunks.  I’ve finally figured out what was causing this!  Most of our products are protected during the nightly builds.  This error however is specific to assemblies protected using the the Remotesoft .NET Explorer UI.  When using this application for the protect or obfuscate functionality it is really just a front end around the protector.exe/obfuscator.exe.  The UI is building the following command line string and tonight it finally dawned on me:Remotesoft .NET Explorer

Command: C:\Program Files (x86)\Remotesoft\Protector\bin\protector.exe -neutral -resource -string -cctor -clrversion v2.0.50727 "C:\temp\SmartInk for Kahua\SmartInk.UI.exe"

The UI was forcing the clr version to .NET 2.0 – when my assemblies are all built against .NET 4.0.  Oops…

After a bit of digging I found that you can set the CLR version in .NET Explorer from the Action / CLR Version menu item.  Unfortunately it has not been updated to support .NET 4.0 – and so has been rendered pretty much useless as a front end for protector.

The Fix

The only solution is to use the command line to execute your protection.   The updated command line ended up looking pretty similar:

"C:\Program Files (x86)\Remotesoft\Protector\bin\protector.exe" -neutral -resource -string  -clrversion v4.0.30319 "C:\temp\SmartInk for Kahua\SmartInk.UI.exe"

There you have it – I can’t believe I missed that…

November 6, 2010

ERROR: Unable to update the dependencies of the project

Filed under: Development — Tags: , , — Darrin Maidlow @ 11:22 pm

Working on the automated build process for FullCircle SmartForms tonight and I came across an irritating problem tonight:

"ERROR: Unable to update the dependencies of the project. The dependencies for the object ‘NHibernate.Validator.DLL’ cannot be determined."

One of my three Visual Studio 2010 installer projects started failing during the automated build process with this error on a dozen included assemblies.  When the project was built using the Visual Studio IDE the installer would build just fine.  With a little bit of digging and a great deal of screwing around, I found a and for this problem.

After installing the patch – my automated build system is happily compiling the installation project.

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.

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 12, 2010

Visual Studio 2010 and .NET 4.0 Full available on MSDN!

Filed under: Development — Tags: , — Darrin Maidlow @ 10:06 am

MSDN has been updated with the full releases of VS 2010 and .NET 4.0.  Getting some decent download speeds too..

http://msdn.microsoft.com

wooo!

Visual Studio 2010, .NET 4.0, AND ReSharper 5.0 launch today!

Filed under: Development — Tags: , , — Darrin Maidlow @ 8:32 am

I may be weird, but I actually went to bed excited last night.  VS 2010, .NET 4.0, AND are supposed to be released today.   For the first time in probably months I got out of bed at 7am -  It’s now 7:30 Redmond time – but MSDN has not yet been updated!  Apparently we have to wait until 8:30 Redmond time.   Adobe is all over their release of CS5 today, and they didn’t make their users wait until 8:30 Redmond time! =)

In the meantime, The Register has a good write up on some of the coming in an hour or so.  That will learn me for getting up early.  Oh well, time for another !

November 24, 2008

.NET 3.5 “Attempted to read or write protected memory” Caused by Remotesoft Protector

Filed under: Development — Tags: , — Darrin Maidlow @ 11:25 pm

Months ago, I started getting the “Attempted to read or write protected memory” error.  In hindsight (as always) its all clear.  In short, it seems .NET 3.5 SP1 and v2.x do not play nicely resulting in this error.  Either stop using Protector, or upgrade to the latest version.

In long – for a number of reasons there was not a strait line between upgrading my machine to SP1 and noticing the problem.  This made diagnosing the problem significantly more complicated because I had no idea when it actually started.  At the time, I was dealing with .  This had prompted me to start doing all my dev in an XP virtual machine.  Eventually, the slowless of developing in a VM drove me insane and I just had to get my machine working again.  So I got Oracle dealt with – but that left this annoying error.

It was a complete fluke that I noticed this.  The stars aligned, and I manually compiled some assemblies, instead of pushing the big green button on my build system.  This resulted in my assemblies not being run through the Remotesoft Protector.  All of a sudden the problem went away.  At the time I had been using Protector 2.x which would not support .NET 3.5 SP1 fully. So, either stop using Protector, or upgrade to the latest version which resolves this problem =)

Older Posts »

Powered by WordPress

Switch to our mobile site