Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack.

This is an inner exception that you may encounter with Crystal Reports, now it sounds rather bad, but its really just a badly named error – don’t panic (just yet anyway)!

.
Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack.
.

More than likely it is caused because the reporting engine can’t load your report due to a spelling error in the report name or an incorrect path to the report file.

In my case the problem arose because the report was defined in a different project to where it was displayed, so I just added a post build step to one of the projects so that the report file (.rpt) was copied to the output bin directory on a successful build, and its all ok now!

Crystal Reports in WPF, which references do I need to add to my project?

In this software development game it can be hard to avoid developing reports, I haven’t had the need to use CrystalReports in many along year, but last year I had the misfortune of using Microsoft’s shoddy reporting services for a client and decided after that that I would try at all to avoid a repeat of the experience!

So here I am with SAP’s shiny Crystal Reports, so far so good, except for some slightly worrying bitness problems, I am developing on Windows 7 64bit targeting x86 and found that I _sometimes_ had to set my project’s build target to x86 (from AnyCPU) to avoid getting exceptions thrown like this:

.
The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception
.

With an inner exception like this:

.
Retrieving the COM class factory for component with CLSID {4DB2E2BB-78E6-4AEA-BEFB-FDAAB610FD1B}
   failed due to the following error: 80040154 Class not registered...
.

Anyway back to the point of the post:

Which references need to be included in my WPF project?

There are millions of them to choose from and I hate having to add them all if I know they are not all required, so here’s what I found that you need at a minimum:

.
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.ReportSource
CrystalDecisions.Shared
SAPBusinessObjects.WPF.Viewer
SAPBusinessObjects.WPF.ViewerShared
.

WPF / XAML: Binding ComboBox directly to enum values

This is a note to remind me how to bind a xaml combo box directly to an enum property defined in the ViewModel. This is handy if the ComboBox values for display match exactly those defined in the backing enum.

So imaging that we have an enum defined as follows:

public enum UserType
{
    Tester,
    Engineer
}

Now imagine that we want to include a ComboBox in our view that allows the selection of these enum values and whose SelectedValue property binds with a property of our view model, in xaml terms:


So we need to add a property to our ViewModel called UserTypes that will enumerate our enum’s values so that they can be displayed in the combo box. We also need a property called UserType that will bind to the ComboBox’s selected value like this:

//
public IList UserTypes
{
    get
    {
        // Will result in a list like {"Tester", "Engineer"}
        return Enum.GetValues(typeof(UserType)).Cast().ToList();
    }
}
public UserType UserType
{
	get;
	set;
}
//

And that should do it…. But knowing WPF and XAML you will probably end up fighting with it for a good few hours! ;-)

Compiling / Building libJpeg for Windows

Here is a record of how I managed to build libJpeg for Windows, Visual Studio 2012:

1.) Download & unzip the source, I downloaded it from here:

http://sourceforge.net/projects/libjpeg/files/latest/download?source=files

2.) Launch the Visual Studio Command console. To launch it, search for ‘command’ in the start menu, and you should see something like ‘Developer Command Prompt for VS2012’, start this.

3.) in the command prompt cd to the directory in which the libJpeg source resides

4.) At the command prompt, run the following commands:

 
set INCLUDE=%INCLUDE%;c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
copy jconfig.vc jconfig.h
copy makelib.ds jpeg.mak
copy makeapps.ds apps.mak
nmake /f makefile.vc  nodebug=1 libjpeg.lib
 

In the first command make sure to replace the path with your path to your installation of the windows SDK, you may have to look around for this… If you get an error like this:

.
makefile.vc(11) : fatal error U1052: file 'win32.mak' not found
.

Then you haven’t correctly specified the SDK path.

When the compile finishes you should see libjpeg.lib in the top folder.

.

Building snappy compression library on windows with Visual Studio 2012

Snappy is a little fast software compression library by google. It eschews high compression rates for speed, it is very easy to use. Building it on windows for use with visual studio etc. is relatively straight-forward due to this github project by kmanley which provides it with a visual studio solution.

https://github.com/kmanley/snappy-msvc

To build the snappy static libraries, follow the instructions on the github page (README.rst).

If you get a build error like this:

.
Error	15	error C2061: syntax error : identifier 'ssize_t'
.

