Creating an Event Source

At times you want to send events to an Ocularis server, and use the servers event distribution system to send notifications to operators and clients. This is – fortunately – a pretty simple operation, so let’s look at a sample.

We are going to create a small WinForm app that simulates two sensors with two rules each, without further ado, lets start by creating a simple WinForm app.

Then, add references to System.Messaging and EventTypes.dll (part of the Ocularis SDK). System.Messaging enables .NET to use Microsoft Message Queuing, while EventTypes provides the classes of object we will be sending to the Ocularis Server. Ocularis is using Microsoft Message Queue which provides a safe and reliable store- and forward mechanism. That means that even if the server is down, or unreachable, events will be sent when it comes back up. No additional code is necessary, but naturally the events will arrive with a delay if the server is unreachable for some period of time – but at least you will eventually be notified.

In your implementation file, you can add these two lines

using System.Messaging;
using EventTypes;

First things first; we need to define some GUIDs. We need one for the system itself, one for each sensor, and one for each rule – so all in all we need 7 GUIDs. I made mine like so:

private static string SystemGuid = "F23E4B1B-DB17-4aac-B26B-8447998347B1";

private static string Sensor1Guid = "4897F900-A1F5-4b6c-8683-6200FED219D9";
private static string Sensor1Rule1Guid = "B2D5D3C4-5724-46fa-A999-D77A221AAF76";
private static string Sensor1Rule2Guid = "4F6CF214-82B6-49fb-A2D9-1592B98803A1";

private static string Sensor2Guid = "9F6759F1-A6FB-4f9d-85C9-2D06D21B645A";
private static string Sensor2Rule1Guid = "01417A33-90DC-4498-8D84-3B0A25E02DD5";
private static string Sensor2Rule2Guid = "2948263F-F684-4afb-9EC6-A50079946299";

The GUIDs are created using Visual Studios GUIDGEN tool (Tools/Create GUID).

In the handler for [Register With Server] we need to create the code to register at the Ocularis Server. To do this we need to create an XML fragment that describes the system (this is just a string with some XML in it), wrap the fragment in an object and send it across using the Message Queue.

In my example, constructing the XML fragment is done like this:

string strConfig = "";
strConfig += "<source>";

// add sensor 1
strConfig += "<sensor name=\"sensor 1\">";
strConfig += "<guid>" + Sensor1Guid + "</guid>";

// add rules to sensor 1
strConfig += "<event><name>Rule 1</name><category>VMD</category>";
strConfig += "<guid>" + Sensor1Rule1Guid + "</guid></event>";
strConfig += "<event><name>Rule 2</name><category>VMD</category>";
strConfig += "<guid>" + Sensor1Rule2Guid + "</guid></event>";

strConfig += "</sensor>";

// add sensor 2
strConfig += "<sensor name=\"sensor 2\">";
strConfig += "<guid>" + Sensor2Guid + "</guid>";

// add rules to sensor 2
strConfig += "<event><name>Rule 1</name><category>VMD</category>";
strConfig += "<guid>" + Sensor2Rule1Guid + "</guid></event>";
strConfig += "<event><name>Rule 2</name><category>VMD</category>";
strConfig += "<guid>" + Sensor2Rule2Guid + "</guid></event>";

strConfig += "</sensor>";

strConfig += "</source>";

Now let us register at the server. In the application, the server input field is mapped to _ctrlServerIP (a textbox), so we proceed with this..

try
{
  // prepare event object
  EventTypes.SourceSetup src = new SourceSetup();
  src.m_strName = "Prescienta Event Demo";
  src.m_strGuid = SystemGuid;
  src.m_iSourceType = 0;
  src.m_strConfig = strConfig;

  // prepare event queue
  _serverQueue = new MessageQueue();
  _serverQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
  _serverQueue = new System.Messaging.MessageQueue("FormatName:DIRECT=TCP:" + _ctrlServerIP.Text + "\\PRIVATE$\\onssieventqueue");

  _serverQueue.Send(src);
}
catch (Exception ex)
{
  MessageBox.Show(ex.Message);
}

That’s it. If it all went well, we should see the source in the admin, with the two sensors and the rules attached.

To trigger an event, we simply create another object and send it across the server queue.

private void SendEvent(string strEventGuid)
{
  if (_serverQueue == null)
  {
    MessageBox.Show("No queue created");
    return;
  }

  try
  {
     // create an event object
     EventTypes.GenericEvent genEvent = new GenericEvent();
     genEvent.m_strDesc = "User Created Event";
     genEvent.m_strServerGuid = SystemGuid;
     genEvent.m_strEventGuid = strEventGuid;
     genEvent.m_strTimestamp = DateTime.Now.ToUniversalTime().ToString();

     // send event
     _serverQueue.Send(genEvent);
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

The solution files can be found at OnSSI’s SDK Page

Advertisements

Win 7, broken as ever!

At least on 64 bit.

Changed from Vista 64 to Win 7 because Vista 64 kept screwing up the NTFS tables (Knoppix sometimes was able to help out, where the expensive, for profit, POS software fails).

Installed Win 7, VPN no longer works (no warning, but you’ll learn after having waited 3 hours to install the idiot OS). Video Drivers went AWOL, got new ones though the wonderful wizard, now I have a nice error message every time i boot.

Icons that “lead nowhere” give you the helpful error message “The parameter is incorrect” – I am sure that little 5 year old Asian kid knows the significance of THAT message.

Forget Microsoft, and stick with the Snow Leopard – this Windows 7 is a piece of feces.

An example of the attention to detail in Windows 7:

MeaninglessDragger

Update : Win7 has been playing nicer than Vista since i installed it (no NTFS problems)

Ocularis In-Store Display

Some clients have a nice full screen display mode with no GUI for in-store displays. Ocularis has one too, and it allows you to customize the layout a little bit.

In its standard form, OC would look something like this.

Ocularis In Standard Mode

In a kiosk setting you might not want to display the camera name, the menu bar, the connection indication and any status or error messages that might make sense otherwise, so these things can be turned off.

First you need to create a “skin file”:

<?xml version='1.0'?>
<skin>
  <kioskmode>yes</kioskmode>
  <globaloverlay>c:\skin_custom.png</globaloverlay>
  <showdiskspaceerror>no</showdiskspaceerror>
</skin>

The file should be called skin_custom.xml and be placed next to the HeimdallViewer.exe file (usually in the c:\program files\OnSSI\Ocularis Client directory)

The tag kioskmode puts the Ocularis Client into – well – Kioskmode. That means: No menu bar, no camera labels, no connection status and a nice, calm fade between cameras in a carousel. That also makes the showdiskspaceerror sort of moot (since no errors are ever shown on the screen).

The globaloverlay node is a path to a 32 bit PNG file. The file is stretched to match the window/screen, so to avoid any stretching artifacts, you should prepare a PNG that has the exact same size as the screen (or at least have the same aspect ratio).

In my example, I made a small PNG with a logo and some happy rainbow colors.

Example of Overlay File
Overlay

The end result is this:

It should be noted, that some screens are susceptible to burn-in, so keep that in mind before going deciding to place a logo on the window.

Focus Groups?

I am pretty sure that day to day interaction between clients and developers is the best way to develop useful, and remarkable products.

Here is what Jonathan Ive said

So how did the company decide what customers wanted – surely by using focus groups? “We don’t do focus groups,” he said firmly, explaining that they resulted in bland products designed not to offend anyone.

http://www.bbc.co.uk/blogs/technology/2009/07/listening_to_mr_iphone.html