Vovin.CmcLibNet - A .Net wrapper for the Commence RM API

What is CmcLibNet?

CmcLibNet is an open-source .Net wrapper around the Commence API.

What does it do?

CmcLibNet allows you to make calls to Commence from a .Net environment (such as PowerShell or Visual Studio) without having to talk to the native Commence API directly. It is also 'COM-enabled', so it can be used from COM-capable languages. So you can use CmcLibNet even from Commence Item Detail Form scripts.

Who is it for?

Developers and script-savvy Commence users.

Why did I create it?

As Windows 7 and especially Windows 10 evolved, the de-facto standard of automating tasks has shifted from VBSript to Powershell. And while I think the developers of Powershell deserve a special place in hell (hell, it even ends in 'hell'), I have to admit it is very powerful. Talking to Commence from VBScript is already hard because of Commence's peculiar syntax. From Powershell, it is crazy hard. I wanted an easier way.

Objectives

I created CmcLibNet with the following objectives in mind:

No more DDE!

All DDE methods that Commence (more specifically: the ICommenceConversation interface) exposes are implemented as a simple method; the actual DDE calls to Commence are all handled internally.

Easier filtering

Filtering data using code in Commence is hard. Filter definitions have to be in DDE syntax, which is difficult to master and impossible to remember. With CmcNetLib, you can simply request a particular filter type and you get returned a filter object that exposes only the properties that pertain to that filter type. It is more verbose, but also a lot more user-friendly, especially in development tools that support Intellisense and Autocomplete. If you want to, you can still throw SetFilter and SetLogic at a cursor, but using the Filters collection is easier. A basic example of the idea can be found in the examples.

Easier exporting of data

CmcLibNet allows you to export data in various formats not natively included in Commence, notably Xml, Json and Microsoft Excel. Connected values are not returned as a single delimited string but as individual nodes in Xml and Json. The Cursor object also has an ExportToFile method that allows you to export data from a cursor in a quick and easy way.

Better exporting of data

The built-in export methods provided by Commence are -by far- the fastest. Use them whenever you can. But they are quite limited.

The alternative is reading data via the API. Much slower, but you get more control over what is returned. However, the Commence API is a little sloppy. For example, there is a setting to get data in a consistent (canonical) format, but that does not work on connected items. For example: when you request checkbox values, you get TRUE/FALSE for direct fields, but Yes/No for connected checkbox fields. It's all a little messy.

CmcLibNet takes care of that. CmcLibNet also adds a little more power. For example, unlike the built-in Commence text-export, you can specify text-qualifiers and delimiters as well as export connected values other than the Name field. Its Xml and Json exports are prettty decent. They will return connected items as distinct objects instead of hard-to-process delimited string values.

Connected values and the Commence API deserve a book on their own, but as long as you have a decent-sized database, CmcLibNet will do a decent job of handling connected data. You can play around with the NumRows and MaxFieldSize parameter, use the 'PreserveAllConnections' option, or use the nuclear option: UseDDE (tip: you do not want that).

Exporting to Excel does not require that Excel is installed.

Scripting and COM

You can use CmcNetLib from scripting, most importantly of course Commence Item Detail Form scripts. While CmcNetLib is primarily intended for use from .Net assemblies, I made CmcNetLib support 'COM Interop'. Which is a complex way of saying you can use it in Commence scripting or any COM-capable language.

Important: if you intend to use CmcLibNet via COM, pay special attention to the Close() methods of the COM-creatable classes.

Limitations

Maturity and stability

CmcLibNet will probably never leave beta-status. It has barely been tested 'in the wild'. You are encouraged to try it out and send me feedback when something goes wrong.

Download installer

The installer supports Full, Compact and Custom install modes. Compact mode will get you just the single DLL for use in you .Net project or PowerShell script, nothing else. COM Interop registration is optional.

Package

The assembly is available on NuGet.

The only difference between the NuGet package and the installer is that the installer will put the files in a standard location and (optionally) register them for COM-Interop.

Source

Examples

For examples see the documentation.

System requirements

Support

CmcLibNet is free software. I do not provide support but I welcome feedback, you can send it to cmclibnet@!NOSPAM!vovin.nl. Remove the '!NOSPAM!' part.

Background information

The installer was created with Inno Setup.

The installer installs the following files:

What the installer (optinally) does:

  1. Detect if Commence RM 6.1 or higher is installed.
  2. Detect if .NET Framework 4.7.2 is installed. If not, it will try to install it .
  3. Create a directory %ProgramFiles%\Vovin\Vovin.CmcLibNet\ and put the files there.
  4. (Only if 'Register for COM Interop' is checked.) Register Vovin.CmcLibNet.dll using regasm (part of the .NET Framework) to make the assembly available to COM-enabled languages, such as Commence Item Detail Form Scripting. This is why the installer requires Administrator privileges. This will create an additional file called file Vovin.CmcLibNet.tlb.

The assembly is not added to the Global Assemby Cache, so you have to reference the DLL manually if you are using a .Net environment such as Powershell. This is by design.

Upon uninstall, no files or registry entries should be left (unless you install newer versions over existing ones, haven't figured that scenario out yet.).

If it doesn't do all this, let me know.

Documentation

The API reference and some examples to get you started can be found here.

Known issues

Comparison with other tools

There aren't many tools comparible with CmcLibNet. I know of none that explicitly target the .Net world. There is Dumont, which is a great open-source C++ tool offering a transparent wrapper around the Commence API, but it is not .Net and is no longer actively maintained.

As for exporting Commence data, there are two competing tools worth mentioning. Memocom has developed MemoDLL, an all-purpose DLL allowing all kinds of nice stuff with Commence data. A very powerful and versatile tool. MemoDLL offers some exporting methods very similar to those in CmcLibNet, such as exporting a View.

They also created MemoExport, a standalone tool specifically developed for exporting Commence data. I find MemoExport very hard and unforgiving to use, but it has much more options than CmcLibNet.

However, both Memocom tools are legacy VB6 applications and are not open-source. And while powerful, MemoExport in particular is quite slow.

Some key differences:

Useful links