Then copy the following code and place it at the top of the snappy.h header file (say, after #define UTIL_SNAPPY_SNAPPY_H__):

//
#include 
typedef SSIZE_T ssize_t;
//

Once it has built, snappy.lib can be found in the Debug or Release folders, note that the debug build of the snappy lib is very slow so don’t do any tome testing with it! The release build screams along!

To use snappy in your C/C++ project you will need to #include “snappy.h” (which in-turn uses “snappy-stubs-public.h”) and also add snappy.lib to your project. Here is a little silly example:

//
#include 
#include "snappy.h"
void test_compress() {
	std::string in("This is not a very long string at all!!!  So the compressed output may be larger than its size, but don't worry it will work well for longer things");
	printf("Abut to compress string (size is %d)\n", in.size());
	// 
	// Compress the string...
	//
	std::string out;
	auto comp_size = snappy::Compress(in.c_str(), in.size(), &out);
	
	printf("Compressed size is %d\n", comp_size);
	//
	// Uncompress it..
	//
	std::string plain;
	snappy::Uncompress(out.data(), comp_size, &plain);
	printf("Un-compressed size is %d\n", plain.size());
	printf(plain.c_str());
}
//

If you get an error like this when you try to compile your client code:

.
Error	1	error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' 
.

Then it means you are trying to use the debug version of snappy.lib in a release build or vice versa, use the correct version and the error should go away….

Many thanks to kmanley!

Have a WPF application remember its size and position between runs

Sometime software development is all about doing the same things over and over again! I keep on forgetting how to get a windows application to remember it size and position in between runs, and I keep on re-finding this handy post that describes how it’s done:

http://stackoverflow.com/questions/847752/net-wpf-remember-window-size-between-sessions

The first answer always works like a charm – copy and paste city! ;-)

Thanks ChrisF!

thecorknews.ie wins Best Online Publication at the Irish Web Awards 2014

irish_web_awards_winner
We were very pleased to hear the thecorknews.ie won the ‘Best Online Publication’ award at the 2014 Irish Web Awards yesterday. Congratulations to The Cork News team!

We are especially proud as we helped Pride Design build the site some years ago. It was technically quite a challenging website to build but as always Drupal was up to the job!

Which OpenCV libraries do I need for VideoWriter ?

I am currently testing some video encoding times for a computer vision project that I am working on using the OpenCV video functionality in windows. I hate wrestling with all of the OpenCV library files, but to use VideoWriter you just need to use the following libs:

opencv_coreXXX.lib
opencv_highguiXXX.lib

Where XXX is the version number of the libs that you are using, so for example on the software project that I am currently working on, I need to include:

opencv_core246.lib
opencv_highgui246.lib

You will need to have the corresponding .dll files on your path as well to run your program.

Nasty Drupal 7 SQL injection vunerability

The register reported today about a nasty SQl injection vulnerability in Drupal 7 (in the Database abstraction API):

http://www.theregister.co.uk/2014/10/16/drupal_megavuln_sql_injection/

Better upgrade to 7.32!

Send event to intercom.ie – example python code

So as mentioned in a previous post I have been doing some python software work to integrate a client’s could application with intercom.io. The intercom REST interface is nicely designed and quite straightforward to use.

Applications send events to their intercom account (with optional event data) when their users do interesting things, intercom can be configured with rules so that messages are automatically sent in response to a particular combination of events.

It is a nice idea that shows great potential, however the intercom rules engine is quite limited and probably needs quite a bit of work before it is really useful, for example, at the time of writing, it is not possible to include any of the event data as part of the decision process of a rule.

Anyway to post an event to intercom.io you do an HTTP POST to /events passing some data, including: the event name, the user’s email address a time-stamp. You can also send optional data that will be stored with the event (but which can’t bu used as part of a messaging rule).

The following code defines a function called raise_event() which can be used like this:

raise_event('project_created', email_address,
		{'project_id': id, 'project_name':name})

This raises an event named ‘project_created’ with some extra data: project id and project name.

import httplib
import json
APP_ID = 'Place your App Id here'
API_KEY = 'Place your API key here'
API_URL_STUB = 'api.intercom.io'

def raise_event(name, user_email, extra_data = None):
 
	return _api_post('events',
			 {'event_name': name,
			  'created_at':_timestamp(),
			  'user_id': user_email,
			  'email': user_email,
			  'metadata': extra_data,
					 }
	)
def _api_post(endpoint, data):
    userAndPass = b64encode(b'%s:%s' % (APP_ID, API_KEY)).decode("ascii")
    headers = {"content-type": 'application/json', 'Authorization' : 'Basic %s' %  userAndPass}
    h = httplib.HTTPSConnection(API_URL_STUB)
    url = '/%s' % endpoint
    h.request('POST', url, body=json.dumps(data), headers=headers)
    response = h.getresponse()
def _timestamp():
    now = datetime.now()
    return long(time.mktime(now.timetuple()))

Of course this is all very interesting but for a real python API wrapper you should probably checkout python-intercom here:

https://pypi.python.org/pypi/python-intercom