Thursday, April 30, 2009

How to add a control to the header of a UltraWebGrid Infragistics control

I found this link:

http://devquirks.com/SelectAllGridColumn.php

But note that the click event does not get fired on the server.

Office 2007 horribly slow?

Because of the search integration within it, I know for a fact that
office 2007 makes your PC very slow. I also know that when you have
many emails in your personal folders, outlook 2007 is the slowest app
on the planet.

Announcing a solution! - day before yesterday Microsoft released a
slew of updates including office 2007 SP2, SQL server 2008 sp1,
sharepoint sp2, etc.

This resolves all performance issues with all these software. The
major improvements are in the performance of office 2007, IE 8 &
sharepoint.

Sharepoint was a crawler till now. It became a corvette after the
update.

Wednesday, April 29, 2009

One feature no .NET OR/M tool provides

Here's an interesting tidbit. There is one thing my OR/M tool can do which no other OR/M tool in the world can do - mine is the only one which lets you create entity, criteria and interface classes for a complex stored procedure which contains insert statements, temp tables, etc but still returns a resultset.

Every other OR/M tool analyzes the stored proc and says it is an action stored proc. I don't analyze the stored procs automatically, I let the user enter the parameters, run the query and then depending on the resultset, I generate the criteria, entity and interface classes.

So, it beats LLBLGenPro, LINQ to SQL and Entity Framework. None of them support these stored proecedures!!!

It is a shame guys!!

Response to: Stored Procedures Vs Dynamic Queries

 
I have a difference of opinion here, because I have also built an ORM mapper/ code generator before. My opinion is that, the whole area of dynamic queries being faster and better than stored procedures only makes sense in the context of having stored procedures for specific tables. Which means, when we have a tool which directly operates against tables then it makes sense to have stored procedures vs dynamic queries, and there dynamic queries can be recommended because we are only talking in the context of a single table.
 
So a C# developer can write the query in C# and have a better dynamic query than the code calling a generic stored procedure because it is generic.
 
However, in big, real world applications, nobody works in the context of a single table all the time. Mostly, what we retrieve spans multiple tables and complex queries. What we insert may also span multiple tables. So, it becomes more difficult for a C# developer to write a complex query like that in C# and still have it as optimized.
 
Because of this, in such situations, stored procedures will actually work better, faster, and have lesser chances of error because it is written by a database guy, and it is easier to write complex queries in SQL (notwithstanding the newer advancements in LINQ).
 
So, I think every ORM tool must fully support stored procedure code generation, and stored procedures are fully valid in these cases.

Monday, April 27, 2009

How to handle multiple windows with different states in a web application

I know a lot of people have written a lot of ways in which to do it. But, I have a way which I think works when you actually consider that a new window is a "GET" on the server. Most of the implementations floating around are for "POST". The really difficult problem to crack is that, there is no way for the server to know whether the "GET" which is being processed is a page refresh request OR a File >> New Window Request. There are two ways of doing this, depending upon which kind of application you are:

The Easy Way

The easy way is only possible when your application opens in a full window mode (business application), and you do not show anything like the address bar (even if it is shown, this has to be read only), and you do not show any browser buttons OR right clicks.

This is simple:

1. Every time a window is opened, have a window identifier in the query string.
2. Use this identifier on the server as a part of the key while storing anything in any shared storage for the user (like session or cache).
3. This ensures that for different windows, the server stores the information with different keys.

This works very, very well. Users like to use the cool "New Window" icon to open a new window. 

The Difficult Way

I went through a struggle to get this going because, in a regular browser application, the user can hit the browser buttons and also, change the query string. So, there is no apparent way to handle all these events and ensure that we get a unique window key when the user presses, Page >> New Window, because there is no way to detect whether the user did that from the client.

This is how I finally did it:

1. Used a base class to do all the processing.
2. Uses logic similar to method 1 (first section) for window identifiers.
3. What I did was ensure that before every user request from the client, an AJAX call is made to the server to update a variable.
4. It is possible to detect page refreshes done by the user through any mechanism using the below:

        window.onbeforeunload = function()
    {
        if((window.event.clientX<0) || (window.event.clientY<0))
        {
            HandlePageRefreshButtonClick(); >> Make Ajax call inside this function, and then in callback event.ReturnValue = true so that refresh will happen
        }
        else 
        {
            HandleRightClickPageRefreshClick();
        }
    }

