February 18, 2013

Enum: the ‘simple’ C# value type we love to complicate

Filed under: Development — Tags: , , , , , — Arne Joris @ 12:20 pm

Enums are simple collections of constant values, using an underlying integer to store the value.  Enums implement IComparable, IFormattable and IConvertible while still being value types and give us everything we need to store and use things like status values, action codes, colours etc…

You can use enum values in both server and client code, but when the user interface displays an enum, or when the user must be able to choose enums from a combobox, we can run into complications with enums. Making enum display values more human readable and showing values in a particular order are not that easy to implement. In this article, I will show you a solution used in a WPF client consuming WCF web services.

(more…)

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…)

December 17, 2012

Are you a pointy haired software manager?

Filed under: Development — Tags: , — Arne Joris @ 4:11 pm

Ah, managers… We all love to hate management, until of course we join its ranks. Then we like to think we are different from those other pointy haired types, but we fail to see the evidence to the contrary.

If you recognise some of your own behaviour in the anti-patterns in this article, it is time to re-evaluate! Admitting you are a pointy haired boss is the first step toward better management.

(more…)

November 16, 2012

SCRUM: beyond better software

Filed under: Development,Small Business — Tags: , , — Arne Joris @ 6:24 pm

Agile software development has been picking up steam in the last couple of years and especially SCRUM has become a very popular development methodology. SCRUM can produce better results for complex projects and the internet is full of helpful tips on how to tailor it to specific project types, team structures or industries.

I have been using SCRUM for several years now,  in both large and small environments and found that there are  non-technical benefits from the SCRUM process that can have a positive impact on your business. Benefits such as effective customer engagement, timely customer payments and better estimates should be of interest to everyone in the software development business. Small companies may benefit the most because the link between a developer’s pay cheque and customer happiness is obvious and there can be direct contact between end user and developers.

(more…)

November 2, 2012

Visual Studio running slow? Check your Anti-virus

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

TurtleFor several weeks now I’ve been suffering a slow painful agony at work,  has been unusably slow.  The editor takes forever to display WPF views and don’t even get me started on builds.  I’ve got what I would consider to be a pretty decent pooter – Alienware M17xR3 with an Intel i7-2720QM 2.2Ghz, 16GB ram with SSD drives.   The machine is still generally pretty quick.  It boots in a matter of seconds.  A quick test of the disks using shows that disks are running within the expected ranges.

Visual Studio seems to be the only thing really running slowly

I tried the usual suspects.  Disabling all plugins and addins.  is a very powerful tool – but it can also come with a cost creating all of its metadata.  It was conceivable that as our solution grew (it’s at 40+ projects) some bug may have been exposed in R#.  I  also and that were rumored to help deal with slowness.

There’s no bad ideas when you’re brainstorming

That header there was for those of you with toddlers and TV’s glued to the Disney channel.  Yes, its true… I have kids TV show songs like stuck in my head most o f the time now.  Oh the joys of being a parent =)  In all seriousness though after sitting back and thinking about the systems involved it dawned on me.  Real time anti-virus scanning.  Visual Studio is constantly writing temporary files during use.  Builds are especially disk intensive.  Builds are also usually building and copying around exes and dlls that real time anti-virus engines love to scan.  This may not be immediately apparent on smaller solutions which would explain why this seems to have been a progressing problem.  As more and more code and projects were added to the solution – Visual Studio got slower and slower.   To test this theory I just disabled and ran a build.  Hurray it was fast again!

Add some scanning exceptions

Thankfully due to our strict rules on source control all of our solutions exist within one of two folders – one for and one for .  This allowed me to create a handful of exceptions under the AVG real-time scanner settings that excluded my source control repositories.  Suddenly now my designers as well as my builds are quick once more!

Set it and forget it is great – except when you set something up years ago and forget about it when its causing you problems.  =)

October 26, 2012

WPF style resources bug causes stack overflow in .NET 3.5

Filed under: Development — Tags: , , — Arne Joris @ 8:12 am

XAML logo We recently re-wrote an AutoCAD 2010 application to be entirely based on .NET.  Our application was using Windows Presentation Foundation for the presentation layer, which lets you nicely separate presentation from business logic using the MVVM pattern.  Since this application also had to run in AutoCAD 2009, it had to use the .NET 3.5 version.

It turns out there is a bug in .NET 3.5 (fixed in 4.0) that causes a stack overflow exception when you define two or more default style resources for the same type at the same level.  If you use global resource files and window-specific default styles, you may run into this and its not at all obvious what the problem (or the solution) is.

(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…)

January 13, 2012

Using Log4Net with Visual Lisp

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

If you’ve worked with me or talked technical with me in the past there is a good chance you area already very aware that I love .  There is also a really good chance that you know I still have a special place in my heart for .  Not only did I spend what may have been the “best years of my life” buried in VLIDE (or hey, maybe all those 30+ hour days and passing out under my desk were the best years of my life? =)) , I still firmly believe that Lisp is one of the most effective way to bang out even a relatively complex operation in AutoCAD when it comes to data manipulation.  ObjectARX (both original and .NET) is great – but the time and effort overhead is pretty high when you just need to bang out a quick routine.

