Friday, October 19, 2007

I've always liked the software from Microsoft, and especially Windows. Ever since I started my first Windows program back in 85, I knew they were on the right track. A few years I was frustrated because I had to code in character-based tools while my users had a better UX with the mouse, and when I could use Windows to do my work, I was delighted – and I still am! I don't know why many in our business are so afraid of being Microsoft "fan boys". Why not? It's a very successful company, and that success mostly comes from creating great software. I'm not ashamed; I'm a Microsoft fan boy!

Just take a look at my desktop on the right. Every morning when I turn on my computer I smile. I just love what I do (and of course my amazing woman on the photos from Greece this summer), and there are very few days that I don't want to write some code to create something amazing. My dear friend, Andy, always tell the story of his school paper about programming he named "Happiness", and I know exactly what he means. I'm happy! What I like most with the stuff from Microsoft is that I can use the same tools to program everything from a fat server to a tiny mobile phone (I'll never buy a phone where I can't install my apps).

Even if some of my friends and colleges complain about Vista (they say that they will go back to XP, that Microsoft is offering free "downgrades", maybe buy a Mac, etc), I haven't regretted installing it one second. I know it's not as fast as it should be, that all the drivers aren't there yet, and I say: -What's new? I have been installing new versions of Windows (and other OSs) for 20 years, and it's always the same thing. The hardware manufacturers need to catch up, that's all. I use Vista mostly for development, and I think almost everything works great. If I need to try something odd, I fire up a VPC image, and if it crashes with a blue screen, I only smile again, and restart it.

All in all, I haven't had any major problems, I have been able to sync my mobile devices with Windows Media Center since the installation (I guess I'm lucky). But I'm also very careful (I always unpack installation to see what they do before I run them) and I follow a golden rule: don't install too much of the other's stuff. I was forced to install QuickTime by the Expression Media setup, and after that my IE couldn't even show .png files, so QuickTime had to go. I haven't even thought about unnecessary things like Firefox (I have a great browser in IE) or RealPlayer (I have a great media player), and I'm more surprised when some actually work, like Skype, Nero, etc. I'm actually amazed that my favorite imaging tool, Image Composer (now 10 years since its last version), actually runs very well on my 64-bit Vista! I even like the name "Vista" as it means "View" in most of the Latin languages, and that's the feeling I get every morning as I turn on my laptop!

Keep up the great work, Microsoft!

posted on Friday, October 19, 2007 4:34:47 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Thursday, October 18, 2007

Even if the Silverlight Downloader is fairly tolerant when it comes to handling unsuccessful downloads of files from the server, it can be inefficient to use that tolerance. As an example, I was playing around with Michael Schwarz's excellent Surface sample (source code) and wanted it to handle an arbitrary number of pictures. I therefore created a general purpose method that uses the BrowserHttpWebRequest (only link I could find) from the System.Windows.Browser.Net namespace, and it looks like this...

public static bool CheckUri(Uri uri)
{
    
bool exists = false;

    
try
    {
        
HttpWebRequest request = (HttpWebRequest) new BrowserHttpWebRequest(uri);
        request.Credentials =
new NetworkCredential("Username", "P@ssw0rd");
        request.PreAuthenticate =
true;
        
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        request.Abort();

        
// Success?
        if(response.StatusCode == HttpStatusCode.OK)
            exists =
true;
        response.GetResponseStream().Close();
    }
    
catch(WebException we)
    {
        exists =
false;
    }
    
catch(Exception ex)
    {
        exists =
false;
    }
    
return exists;
}

...and with this placed in a helper class (e.g. NetHelper), the check can be made with code similar to...

for(int i = 1; i < 100; i++)
{
    
if(NetHelper.CheckUri(new Uri(HtmlPage.DocumentUri, "photo" + i.ToString("00") + ".jpg")))
        
// File exists, so get it using Downloader
    else
        break;
}

...assuming that the photos are named in sequence "photo01.jpg", "photo02.jpg", and so on. The loop will download photos until one in the sequence is missing.

