Ideablade Cocktail for Windows Store – Part 1

Ideablade is currently offering licenses to Windows Store version for free. The Dev_Tour sample shows how a basic DevForce is set up. However, there is scant documentation on how to create a Windows Store application that runs on top of the Ideablade Cocktail framework.

There are two Windows Store samples bundled with Cocktail – the Todo and the NavSample. The best place to start is the NavSample project. The Todo sample is a little too simplistic to learn much from.

Create Windows Store Application

Create a blank Windows Store Application using the Grid app as a base, and we will call it AssignmentTracker.RT and the solution is named sans the RT suffix. Assignment Tracker allows teachers to assign homework to students. It is not very different from a Todo list conceptually. The reason we add RT to the project is because, one day, we might wish to develop a desktop version.

However, we don’t want the created assemblies to have the .RT suffix. So, go into Project Properties and set accordingly.

Add packages via NuGet

After you create a blank Windows Store application in Visual Studio, add the following packages via NuGet:

  1. IdeaBlade.Cocktail
  2. IdeaBlade.Cocktail.Utils
  3. IdeaBlade.DevForce.Core
  4. Microsoft.Composition


The first thing that strikes any seasoned Caliburn.Micro user is that there is no Bootstrapper class in Caliburn.Micro.RT. This is because the Windows Store application provides a base Application class that you must override to get events. I was somewhat dismayed at Microsoft for doing this. WPF, Silverlight and Windows Phone all had one startup model and WinRT comes along and insists on another.

On the other hand, the people at Caliburn.Micro had done a pretty decent job of abstracting over this. There are two base classes provided – CocktailMefWindowsStoreApplication and CocktailWindowsStoreApplication, and they behave in the same way as the bootstrapper, all the normal overrides like Configure, SelectAssemblies, StartRuntime et c are still there, so you retain instant familiarity. (Don’t worry if you don’t know much about Caliburn.Micro, under the hood Cocktail uses a lot of Caliburn.Micro, but Cocktail has a smaller API surface area).

Once NuGet packages are installed, go to App.xaml.cs delete the entire application class (and enjoy the instant weight reduction!) and replace it with this. (Replace NavSample with your own project name)



        <!-- Application-specific resources -->

        <x:String x:Key="AppName">AssignmentTracker</x:String>

using Cocktail;
using IdeaBlade.Core;

namespace AssignmentTracker
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : CocktailMefWindowsStoreApplication
        /// <summary>
        /// Initializes the singleton Application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App(): base(typeof(GroupedItemsPageViewModel))

        protected override void StartRuntime()

            IdeaBladeConfig.Instance.ObjectServer.RemoteBaseUrl = "http://localhost";
            IdeaBladeConfig.Instance.ObjectServer.ServerPort = 57209;
            IdeaBladeConfig.Instance.ObjectServer.ServiceName = "EntityService.svc";


The GroupedItemsPageViewModel is the first ViewModel that will be loaded by Cocktail. Cocktail then automatically finds GroupedItemsPage.xaml or GroupedItemsPageView.xaml, and displays it on the screen. (This is known as ViewModel-first style. If you are careful, you can develop and test the ViewModels without any dependencies on the actual visual controls, and makes it easier to port to other platforms.)

Next: Defining GroupedItemsPageViewModel

Learning Cobol Round #2

COBOL programs are very similar to FORTRAN ones. Arguments are passed via a DATA DIVISION block. Local variables are declared in a WORKING STORAGE section in the DATA DIVISION.

Interestingly, the variables can have limited range as defined by a string format. For example:


means the variable THE-NUMBER can hold any numbers from 0-99. (maximum length is 18 digits)

Length of alphanumeric variables are declared using letter X. (maximum length dependent on implementation)


One can also declare variables using a shorthand that is reminiscent of SQL (see NEW-MESSAGE)

Formulas are declared using COMPUTE.


Assignment is performed using the MOVE verb. For example MOVE "Samuel" TO FIRST-NAME.. Interestingly, mathematical operations are done in-place. For example:


Alternatively, MULTIPLY 10 BY THE-NUMBER GIVING THE-NUMBER. is probably the clearest.


COBOL has a basic idea of jumping to subroutines. Labels are simply declared without any keywords. The STOP-RUN is used to prevent the program from flowing into the subroutine area.

           STOP RUN.
           DISPLAY "Hello World"

Learning Cobol Round #1

My mum learnt COBOL and FORTRAN when she was in university back in the 60s. Although I have used FORTRAN77 in a professional capacity, I still haven’t had the opportunity to try COBOL.

