Saturday, November 24, 2007

I had an idea back in the 80's of a portable book that would have a great screen, that would be connected, that had access to all the books. I thought that the biggest obstacle was to get the authors (or rather the publishers) to believe in electronic books, and that the copyrights was my biggest challenge. Hey, I even started the drawings for the patent (ok, give me some slack, I was young then), but I never actually made any serious attempt. Then, I bought my first handheld, a Casio Cassiopeia E10, I thought that the screen wasn't great and it wasn't connected but still, I was amazed. I showed it to my friend Andy, and he was amazed, and that was almost 10 years ago.

Now, when I look at the Kindle, I see that Jeff Bezos has another idea that is far from new, but he has some points. He aimed for a great screen and he aimed for connectivity. I still think that he missed out on the first one (even if a bunch of authors say it's great, I'll wait for the color display ;-)), but he really got it on the second. I agree with Rob Tiffany on all points, but as a WM developer, it's the connectivity that gets me. I'm tired of reading all the connectivity small print ("...Connectivity and synchronization may require separately purchased equipment and/or wireless products...") on many WM pages. On an event back in 2000 I asked if Microsoft would enter the operator business because I believed (and still do) that the operators don't understand what an open wireless Internet can bring to everyone (it doesn't have to be free, but free us from abuse). I still ask the same question when I see they offer great devices without specifying the operating system. What is that? If I could reformat any phone (Nokia, etc) and install WM, they did have to inform me, but now I'm almost always stuck with what the manufacturer and/or the operator put in there. How could the mobile phone industry go so wrong?

Please Microsoft, the operators is not doing their job, let us free, get our users an open Internet...

posted on Saturday, November 24, 2007 1:01:20 AM (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]