Timmy's Blog

Embedding IronPython in a C# application

 

1/02/2010 14:27:26

For reasons explained in my previous post, I decided to embed IronPython.

In this post I’m going to show you how to do it yourself. In order to get started
you’ll need a build of IronPython. If you’re targeting .NET 4.0 Beta 1 you’ll have to
get “IronPython 2.6 CTP for .NET 4.0 Beta 1”, otherwise you can get the normal release.
(The new features of C# 4.0 do make it a lot easier to embed dynamic languages).

Comments: 0 (view/add)
Tags: c# | development | dotnet

Why I decided to embed IronPython

 

31/01/2010 19:27:33


Most of the applications that we and our partners work on are highly customized
for a very specific purpose with point-and-click end users in mind, but some of the
applications are designed only to control and configure hardware devices.

The highly customized applications usually integrate our hardware as part of a much
larger system. The focus of those applications is not the hardware.

The focus of the other applications is really the hardware itself.
Those applications simply try to expose all of the hardware’s functionality
with just enough abstraction so that the end users (most likely technicians, engineers or
others with detailed knowledge about the hardware) can consume it easily.

Consider the software to control our LED panels. It allows the user
to configure the LED hardware’s parameters, perform diagnostics and
put various components on the screen as a means to “demo” it to potential customers.

This software is not on our highest priority list, so it doesn’t really get special features
or new additions unless the hardware changes.

However, on more than one occasion we’ve had customers asking:
Hey it’s great you can control the hardware like that, and we like the designer you
provided, but some of our engineers would like the ability to do some of those things
by using code.” and
we’ve had situations where potential customers want to see more
then the static demo where you just add some text, pictures, etc… to the screen.

Now with IronPython we can solve both problems in one go. By embedding IronPython
into our application the end user can manipulate the objects we expose directly.
The customer wants to see the latest tweets on an LED panel or perhaps a simulation
of traffic information on an LED panel? No problem!


A screenshot of the initial version of our IronPython powered DSL.
(Completely outdated, but more on that in my next blog entry)

I’m going to post more information on how to embed IronPython in .NET applications
very soon. If you’re an IronRuby fan, don’t worry the same concepts apply.

Comments: 0 (view/add)
Tags: c# | development | dotnet

ClickOnce Trouble

 

15/12/2008 21:13:42

ClickOnce is a great way of distributing software and it's been
a real life saver for one of the projects I've been working on.

Basically it allows you to publish an application every time you
have a working build and all customers will get the new version automatically
the next time they start the software. Users don't have to go through the motions
of uninstalling old versions, copying files and so on.

On more than one occasion I had the customer calling me to report a problem
and by the time the conversation was over I had already published an updated version.
It's kinda nice to tell the customer "Please restart the application, there ya go... it works".

There's a lot more to ClickOnce than easy deployment, such as sandboxing
and fine grained security but that's not what this post is about.

While using ClickOnce I tend not to worry about deployment problems,
and without giving it any further thought I published the application from
my laptop after making a few tweaks while I was on the road.

I've learned never to try that again...

The software published just fine... but after updating the clients
started crashing and the entire update system collapsed.

After quite a long time of bug hunting I finally realized it might
have had something to do with the fact that I published from another pc.

I came home, updated the source repository, published from my dev-machine
and all was well again... Bottom line: only publish from a single computer.

PS: Google either uses or mimicks the ClickOnce deployment technology,
can anybody confirm this?

Comments: 0 (view/add)
Tags: c# | development | dotnet

Working with the Windows Forms ListBox

 

16/06/2008 0:05:19

I haven't used Visual Basic 6 in years, but yesterday I got a question from Karl,
who's a Visual Basic developer who recently migrated to C#. Karl is used to working
with the ListBox control in VB6 and wants to know how to work with the .NET version.

Visual Basic 6 isn't an object oriented language and the ListBox only had the ability to
work with strings. Basically you could add and remove strings to and from the ListBox:

lstProducts.AddItem "Product A" lstProducts.AddItem "Product B"

If you wanted to build your list of items from a database, you had the ability to use
the ItemData field to store an extra string for each item in the list, allowing you to
identify the item with the value of a primary key field for example. While it was easy
to use, it was hardly versatile and forced us to write a lot of glue-code.

The biggest challenge, coming from a language such as Visual Basic is to understand
object orientation and the fact that it requires a whole new programming methodology.
Visual Basic developers often feel .NET is overly complex and more difficult to work with,
while in fact it provides a much more flexible and scalable development environment.

Karl wants to fill a ListBox with records of a database. He didn't tell me what data
he's working with, so let's assume he wants to display products. The table looks like this:

Product
- Id : Integer
- Name : VarChar
- UnitPrice : Double

In the past he would iterate through all the rows in the table and add a string to
the ListBox for each one of them. Setting the ItemData field of every item to the Id.

In this post I'll explain how to do this in .NET or Windows Forms to be more precise.
I'll explain everything using C#, but what follows isn't language specific.

Comments: 3 (view/add)
Tags: c# | development | dotnet

GData-DotNet Google Group

 

24/01/2008 12:08:02

There's a new group for the GData.NET project.
Until now messages were posted to the general group for the GData API.

So if you are a user of the .NET client libraries who wants to know about
new features and updates, please subscribe here. (gdata-dotnet-client-library)
Comments: 0 (view/add)

System.Data.SQLite v1.0.47.0 released

 

4/12/2007 18:24:09

Shortly after publishing my previous entry, I was contacted by
Robert Simpson who explained the cause of the problem to me.
It turned out it wasn't a real bug but rather a usability issue.

Like many developers, I was closing connections but didn't always dispose
of them, as this is normally handled by the garbage collector.
(It's actually a bit more complex than this, but that's besides the point)

This problem has been fixed in the latest release which you can download here.

System.Data.SQLite is an enhanced version of the original SQLite database engine.
It is a complete drop-in replacement for the original sqlite3.dll. It has no linker
dependency on the .NET runtime so it can be distributed independently of .NET,
yet embedded in the binary is a complete ADO.NET 2.0 provider.

Personally I love SQLite and I see no reason to deploy a database server
as a data back-end for small sites such as my blog for example.

Comments: 0 (view/add)

C# IEqualityComparer

 

7/10/2007 23:35:07

In my previous entry I explained the basics of operator overloading in C#
and why it's important when comparing instances of user-defined reference types.

But sometimes you want to compare instances based on something other than
the overloaded operators. Let's say you want to compare instances of the
GoogleCalendar based on their value for the Title property. Of course we could
simply rewrite the code for the overloaded operators, but that's probably not
a good idea, since most of the time we'll base comparison on the GoogleUrl property.

Remember this code? This code uses the overloaded operators for the LINQ Except methods.
var newCalendars = calendars.Except(noSyncCalendars).Except(syncCalendars); foreach (GoogleCalendar newCalendar in newCalendars) { this.noSyncCalendars.Add(newCalendar); }

We want to do the same thing, but we want to compare based on the Title property instead.
Don't change any operator code, but create a new class which implements the IEqualityComparer:
class CalendarEqualityComparer : IEqualityComparer<GoogleCalendar> { public bool Equals(GoogleCalendar x, GoogleCalendar y) { return (x.Title == y.Title); } public int GetHashCode(GoogleCalendar obj) { return obj.GoogleUrl.GetHashCode(); } }

Now we can execute the same LINQ functions again, but we have to change something:
var newCalendars = calendars.Except(noSyncCalendars, new CalendarEqualityComparer()).Except( syncCalendars, new CalendarEqualityComparer()); foreach (GoogleCalendar newCalendar in newCalendars) { this.noSyncCalendars.Add(newCalendar); }

We instruct the Except() to use the CalendarEqualityComparer class
for comparison instead of the default "==" operator.

Just wanted to share that with the world, you never know when somebody needs it :-)
Comments: 0 (view/add)
Tags: c# | development | dotnet