Since being retro is the harbinger of cool, I’ll spend the next few articles blogging about my experience working with COBOL.

Visual Cobol

There is a free non-commercial use license granted by Visual Cobol. This is sufficient for my learning purposes.

In terms of resources, Teach yourself COBOL is 21 days seems to be a good starting point.

The download is a little tricky. After receiving the confirmation email, I was presented with a screen but the download link wasn’t apparent. It’s tucked under the Software/Licenses tab (see red arrow). The download was 417MB, and I was a little concerned I’ll not have much space left on my SSD, which is burgeoning with several virtual machines. However, the promise of the familiarity of Visual Studio and having access to the .NET framework beckons me to try it out.

In comparison, the OPENCOBOL 1.1 source download is 1 Mb. That’s very inviting, although I don’t really like the idea of building GNU autoconf project on Windows.  There’s never a nice ending.  I found prebuilt-binaries for OPENCOBOL on Windows, and given the download size of 7.3 Mb,  I downloaded it as well.

Upon creating the first COBOL project with Visual Studio, I was prompted for a license key. It wasn’t immediately apparent, but all I had to do was to provide the email address I had used to register with Microfocus, and that activated my free copy automatically.

Running Hello World from a Visual Cobol Console project was simple enough.

       identification division.
       program-id. Program1.

       environment division.
       configuration section.

       data division.
       working-storage section.

       procedure division.

       DISPLAY &amp;amp;quot;Hello World&amp;amp;quot;.
       end program Program1.


OpenCobol was straightforward. Unzip the 64bit binaries to C:\OpenCobol, and run vcvars64.bat to set up the path to Visual C (OpenCobol translates COBOL to C and then uses the platform compiler to build executables). The command below builds hello.exe

cobc -x hello.cob

Project scope

In terms of project, I’d like to try my standard project, involving authorization, data validation and persistence (both NoSQL and SQL). I’m mindful that my projects will be un-COBOL-like, but that can be refined with time.

Next article – Round #2

Working with 4D database via ODBC

There are some peculiarities when working with 4D databases and .NET

Date time 0/00/0 12:00

0/00/0 12:00 is valid in ODBC, but not valid in .NET.
Recommendation – wrap all date calls with a CAST

alternatively, use a CASE statement to convert this call to something palatable to 4D e.g.


Other alternatives simply don’t work. e.g. ... THEN NULL ELSE ... and NULLIF()

Business Forms in Silverlight Part 2

(this is a continuation of Part 1)

From the previous post:

Basic DataForm experience

Basic DataForm experience

The first problem is the OrderDate is unintialized and renders as 0/00/0000.

The first thought is to change the OrderDate from DateTime to Nullable<DateTime>. This will require either the database schema be changed, or a second viewmodel created. Changing the database schema just to support a user-interface tweak is obviously out of the question. However, writing a viewmodel and copying all the properties over breaks a rule of “DRY” (Don’t Repeat Yourself).

Luckily, XAML binding supports the notion of binding converters. This lets us transforms inputs from one type to another.

public class NullValueConverter : IValueConverter

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        if (value is DateTime && targetType == typeof(Nullable<DateTime>))
            if ((DateTime)value == DateTime.MinValue)
                return null;
        return value;

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        return value;

Applying the converter to the date picker, we get reasonably good results. For example, after entering a date and then clearing it, we get a validation error showing (see picture below). Furthermore, hitting cancel restores the control back to default value.


This done, we are ready to tackle our next problem.


Here’s a sample of how converters are applied.

    <local:NullValueConverter x:Key="NullValueConverter" />
  <sdk:DataField Label="Order Date">
    <sdk:DatePicker SelectedDate="{Binding OrderDate, Converter={StaticResource NullValueConverter}}" />

Fool-Proof Business Forms in Silverlight Part I

Silverlight DataForms makes it quick and easy to get started with database applications. However, it has some downsides. The default isn’t particularly customizable, and to do anything more takes a great deal more effort.

