ASP.NET Ajax and Silverlight

by mheydt 28. August 2007 01:35 >

Over the last few days I've decided to start working on some Silverlight content for the site.  I decided to use this as I was looking for a good picture gallery for the site.  I initially found simpleviewer from airtightinteractive.com.  SimpleViewer is a flash object for displaying photo galleries, and I really like what it can do (you can see an example here).  I did find the code way too complicated for my liking, and I didwrap all of this so that it can be run in an asp.net web control to hide all of the gory details of setting up the flash. 

Also from Airtight Interactive is a post card gallery, which I really liked.  Unfortunately, that control is really limited in its free version, to the point that I don't want to use it and don't want to buy it as I would think I can find something similar elsewhere.

So, I figured that since Silverlight is supposedly so neato, I decided to start looking for Silverlight photo gallery controls.  There are a few basic demos out there, but I didn't really find anything really suitable, exception for potentially the Silverlight Surface Demo.  I really like this, and to great lengths it is very similar to the post cardviewer that I'd like, so I figured I'd go about modifying the code to get it to do operate this way (as well as to learn Silverlight).

I immediately came upon a problem in the code that I needed to address.  The demo code has a fixed set of images that are hard coded by name into the application.  Sure, they are downloaded dynamically to the client, but the set of files is fixed.  Given I would like to reuse the control to display multiple sets of galleries, I needed to figure out how to provide a dynamic list of files to the Silverlight control.

This was not exactly easy to figure out.  There were several issues that I had identified.  First, most demos I could find utilized .HTML files, not .aspx files.  So, this inherently wouldn't let me write code-behind to process parameters.  Second, I could find no examples of how to pass dynamic (or static) data from the page into the silverlight control.  Third, was how to program the silverlight control to retrieve data from the back end dynamically from the page based upon data passedinto the control.

 

Tags:

.Net | Silverlight

evisting the iterator pattern, revisited again

by mheydt 15. August 2007 15:47 >
Revisting the iterator pattern, revisited again
I was playing around with .NET 3.5 extension methods and lambda functions and it hit me that this will very closely get me to the syntax that I desire for iterating across collections.  If you remember from my earlier post, I was looking for a syntax like the following (which is kind of both C# and ruby-ish in style):

    int[] ia = new int[] { 5, 4, 3, 2, 1};
    iterate ia |x| do { Console.WriteLine(x); } where { x < 3; };



Well, what I was able to come up with is an extension method that can add an iterate method to a collection (basically, anything IEnumerable) that can take two lambda methods, one for selecting items, and the other for processing on each selected item.  For example, the following actual C# code is possible:

    int[] ia = new int[] { 5, 4, 3, 2, 1};
    ia.iterate(x => x < 3, x => Console.WriteLine(x));


The output of running this c# is:

2

1

One of the neat things about the lamba methods is that they can operate on variables declared in local method scope.  For example, take this example of building a list on the items between 2 and 4 and then printing out that list:

    int[] ia = new int[] { 5, 4, 3, 2, 1};
    List<int> result = new List<int>();
    ia.iterate(x => x >= 2 && x <= 4, x => result.Add(x));
    result.iterate(x => Console.WriteLine(x));


This prints out:

4

3

2

The code for this extension method is the following:

    public static class IterateExtension
    {
        public delegate void operationdelegate(object o);
        public delegate void operationdelegate<T>(T o);
        public delegate void selectiondelegate(object o);
        public delegate bool selectiondelegate<T>(T o);
        public static void iterate<T>(this IEnumerable<T> objects, operationdelegate<T> od)
        {
            foreach (T o in objects)
            {
                od(o);
            }
        }

        public static void iterate<T>(this IEnumerable<T> objects, selectiondelegate<T> sd, operationdelegate<T> od)
        {
            foreach (T o in objects)
            {
                if (sd(o))
                    od(o);
            }
        }

        public static void iterate(this IEnumerable objects, operationdelegate od)
        {
            foreach (object o in objects)
            {
                od(o);
            }
        }

        public static void iterate<T>(this IEnumerable objects, selectiondelegate<T> sd, operationdelegate<T> od)
        {
            foreach (T o in objects)
            {
                if ((sd(o)))
                    od(o);
            }
        }
    }

Tags:

.Net | P#

Spine MRI = Ruptured Disc

by mheydt 2. August 2007 15:45 >
I just got the MRI of my spine and its pretty obvious what the problem is: L4 ruptured disc.  So, of course, I thought I'd show it to everyone…

Tags:

Me

about the author

I'm a .NET, XAML, and iOS polyglot that loves playing with new things and making cool and innovative stuff.  I am also a Mac junkie.

I am Principal Technologist for SunGard Global Services in NYC, in their Advanced Technologies practice, and I work extensively with SunGard's energy and financial customers.

Note the the posting on this blog are my own and do not represent the position, strategies or opinions of SGS.

twitter

I can't stop thinking big!
Sunday 1:08AM via WindowsLive
Just watched Moneyball. That's my pick for best movie this year.
Saturday 3:51PM via WindowsLive
@vincebelpiede: Report: Skype For Windows Phone Beta Imminent http://t.co/KYNjgg1L#mhtnd
Wednesday 8:39AM via Twitter for Mac
@mashable: Kinect Fusion Will Turn Gaming (and More) Into a 3D Fun House - http://t.co/Ihrq2fY2#mhtnd
Wednesday 8:39AM via Twitter for Mac
New Kinect SDK: http://t.co/57MvA5L5 #mhtnd
Wednesday 8:39AM via Twitter for Mac
Follow me on Twitter

recent comments

None

month list