C# Operator overloading

 

7/10/2007 23:18:47

What's the output of the following method?
int x = 4; int y = 2; Console.WriteLine(x == y ? "They are the same" : "They are different");

There's no doubt this will result in "They are different" being written to the screen,
but what about comparing user-defined types?  Let's say you have a class called GoogleCalendar:
class GoogleCalendar { private string title; private string googleUrl; private bool sync; public GoogleCalendar() { //Default } public GoogleCalendar(string GoogleUrl, string Title, bool Sync) { this.googleUrl = GoogleUrl; this.title = Title; this.sync = Sync; } public string Title { get { return this.title; } set { this.title = value; } } public string GoogleUrl { get { return this.googleUrl; } set { this.googleUrl = value; } } public bool Sync { get { return this.sync; } set { this.sync = value; } }

If you create two instances of this class and compare them:
GoogleCalendar c1 = new GoogleCalendar("img1.jpg", "Sample", true) GoogleCalendar c2 = new GoogleCalendar("img1.jpg", "Sample", true) Console.WriteLine(c1 == c2 ? "They are the same" : "They are different");

What do you think will happen here? Honestly?
Comments: 0 (view/add)
Tags: c# | development | dotnet

Google .NET Calendar API v1.1.0.0 diagram

 

4/10/2007 17:37:42

Google has released an update to their .NET calendar API libraries today.
Since I'm using the libraries in a few projects, I decided to create a diagram
of the Calendar API object model.

(You can get the full sized version right here)

I added commonly used classes and their direct parent. If you're developing
Google API applications using .NET, please let me know so we can share :-)
Comments: 0 (view/add)

Microsoft releases sources for .NET libraries

 

3/10/2007 23:25:52

Scott Guthrie just announced that Microsoft will be releasing the
source code for a lot of the .NET libraries under the MS reference license.

The sources for the classes in the following namespaces will be included:
  • System
  • System.IO
  • System.Collections
  • System.Configuration
  • System.Threading
  • System.Net
  • System.Security
  • System.Runtime
  • System.Text
  • System.Web
  • System.Windows.Forms
  • System.Data
  • System.Xml
  • System.Windows
The sources for even more libraries will be released at a later time.
The .NET source libraries will be made available as a separate download
allowing you to browse and view the files using any text editor.

I can't wait to take a look at some of the implementations and to compare
the them to the Mono implementations. There's a lot to be learned from this.
Comments: 0 (view/add)
Tags: c# | development | dotnet

|<< 1 2 >>|