Tip: Create an App icon for your website

If you already have a web site, and you are thinking about creating a mobile app version of this, there is a less expensive approach.

Mobile users who bookmark your website can get essentially an App experience because your website will have a proper App icon, rather than a screenshot of your website.

Here’s a flow chart of what you will need to support iOS, Android and Windows

Cocktail for Windows Store – Part 3

One style of Entity Framework development is known as Code-First. With Code-First style, you’d define the schema using .NET classes and properties. This style of development makes it easy to keep the data model under source control.

Entity Framework comes with a powershell script that detects the schema changes as you add/modify the classes, and generates the necessary upgrade scripts for you.

Our project involves an assignment tracker for schools. Students can be assigned one or more assignments in subjects they are enrolled to. Assignments are created by the teachers who teach the relevant subject.

// Schema.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace AssignmentTracker
    using IdeaBlade.Aop;

    public class Assignment
        public int Id { get; set; }

        public string Description { get; set; }

        public int StudentId { get; set; }

        public int SubjectId { get; set; }

        public DateTime? DateDue { get; set; }

        [Association("Assignment_StudentSystemUser", "StudentId", "Id")]
        public Student Student { get; set; }

        [Association("Assignment_Subject", "SubjectId", "Id")]
        public Subject Subject { get; set; }

    public class Subject
        public Subject()

        public int Id { get; set; }

        public string Description { get; set; }

        public int TeacherId { get; set; }

        [Association("Subject_Teacher", "TeacherId", "Id")]
        public Teacher Teacher { get; set; }

        public IList<Student> Students { get; set; }

    public class SystemUser
        public int Id { get; set; }

        public string UserName { get; set; }

        public string FullName { get; set; }


    public class Student : SystemUser
        public Student()
            //Subjects = new RelatedEntityList<Subject>();

        public string StudentNumber { get; set; }

        public ICollection<Subject> Subjects { get; set; }

    public class Teacher : SystemUser
        public virtual IList<Subject> Subjects { get; set; }

Schema.cs is added to AssignmentTracker.Server.dll and added as a link to the AssignmentTracker.RT project. This is the main value from DevForce, the same code that is used on the server is deployed on the client.

Ideablade Cocktail for Windows Store – Part 2

A Cocktail project is usually grouped into folders called Views and ViewModels. The Views folder contains all the XAML files, and the ViewModels contain the datacontext that each view binds against.

We’ll create the missing GroupedItemsPageViewModel first, and then drag them into the Views and ViewModels folder. All Cocktail ViewModels that represent a screen should inherit from Screen, and INavigationTarget. The INavigationTarget has two purposes:

  1. It provides notification when a screen has been navigated to, or navigating away from – Similar to Silverlights Navigation events
  2. It also provides notification that the screen is about to go into suspended state, so that we can save the work and resume later.
using Caliburn.Micro;
using Cocktail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignmentTracker
    public class GroupedItemsPageViewModel : Screen, INavigationTarget
        private INavigator _navigator;

        public GroupedItemsPageViewModel(INavigator navigator)
            _navigator = navigator;

        #region INavigationTarget

        public void LoadState(object navigationParameter, Dictionary<string, object> pageState, Dictionary<string, object> sharedState) { }

        public void OnNavigatedFrom(NavigationArgs args) { }

        public void OnNavigatedTo(NavigationArgs args) { }

        public void OnNavigatingFrom(NavigationCancelArgs args) { }

        public string PageKey { get; set; }

        public void SaveState(Dictionary<string, object> pageState, Dictionary<string, object> sharedState) { }


So far, we have not loaded any entity from the database yet. That’ll be the next topic.

Next: Querying entities

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}}" />