Take the following example:

        internal sealed class OrderMetadata

            // Metadata classes are not meant to be instantiated.
            private OrderMetadata()

            [Display(Name = "Order date", GroupName = "Order", Order = 1)]
            public DateTime OrderDate { get; set; }

            [Range(0, 100.0, ErrorMessage = "Please enter more than $0.00")]
            [Display(Name = "Total Amount", GroupName = "Order", Order = 2)]
            public decimal Amount { get; set; }

            [Display(Name = "Purchase Order No", GroupName = "Order", Order = 3)]
            public string PurchaseOrder { get; set; }

            [Display(Name = "Customer Name", GroupName = "Customer", Order = 1)]
            public Customer Customer { get; set; }

            [Display(Name = "Is Delivered", GroupName = "Customer", Order = 2)]
            public byte[] IsDelivered { get; set; }

            public int CustomerId { get; set; }

            public int OrderId { get; set; }
            public float Weight { get; set; }

            [UIHint("Image", "SL", "ScannedFilename")]
            public Byte[] ScannedImage { get; set; }

            public String ScannedFilename { get; set; }

This generates a data form that gets us pretty close. See the picture below.


However, there are several issues:

  1. The Order date is very ugly. It should have default to a null value
  2. The Customer field should have been bound to a combo box or something more custom
  3. The Total Amount validation message could not be customized. It reports “Input is not in the correct format”. Ideally, the message should be customizable and localizable.
  4. CustomerId and OrderId should be hidden
  5. Scanned file name and Scanned image should be combined into a single image control, showing the image, the file name, and provide a method to replace the image.

Over the next few posts, I’ll discuss how to overcome these problems using a custom view model and avoid unnecessary code duplication.

Syncfusion’s latest datagrid

I’ve been looking forward to Syncfusion’s latest release of their Silverlight components (and it’s out today). In particular, their new SfDataGrid datagrid is reaching maturity so I decided to take it out for a quick spin, and verdict is out. Two thumbs up. Well done. Their API is intuitive and much improved from their original DataGrid. It is different, so don’t expect to be able to port over existing code easily, but there is considerably less code to port.

We’ll start off with a simple model

namespace SyncfusionGridDemo.ViewModels
    using System.ComponentModel.DataAnnotations;

    public class Customer
        [Display(Name="Full Name")]
        [Required(ErrorMessage="{0} is required")]
        public string FullName { get; set; }

        [Range(18, 80)]
        public int Age { get; set; }

As you can see there is not much to it, and we’ll create a viewmodel and host a collection of Customers.

namespace SyncfusionGridDemo.ViewModels
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Collections.Specialized;

    public class MainPageViewModel
        private IList<Customer> _addedCustomers = new List<Customer>();
        private IList<Customer> _deletedCustomers = new List<Customer>();

        public MainPageViewModel()
            Customers = new ObservableCollection<Customer>(new[]
                new Customer { FullName = "Marcus Aurelius", Age=30 },
                new Customer { FullName = "Dana Fausbinder", Age=3 },
                new Customer { FullName = "Tomoko Cressida McManus", Age=54 },
            Customers.CollectionChanged += Customers_CollectionChanged;

        void Customers_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            switch (e.Action)
                case NotifyCollectionChangedAction.Add:
                    // TODO these will need to be saved to the database
                case NotifyCollectionChangedAction.Remove:
                case NotifyCollectionChangedAction.Replace:
                    // TODO these will need to be saved to the database



        public ObservableCollection<Customer> Customers { get; set; }

    public static class CollectionExtension
        public static void AddRange<T>(this IList<T> coll, IEnumerable<T> items)
            foreach (var item in items)
                if (!coll.Contains(item))

        public static void RemoveRange<T>(this IList<T> coll, IEnumerable<T> items)
            foreach (var item in items)
                if (coll.Contains(item))


And now let’s bind to Syncfusion SfDataGrid

            ItemsSource="{Binding Customers}" 

and the result is rather good for so little work.

Some minor criticism

The datagrid is not aware of IEditableObject interface. This interface supports BeginEdit(), EndEdit() and CancelEdit(). This allows the user to revert the record’s changes using the escape key.

Overall, the user experience is much improved. Thanks again for listening to my concerns.

Succeeding with Windows Phone Apps

Take aways:

  1. Add all screenshots
  2. Provide background image – or it will not get featured in the Store
  3. Description is super important especially the first few sentences

Make use of

  1. Live Tiles
  2. Lock Screen
  3. Toast Notification
  4. SkyDrive
  5. Wallet
  6. Caching
  7. Location Services

Live Tiles

  1. 159 x 169
  2. 336 x 336
  3. 691 x 336

There are three type of templates

  1. Flips to the back. So the most important info should be on the front
  2. Cycle template of 9 images – but don’t make user wait.
  3. Iconic template small icons
    1. 110×110 for small
    2. 202 x 202 for Medium.
    3. Wide uses the small icon