27
Apr

ASP.Net AJAX Extensions, GetPostBackEventReference And Custom Controls

If you’ve a piece of code similar to this one, and try to use the control inside an UpdatePanel then you might be surprised to see that triggering that event will in fact do a complete PostBack of the page (read Refresh-like-Postback):

public override void Render(HtmlTextWriter writer)
{
Response.Write("Button“, Page.ClientScript.GetPostBackEventReference(this, “onclick”));
}

The reason is simple but not at all obvious, the ASP.Net AJAX framework requires you to setup a valid ID on the element like this:

public override void Render(HtmlTextWriter writer)
{
Response.Write("Button“, Page.ClientScript.GetPostBackEventReference(this, “onclick”), ClientID);
}

Nice coding :)

convert this post to pdf.
03
Apr

Fedora 8 and the Sudo command

Today I was checking out the latest mono from subversion and something funny was happening, I wasn’t able to install the builds if I used sudo make install, the error I was getting was a bit different from package to package but always looked something like:

/usr/local/bin/gacutil /i monodoc.dll /f /package monodoc /gacdir /usr/local/lib /root /usr/local/lib
xdg-open: unexpected option ‘-q’
Try ‘xdg-open –help’ for more information.
Failure adding assembly monodoc.dll to the cache: Attempt to install an assembly without a strong name.

The first thing that came to my mind was that the assembly wasn’t strong named, which I discarded after trying a simple make install without sudo and as a normal user. Then, I found that if I did a su and then the make install it worked just fine, but if still as root I did sudo make install it all failed…

Turns out that Fedora 8 sudo package uses some new flags to improve security, something previous versions didn’t had enabled because I don’t remember to ever have this sort of problems. To solve this I needed to edit /etc/sudoers and comment the lines that said Defaults env_reset and Defaults env_keep.

What those 2 flags do is to destroy the environment variables when a new “sudoed” session is created, some of them seem to be avoiding some commands from working correctly… anyway, its just one more little configuration to remember to do when I install fedora.

convert this post to pdf.
02
Apr

New Laptop - HP dv6799ep - (Near) Perfect Linux Compability

I’ve a new laptop, an HP dv6799ep (dv6700 series special edition). The reason I choose this exact version was the 4GB of RAM and the Intel 9300 (dual core, 2.5GHz, FSB 800MHz and 6MB cache) which is a great combination to develop on the road and use virtualization .

My main concern with a new laptop was that I never been able to get a fully Linux compatible laptop. I’ve had 2 Toshiba and 1 Acer and none of them fully supported Linux, usually the problem was suspension and hibernation. Sure, I’ve been able to work around this problem with Suspend2 (now called TuxOnIce) but that implied custom kernel builds until they provided a nice Fedora repository with those kernels.

The weak point with this laptop is the graphics card, a NVidia 8400GS which is not really powerful but works fine for my needs. Of course I needed to install the proprietary NVidia drivers which is painless if you simply use Livna. On a side note about Livna, its FAQ provided some information on how to install Flash for 64 bits versions of Fedora but lacks a small note telling people to use the Adobe Yum repository. After adding the Adobe repository just follow the instructions normally.

After all the basic setup I started to see what works and what doesn’t:

  • Suspend and Hibernate work flawlessly after you install the NVidia drivers and without the 3D desktop effects (Compiz Fusion) enabled - something I wish to track down and fix because those 3D effects are very cool
  • Audio, Mouse, Webcam and Bluetooth seem to be fully working without any special configurations
  • Wireless works out-the-box
  • Some hot keys didn’t  work out-the-box because they weren’t assigned in the gnome shortcuts, something you should always configure because of the mute and volume controls

I then also managed to boot my pre-installed Vista from within VMWare. To make it work I had to create a new Virtual Machine under VMWare Server and then to edit its vmx and vmdx files to replace all “scsi” to “ide” and also the scsi mode from lsci to ide. After than, booting Vista went smooth. When Vista is booted and starts detecting new hardware simply cancel all hardware installations and install the VMWare Tools. Needless to say that you should be very carefull not to boot your host OS from the grub selector, neither try to suspend Vista inside the VM and boot it without VMWare… the usual “think a bit before you try” stuff. I’m currently looking for a floppy disk image that will enable my VMWare to skip grub directly to Vista.

All in all, I’m very very happy by this laptop, its really fast and pretty. Feels good not to have too many hacks to fix issues this time :)

convert this post to pdf.
01
Apr

How To: Random DateTime(s)

I had a small database project that needed about a million records to stress test its performance and the front office application. For some reason, working with DateTime in C# is not always straightforward, and you might need some research and trial & errors until you can get something as simple as random date/time generation working. I’ve implemented a nice and simple method to help anyone and specially remember me if I ever need it again:

public DateTime GetRandomDate(DateTime from, DateTime to)
{
    TimeSpan range = new TimeSpan(to.Ticks - from.Ticks);
    return from + new TimeSpan((long) (range.Ticks * rnd.NextDouble()));
}
convert this post to pdf.
22
Mar

SqlServer Connection Problems With Mono

If, like me, you use virtual machines and try to connect from Mono to SqlServer you might run into some problems. The top things I’ve learned to check are:

  1. Mono doesn’t support SqlServer 2000 below SP3 - this is relatively well documented this Mono page but still is hard to detect since the error message doesn’t give any clue about the problem.
  2. If you’re using some complex networking schemes, like bridged networks, beware of a Mono bug on Dns.GetHostEntry. Unlike Microsoft implementation, Mono ignores the IP you provide and tries to resolve the machine IP by itself. In some cases, specially when using virtual machines, the IP returned will be 127.0.0.1 breaking hipotesis of connecting to the correct machine. I’ve tried to follow Microsoft implementation and created a bug report and patch.
  3. If you’re using slow networks or slow virtual machines (resulting in slow network) you might also want to beware of yet another Mono bug. When connecting to a SqlServer using instance names (SERVER\INSTANCE) Mono needs to connect to Microsoft SqlServer Monitor Browser to get the correct port for that instance. Current Mono implementation waits 100ms to the response, which is very low on slow network/virtual machines. I’ve implemented a patch which increases this time limit to 15 seconds, giving plenty of time to network delays and even some server restart case scenarios which could be exposed in real-world application scenarios. The bug report and patch.