<3 Visual Lisp

Even the quick routines need a little error handling and logging can make a huge difference in documenting the results or diagnosing problems.  Keep Reading

November 8, 2011

OracleCommand and parameterized update statements

Filed under: Development,Oracle,RADE — Tags: , , , , — Darrin Maidlow @ 4:07 pm

This week I encountered an irritating situation with Oracle while working on code in the application logic.  In a nutshell I am building dynamically created parameterized insert and update statements based on the RADE metadata and the values entered by the user.  The first call InsertNewRecord works perfectly.  The next call UpdateExistingRecord however was not.  The parameterized SQL was being created.  The parameters were being created and assigned to the .  The ExecuteNonQuery() call was executing without returning an error.  Oracle just would not update.   Even more frustrating – this “just worked” in SQL server.

What were the differences?

The basic logic for insert was this (parts omitted because you probably just don’t care):

  1. Get table metadata
  2. Loop through fields in table
  3. for each field retrieve the value from the UI
  4. Add field to parameterized SQL statement with placeholder
  5. Create new parameter with appropriate name and value.   Add parameter to collection
  6. Loop through parameters in the collection and add to the DbCommand
  7. Finally execute the parameterized SQL statement

As I mentioned this worked great.  Fields were inserted and there was much rejoicing.

The logic for an update was similar but there was one big difference:

  1. Get Table
  2. Loop through fields in table
  3. for each field retrieve the value from the UI
  4. If the field is a key add the placeholder to the where condition, otherwise add the field name and value to the update fields part of the SQL
  5. Create new parameter with appropriate name and value.  Add parameter to collection
  6. Loop through parameters in the collection and add to the DbCommand
  7. Finally execute the parameterized SQL statement.

The branch in step 4 and the if statement ended up causing the problem.

The Problem

defaults to “bind by order” – making the order in which the parameters exist in the SQL statement match the order in which the parameters are added to the OracleCommand. This was happening during the insert because of the structure of an insert statement being so linear. However in the update statement I was building the SQL in a more dynamic way. I was maintaining a list field=value conditions and a separate where condition. In the ended up merging them :

   1: String parameterizedSQL = "UPDATE " + table.Name + " SET " + updateStatement + " WHERE " + whereStatement;

So unless my key field( s) all lined up at the end of the table metadata definitions,  appending that where condition at the end my parameter order got all out of whack in the DbCommand.  So my where condition was actually being set to the wrong value – which could have resulted in the wrong records being updated. Nasty.   Fortunately this can be resolved.

The Fix – BindByName=true

To correct this I had to set the Oracle specific BindByName property to true.  (btw this being the default behavior is just silly.  All the other big data providers default to bind by name and Oracle should too.  That’s a rant for another day though.)   My initial solution was to check if the command is an OracleCommand and if found do a little casting to set the BindByName property then recast it back to DbCommand before executing the query.  Constructive feedback is always welcome!

   1: /// <summary>
   2: /// Execute the parameterized query
   3: /// </summary>
   4: /// <param name="conn">open and active DbConnection</param>
   5: /// <param name="trans">Active DbTransaction</param>
   6: /// <param name="parameterizedSQL">the parameterized SQL</param>
   7: /// <param name="paramList">List of OledDbParameter</param>
   8: /// <returns>DataTable containing the results</returns>
   9: public static void RunParameterizedInsertUpdate(DbConnection conn, DbTransaction trans, String parameterizedSQL, List<DbParameter> paramList)
  10: {
  11:     //create the db command and set the parameterized SQL as a property
  12:     DbCommand command = conn.CreateCommand();
  13:     if(trans != null)
  14:     {
  15:         command.Transaction = trans;
  16:     }
  17:     //hack attack!  By default, Oracle requires its parameters to be placed into the command
  18:     //in the order the parameters appear in the parameterized SQL.  Little hackery here
  19:     //to set the Oracle Command to bind by name
  20:     if (command is Oracle.DataAccess.Client.OracleCommand)
  21:     {
  22:         OracleCommand oraCmd = (OracleCommand) command;
  23:         oraCmd.BindByName = true;
  24:         command = oraCmd;
  25:     }
  26:     command.CommandText = parameterizedSQL;
  27:     command.CommandType = CommandType.Text;
  28:  
  29:     //loop through the params and add them to the command
  30:     foreach (DbParameter parameter in paramList)
  31:     {
  32:         command.Parameters.Add(parameter);
  33:     }
  34:     try
  35:     {
  36:         command.Prepare();
  37:         command.ExecuteNonQuery();
  38:     }
  39:     catch (Exception ex)
  40:     {
  41:         command.Dispose();
  42:         throw;
  43:     }
  44: }

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.

Older Posts »

Powered by WordPress

Switch to our mobile site