Note that the CheckUri method can be used to check connectivity in general. Of course, you can check that you have a network connection using the InternetGetConnectedState Windows API or even that a specific domain exist with Dns.GetHostEntry, but if you want to check for a specific file (e.g. the .asmx file of an XML Web Service), the CheckUri method is very useful.

BTW, a tip is to set the inplaceInstallPrompt parameter to true to speed up your users installation of the Silverlight plugin.

 

posted on Thursday, October 18, 2007 8:36:27 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Wednesday, October 17, 2007

User Experience (UX) on the web and on Windows clients is moving forward! We have moved from the basic (HTML) to the second wave (DHTML/AJAX/etc), and even if many (the games industry is always ahead) have already created a better UX (mostly with Flash), much is still to be done. I believe that one important reason is that Flash requires the traditional site developers to learn both a new tool and programming language/model. And even if the first version of Silverlight build on well-spread JavaScript with the addition of XAML, it's with Silverlight 1.1 (now in Alpha since September) that things are getting interesting. The reason is that the Silverlight applications are now driven by the managed code that we have learned to love (and sometimes hate). The new thing to learn is WPF and XAML, but with excellent books like Applications = Code + Markup and sites like WindowsClient, I'm fine, and with tools like SWF to Xaml I can even reuse the cool stuff all those designers already created. If you want to get started right away, check out this great blog post by David Crow.

If you need to be more motivated, you should check out all the great Silverlight demos out there. Two great sources are the blog posts by Tim Sneath and Mikael Schwarz, and my personal favorites at the moment are the site on Presidential Election 2008 demo and the RIA Eurojob demo built with GOA which allows you to code as in WinForms and then run in Silverlight or Flash.

Don't you just want to build applications like the screenshot on the right (click on image for more info)?

posted on Wednesday, October 17, 2007 4:56:27 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Tuesday, October 16, 2007

So, after my post on waiting for Silverlight for Devices, I spent last night and much of today finding a way to render XAML on a web server. You can see the result in the article Silverlight on Devices, and of course the code is also included.

As expected, there are a lot of the good stuff that you miss out on using this approach (interactivity, animations, etc), but it serves the purpose of moving the design elements of your application to the new user interface platform (XAML, WPF, etc). When the technology is available on the device, the work done can be migrated to the mobile application.

In the article's sample I only render static XAML on the server, as I couldn't get the data binding to work (anyone?), but in most situations this shouldn't be a problem as you do the rendering on the server anyway.

posted on Tuesday, October 16, 2007 4:44:01 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Monday, October 15, 2007

Ever since Mike Zintel's post WPF/e and the .NET Compact Framework on my 40th birthday more than two years ago, I have been waiting. I think he was right then, and I still think he is right. We need an implementation that focuses on the user interface and that allows for both online and offline. My only concern was why it was taking so long, and finally my hopes were out...

...and THEN, Robert Unoki made me green with envy when he posted on his cool work with Silverlight and Compact Framework. A bit later the video with Scott Holden appeared, and my hopes were on max again. But that was almost six months ago, and now I'm getting really inpatient. When you look at the great developer overview of the current Alpha build of Silverlight, Compact Framework isn't even on the "map" (neither is XBOX/XNA).

Even if I mostly build Enterprise applications, I want to build UXs like that (yes, Mike Zintel was right again on his theory that somewhere inside we all get into this business hoping to write video games ;-))

So, what can I do while waiting? Well, I remember that when I didn't have GDI+ on the device, I would create on-the-fly charts on a Web server that download them directly to my WinForms apps on the device. It had its drawbacks, but served my purpose. What if I could do the same with XAML on the server? I'll take a look at that soon...

posted on Monday, October 15, 2007 10:43:53 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [1]
 Thursday, October 11, 2007

As a follow-up on my previous post about pulling data from a web site, this post is about doing it the other way -- uploading data to a web site.