I’ve posted both bugs/patches on bugzilla and mailed them to the mailing list but noone answered :( Hope this helps anyone in trouble.

convert this post to pdf.
21
Mar

Time Sensitive Data

One of my favorite gadgets is Gullible Info, its always on my Google Home Page. Its displays things like:

«Japanese scientists have created a mechanical version of a human hand with similar motor skills; it requires a computer 1,500 times more powerful than a standard desktop computer to function.»

The problem with this is that this kind of information takes a month to be outdated and becomes misleading in some cases. In this case, I don’t know when the “Japanese scientists” developed the mechanical human hand, so I can’t really be sure how many nowadays standard desktops would be needed. Sure, this isn’t a real deal to me because I’m not into robotics R&D but, shouldn’t this kind of information be updated? If so, how?

Another example of this problem is when you read some blog post or news article, it usually says something like “Today…”. Well, we do have the date on the article, but as shown by the first example, that isn’t always enough to place the entire data into context. It is also obvious that we can’t expect people to keep updating each and every article but still, somethings become more like history facts than news and need to be placed in context so future kids can really understand the data.

Taking the dates as a simple example, what we need is a tool to update articles daily so that it will show dates accordingly: today, yesterday, this [weekday], last week, etc… and eventually “on [month], [year]“. This is pretty simple, and in fact I would be surprised if there aren’t tools and content management software already doing this for dates. Yet, I never noticed any evidence of its existence.

Another case, and the reason for the example in this article, is much more complex. A computer knows dates very well, but how can it know whats the power of “standard computers” today? And how can it compare them to the article’s computers? To be fair, it is near impossible, we can’t flatly compare 2 nowadays processors because each technology advancement provides improvement over some tasks but not another. Still, a pretty close estimate can be done, for example, using the number of instructions per second.

In this case, this kind of data can be easily collected, a bot like google’s indexes many computer stores, so it can calculate the “standard” computer for today and also has access to the processor manufacturers homepages, enabling a very approximate estimate of nowadays standard computers power. In the end, all that is needed is a webservice to provide this kind of data in a way that we can easily access and update articles with it, but how do we write them?

Writing this kind of article seems complex, it would require programming at first, but not some tools are extended to support this features. In my idea, something like Microsoft Word or TinyMce, which I’m using to write this article, can be extended to detect dates (or date references like “yesterday”) and change them so they can be updated by the article engine in use. Somethings need to be updated more often that others, for example, dates need to be updated once a day, or, since they are actually quite easily calculated they can be calculated on the fly.

On complex cases like “how many nowadays computers are needed to handle that mechanical hand?” we would need some more work. To start with, the editor wouldn’t be able to detect what is time-context sensitive data, so we would need to select it and click a button to edit the preferences to that piece of information. In this particular example, I believe the best way to setup the data would be to create an “Excel”-like formula, using the webservices that would provided updated date. If at the time of the article the writer would check the webservice to the actual power of one standard PC, he could easily produce a formula to change it whenever it was outdated.

At last, a standard computer power isn’t updated daily, its something like once a month, to either the writer could setup the update time or even the webservice itself would provide it. At a best case scenario, something like RSS feeds could be used to let the article engine know there were some updates.

Well, I believe that I made my idea clear, a mega database of some time sensitive data could help improve our understanding of history when we read something on the internet. Widespread of this kind of tools would enable even more historical data to be stored and used by future generations, or even ourselves, without the risk of misunderstandings related to different technological or social contexts to name a few.

convert this post to pdf.
30
Dec

Seamless But Not There Yet!

I’ve been trying Virtual Box to virtualize a Windows box hosted on my laptop’s Ubuntu. One of the flag features of Virtual Box is the integrated seamless windows mode. This is not really a new idea, it has been implemented in VNC for a while, a standalone application called SharedAppVNC and some others. Now it the time virtualization software to be trying to implement this concept Parallels was the first and VMWare seems to have completed it and its on beta.

This feature is one of the things I’ve tried for a long time. Its good to see some progress but I think there is something wrogn with the approach all the players are using. I believe there should be integration with the host desktop in a way that you can not only fell the guest operation system integrated into the host but still know they are separated. For this I would create an applet to integrate the guest “start”/”Applications” menu into the host start menu. Also the running applications should appear on the host taskbar as well as the system trays would be integrated the same way.

As I’ve tried in the past to implement the seamless windows feature (didn’t reach an acceptable level to advance to the integration part because I lack the knowledge to implement a Windows video driver) I know this isn’t an easy task. There are several problems starting with the need to implement a graphics card driver to be able to capture the windows. The Windows API gives enough data in most cases to get the windows coordinates, dimentions and transparency maps but copying the painted graphics is painful and slow. Still, there are already some of those drivers, most from VNC projects that provide good levels of performance.

The next problem is the non-server Windows architecture designer to be single-session. This fact proves to be problematic because it makes it difficult to correctly separate some windows from another. It also disables some methods that could be used as a workarround like creating a session for each application thus isolating the windows.

All in all, we all know Windows hasn’t been developed to this kind of stuff. But beeing Microsoft commited to the virtualization technologies it would be appreciated if this come as a native feature just like its a X11 one. I believe this is one place where Microsoft could be once again ahead of Linux and define a standard by which remote desktops could be integrated into each other. Imagine beeing able to be connected to all your machines, no matter what OS, under the same desktop… would be simply amazing wouldn’t it?

convert this post to pdf.
13
Nov

Driverless Gadgets

One of the most boring things when I buy some new keyboard or mouse is that they all include a CD with some software. Apart from the manual and somtimes an (useless) application the drivers inside add little to the default Windows/Linux drivers. At the same time I can buy a pen for 10€ or less, I can even find several gadgets with integrated memory even when that has nothing todo with the gadget functionality.

This makes me wonder why there aren’t more gadgets (the only I know is my 3G modem) that include the drivers natively in the gadget. Wouldn’t it be great if your graphics card, scanner, printer, mice and keyboards all had this without the need for CDs that pile up and you never find if you need them again? In fact a CD with drivers noadays is totaly worthless, manufacturers release updates for their drivers every 6 months or so… what am I going to do? Burn new CDs for every new release?

What I’m thinking is totaly possible within the hardware constraits we’ve today and with some standards and more or less effort between OS and hardware manufacturers this could open a whole new era to drivers. This could make it easier and more attractive to hardware manufacturers to produce Linux drivers… wouldn’t it be just great?

convert this post to pdf.
03
Oct

Microsoft Is Releasing .Net 3.5 Core Libraries Source Code

No more Refletor. Now Visual Studio 2008 will enable you to debug and see the core .Net source making our life easier when trying to understand the “Voodoo Inside”. Not exactly Open Source and doesn’t include the VM or compilers but still an important move towards compatibility between implementations.

Initially Microsoft will release the source (comments included) of the following major core components of .Net:

  • System
  • System.IO
  • System.Collections
  • System.Configuration
  • System.Threading
  • System.Net
  • System.Security
  • System.Runtime
  • System.Text
  • … other major core components …
  • System.Web (ASP.Net)
  • System.Windows and System.Windows.Forms (Windows Presentation Foudation and Windows Forms)
  • System.Data (ADO.Net)
  • System.Xml

Excluded for a few months are the WCF (Windows Communication Foundation), Workflow and LINQ but it is planned.

The source will be licensed under the Microsoft Reference License (MS-RL) and available to download as a standard install package. You’ll be able to browse and edit the files in any editor of your choice but integration with Visual Studio 2008 will be provided.

You can read a bit more here as well as check the nice screenshots of the Visual Studio 2008 debugging integration.

convert this post to pdf.
25
Sep

Mono.Mozilla.Browser On Windows

Update: Andreia has posted some really useful tips and “fixes to my approach that might interrest you too. Check them.

A few weeks ago Andreia (a Portuguese like me :)) published in her blog about the latest improvements she has made towards a MWF WebBrowser control. I’m sure that, like me, many people become excited about this and gave it a try. In my case, I trust people when they say something is working on the Mono tree as long as its on Linux systems, so I wanted to test it on Windows and Andreia told me it was entirely possible. So hands to work and here is my progress so far, a bit reordered from my original path… for your sanity.