5. So, page refresh is covered, for any actions from your page, you can do the AJAX call to update the server FLAG before doing the actual GET request.
6. Any request which goes to the server which does not have the FLAG set will thus be the "NEW WINDOW OPEN" request. This can be handled, and you can redirect the user to the same url but with a new window identifier.
7. Clear the FLAG at the end of every page load, so that it is set only before a new request comes from the server.
8. This means, before you redirect also, you need to set the FLAG in the session. An easy way is to handle all redirect methods through a static method in your class rather than the ASP.NET Response object.
9. Ensure that all links in all pages call a JS method, and this method makes the AJAX call before you open a new window or go to another page. This can again be abstracted into a generic JS class.
10. On the server, to see whether you need to redirect with a new window identifier:
         a. Ignore for login page.
         b. Ignore is page is posted back.
         c. If FLAG is null, user did not request the window explicitly - so handle this case.

11. If a user modifies the window key manually, then handle that case by again generating a new window identifier on the server and redirecting to the same page with the new identifier.
12. You can handle Ctrl + N also, and ensure before page refresh to make AJAX call.
13. Remember to use ALL session variables WITH the window identifier as the key, otherwise, the session will leak to the other windows open.
14. If you encrypt the query string, remember you will not find it easy to send new values through query strings anymore. Remember to allow for url decode and encode after encryption and before decryption.
15. Even the script manager used to have the web service reference on every page can be injected into every page from the base page

The method is kind of complex, but it does work for 2 GETs. I have tested thoroughly.

Saturday, April 25, 2009

Why Modern Education might lead to the demise of civilization

I was thinking about the way in which modern education is taught in schools today. And I realize that the way in which we ram down theorems and rules actually harms the ability of children to innovate. The problem is that instead of discovering how stuff is done, they are taught in an hour what might have taken someone years to find out in an earlier age.

What is the problem with this?
- There is so much indoctrination that we get trapped within the boundaries of what we have been taught or what we have read. How can we think out of the box, when our mental model itself is made of the box?

I mean that, if a person has not done a PHD, he might be able to find out a better solution than a PHD simply because he is not thinking confined to the boundaries of what he has learnt. He may be wrong most of the time, but there is a 1% chance he might come up with the next theory of relativity.

Maybe Einstein was not intelligent – he was very poor in school, maybe he learned so less that, in the process of thinking based on his own thought model, he was able to come up with something different. Maybe no-one else has come up with something as big as the theory of relativity because they have learned too much?

I have seen toppers in class unable to think straight when confronted with a problem – because they are very good at learning what someone else had figured out, but never learned how to figure out something on their own. So, I say, the more we learn, the more we bind ourselves in mental shackles.

Why has India never come up with an Einstein or a Thomas Alva Edison?
Because there is too much indoctrination, too much mugging up, too much stuffing the brain with stuff other people struggled to understand over the years and came up with thinking from scratch.

We tend to forget that education, like software should be tailored to the human brain, and not the other way around.

If a student fails in class, maybe it is not the failure of the student. Maybe it is the failure of the education system which is not able to get through to the most advanced computer ever designed – the human brain.

Maybe the student who fails is the best suited to come up with the brilliant innovation 10 years later, and the topper is destined to be struggling trying to resolve a problem nobody wants to solve. An interesting way to look at it is that, when a software crashes a computer, we do not blame the computer – we blame the software. If education is “software”, and the computer is the very different, unique, special human brain – why is the brain said to have failed?

If we understand this, maybe we won’t collapse like the older civilizations have in the past...

Thursday, April 23, 2009

The problem with Microsoft

Somewhere down the way, Microsoft lost its soul. I now see it as a “has been” company where they copy whatever is cool out there and then announce new projects which they drop like hot balls after sometime. It is really pathetic what they have become. The only thing I like about Microsoft Software is their Visual Studio suite, but as everyone knows even though coding is easier, the end product is not.

Windows applications are slow, and WPF is a farce. Even silver light which is based on it is pathetic. I really wish MS had spent the time developing Script# into a real platform than wasting time on WPF. It would have been lovely to finally have an object oriented way to write client script for browsers. I love the fact that script# compiled to JavaScript. It is a really awesome idea which has been ignored by Microsoft because of vested interests, rather than technology.

I say this time and again and I will re-iterate once more, the failure of Microsoft to develop a proper phone OS with so much time on their hands, and the way Apple came up with the iPhone OS, and how MS shamelessly tries to emulate it now, so many years later.

C’mon... Apple has to show every other lousy phone OS maker that it makes sense to have a phone where its firmware can be updated for new releases and patches. This is not high science – it is purely what happens when technologists run a company to make better software compared to a bunch of business people trying to figure out how to crawl their way around by spending less and utilizing existing resources rather than coming up with a better solution which fits the problem.

The solution should fit the problem and not the other way around.

Software was made for humans, and not the other way around.....