Let's first fill a byte array with some content, usually from a file (or database) like this (require a reference to System.IO)...

FileStream fs = File.OpenRead("file.any");
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes((int)br.BaseStream.Length);
br.Close();
fs.Close();

...and then the code to upload looks like this (require an additional reference to System.Net)...

string url = "http://www.businessanyplace.net/file.any";
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method =
"PUT";
request.Credentials =
new NetworkCredential("UserName", "P@ssW0rd");
request.PreAuthenticate =
true;
request.AllowWriteStreamBuffering =
true;
// For large files (> 50KB) you may want to uncomment the next line
//request.SendChunked = true;
request.ContentLength = data.Length;
Stream s = request.GetRequestStream();
s.Write(data, 0, data.Length);
s.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
HttpStatusCode code = response.StatusCode;
string result = code.ToString();

...and this works just as well for text files as for any binary file. Please note that the user needs to have write access to the virtual directory (and the physical disk location) where the file is to be written. For a more complete example of how files (media) can be compressed (zipped) and uploaded to a Web site, see the source code for my article Claims2Go: Claims Processing for Windows Mobile-Based Devices.

posted on Thursday, October 11, 2007 6:19:43 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Wednesday, October 10, 2007

There are some questions that seem to be coming back all the time, and one of those is how to download from a web site. Whether it's a file or an image, it's basically the same approach.

I saw a nice article on DevSource name Pulling Data From Internet URLs in C# using the WebClient class which is a good alternative if you are planning on using it in the upcoming Compact Framework 3.5. But if you want a solution now, here's some code. Let's start by downloading a file (references to System.Net and System.IO)...

string url = "http://www.businessanyplace.net/images/ba.gif";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.Credentials =
new NetworkCredential("UserName", "P@ssW0rd");
request.PreAuthenticate =
true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
int size = 2048;
byte[] data = new byte[size];
FileStream fs = File.Create("baOnDisk.gif");
while(true)
{
    size = s.Read(data, 0, data.Length);
    
if(size > 0)
        fs.Write(data, 0, size);
    
else
        break;
}
fs.Close();

...and note that the download is buffered (in 2K blocks). I've also added some credential code to make it more realistic. If you want the contents of a text file in a string, the code can be modified like this (with a reference to System.Text)...

string url = "http://www.businessanyplace.net/sample/test.htm";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.Credentials =
new NetworkCredential("UserName", "P@ssW0rd");
request.PreAuthenticate =
true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
int size = 2048;
byte[] data = new byte[size];
while(true)
{
    size = s.Read(data, 0, data.Length);
    
if(size > 0)
        sb.Append(
Encoding.ASCII.GetString(data, 0, size));
    
else
        break;
}
string strData = sb.ToString();

...and to process that further (parsing the HTML, etc), you can now follow the same approach described in the article mentioned above.

posted on Wednesday, October 10, 2007 10:10:16 AM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]
 Tuesday, October 09, 2007

So, after installing, configuring, and tuning the dasBlob software, my blog is finally LIVE!

I even created my own skin to get the clean look-and-feel that I (and I hope you) like. As you can see, I like the default fonts in Office 2007! I will be using Word 2007 to post to this blog, and after the configuration was set up correctly, it actually works very well. Even the images get uploaded through the Web Service interface (MetaWeblog API) as the latest dasBlob implementation (I'm running version 2 on ASP.NET 2.0) now even handles a small bug in Word 2007.

I will dedicate this blog to my favorite technologies: Compact Framework and Silverlight. As you see on the links they are aimed at developers, which is also the main focus for this blog. I'm a person that learns by doing, and trying new stuff with the technologies I like is what makes life exciting for me. To complement the CF posts, I will probably also post on Windows Mobile-related stuff.

Finally, there will be some general posts on things that happen in my life, and I'll start off that category with a nice picture of my favorite place in the world...

posted on Tuesday, October 09, 2007 6:02:37 PM (E. South America Standard Time, UTC-03:00)  by Chris  #    Comments [0]