If you are a blogger, you probably have heard of Photobucket.com a site for storing your media files (images, video, audio).  As you can see from this interview on Channel 9, Photobucket has just released a new API.  If you know me by now, you would have guessed what opportunity I would see with this: a Silverlight 2 library of course.

Knowing that Microsoft has both CodePlex (for open source projects) and the MSDN Code Zone (for examples), you might be wondering why I posted it on Google Code.  Since there are already some Photobucket projects on Google code - it makes sense to put this project there as well.

I already have an experimental project up on my test website with some unit tests as well that use the Unit Test framework that you can download along with the Silverlight 2 Beta 1 control source code. 

I am looking for people who are interested in helping me complete and maintain this library, please go to the project and join in.

Here's what one of the unit test looks like:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using Microsoft.Silverlight.Testing;
using Photobucket;
using System.Resources;
using System.Windows.Controls;

namespace Test
{
  [TestClass]
    public class APITest : SilverlightTest
    {
        /// <summary>
        /// Test the Photobucket.API.Search method
        /// </summary>
        [TestMethod, Asynchronous, Description("Search")]
        public void Search()
        {
            m_api.Search("beach", 100, 10, 1, 0, 5, "images", true, delegate(object sender, Photobucket.SearchCompletedEventArgs args)
            {
                EnqueueCallback(() => Assert.IsTrue(args.Succeeded, "Search API Call failed with {0}.", new object[] { args.StatusDescription }));

                EnqueueTestComplete();
            });
        }
    }
}

Here's what the demo app code looks like to do the search:

        void Search_Click(object sender, RoutedEventArgs e)
        {
            var searchText = this.SearchText.Text;

            m_api.Search(searchText, 10, 10, 1, 0, 0, "images", true, new EventHandler<Photobucket.SearchCompletedEventArgs>(SearchReturned));
        }

        void SearchReturned(object sender, Photobucket.SearchCompletedEventArgs args)
        {
            if (args.Succeeded)
            {
                Images.ItemsSource = args.PrimaryMedia;
            }
        }

Here's the XAML for the listbox that has its ItemsSource setin the code above (notice the Binding syntax):

            <ListBox x:Name="Images" Height="400">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Background="Gray" MouseLeftButtonDown="StartDraggingListItem" Tag="{Binding Url}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Image Grid.Row="0" Grid.RowSpan="2" Stretch="Uniform" Width="100" Height="100" Source="{Binding Thumb, Converter={StaticResource converter}}"/>
                            <TextBlock Grid.Row="1" Text="{Binding Title}" Foreground="White" FontSize="10"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>