Prerequisites

First step is to read a bit about Mozilla Build Prerequisites and in my case, because I already had Visual Studio .Net 2003 with C#/C++ support and Visual Studio .Net 2005 with C#, was to get the pre-built Win Tools. You need to extract it somewhere and run one of the “start-*.bat” files according to your main Visual Studio. I did nothing more than that, it is suggested by the Mozilla Build Prerequisites page that you setup a variable and install it, I didn’t do it and it worked fine.

Next step is to get the mozembed Mono code. It can be obtained in several ways, including the Subversion Mono repository. Please note that is you do use Subversion to get the code you might have some problems, I use TortoiseSVN subversion and the “_svn” feature but maybe it would happen with “.svn” too, so I needed to delete the _svn folders from inside the mozembed/build directory - the correct thing to do is to checkout the code to any place in your system and then export it. Another noteworthy thing is that you need to export/place the mozembed in a path without spaces or special chars, something like c:\mozembed, because Mozilla builds on windows don’t handle spaces in paths correctly.

Once you’ve your mozembed tree the first step is to prepare some headers and extra files. This is done using the shell provided by the Mozilla Win Tools package. Just “cd c:\mozembed\build”. You need to get xulrunner and xulrunner sdk files extracted here, and for that there is a script called get-gecko-sdk.sh in the build folder that won’t work on Windows. Instead go to this Mozilla ftp folder, download and extract win32/xulrunner-1.8.1.3.en-US.win32.zip and sdk/xulrunner-1.8.1.3.en-US.win32.sdk.zip files into your mozembed/build folder. You also need libIDL-0.6.dll and glib-1.2.dll in that folder, these files can be found in the Mozilla Win Tools mozilla-build\moztools-180compat\bin folder. After that you just do “make” in the shell and all the headers shall be created and places in the correct folders.

Building xulbrowser.dll

Now its time to open the solution, mozembed/xulbrowser/xulbrowser.sln or the 2k5 version according to your Visual Studio version. In my case I removed the other projects from the solution until all I had left was the xulbrowser project. It also happens that the current (2003) solution lacks some files, so after the solution is open you need to “Add existing file..” and add this files: SecurityWarningDialog.cpp PromptService.cpp LocationProvider.cpp SecurityWarningDialog.h and PromptService.hLocationProvider.h; all are in the xulbrowser project directory.

Next, you open the project properties “C/C++ > Include Directories” and add C:\mozembed\build\gecko-sdk\include and C:\mozembed\build\include. The same goes to “Linker > Additional Library Directories” where you need to add c:\mozembed\build\lib. Finally your project should be ready to build except for a missing file that I really don’t understand where it is supposed to come from… so I just googled for “nsAppDirectoryServiceDefs.h” and downloaded the first that I saw. Place it in one of the include paths.

You should now have a complete xulbrowser.dll in the project folder.

Creating a Test application

Now, we need to get Mono.Mozilla, in my case from the Subversion Mono repository. Just open and build it, the only problem I came across was the Mono Assembly key that I removed. After this we’ve most of whats needed to run a Mozilla web browser in our applications, but we still lack a control implementation to be used. As I’m very lazy I just shortcutted it and got the Mono one from here. What we need is WebBrowser.cs and WebBrowserBase.cs.

I created a new Windows.Forms project in Visual Studio and added the 2 files (WebBrowser.cs and WebBrowserBase.cs) to it. The files obviously won’t build out-the-box, you need to remove or deactivate those MonoTODO attributes (a find and replace of “[MonoTODO” by “//[MonoTODO”) and change the namespace to something else, in my case I just appended a “1″ to it leaving me with System.Windows.Forms1.

I then edited the form Visual Studio generated when creating the project and added a WebBrowser control from the toolbox and edited the URL property to point to “http://whatsmyuseragent.com/”. After that all I needed was to edit the code and change the namespace of the control to the new namespace assigned to the WebBrowser.cs implementation.

Lastly, your application should build but not run correctly. You need to place xulbrowser.dll next to the .exe of your application, but that leads to an ungly memory exception. There are some files missing and I’m not sure which files, but copying the .exe, Mono.Browser.dll and xulbrowser.dll to the c:\mozembed/build/xulrunner folder leaves you with a running application.

Results

screen.jpg

This is a nice result as long as it can be seen in the screenshot but the truth is that its not working except for clicks and selecting text. I can’t input any text to textboxes or anything else. But hey! At least its mozilla rendering it! Now all we need is bug fixing ;)

This is of course a fast and hackish way of getting things to work, but I hope its a start and soon we can have something really usefull to developers who whish to use Mozilla from Windows.Forms applications.

convert this post to pdf.