Monday, 30 April 2007

Sunday, 29 April 2007

The Portughese restaurant Fado

Update: I've heard that Fado has now been closed. It was nice while it lasted. Too bad I didn't have the chance to go again a few times before it went away.


Today we went with my parents at a Portuguese restaurant called Fado. I have to say I was pleasantly surprised by the cuteness of the place and the service was not bad. The food was bravely innovative, too, and tasty. Actually, it was more on my own taste than most of the restaurants I've been to, including Chinese. Well, I like Chinese more, but I can't cook Chinese, that's what I meant :-P

Anyway, if you happen to search for an intimate restaurant in Bucharest, with interesting food and a waiter that knows suspiciously much about the food, up to the point where he recommends you what is better than your original idea, then Fado is the place for you.

This is a link, in Romanian, with more details: Restaurant Fado

Thursday, 26 April 2007

Saving Page ViewState out of the page!

If you look for solutions to get rid of huge ViewStates from your pages you will get a lot of people telling you to override SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium in your pages and do complicated stuff like keeping the ViewState in the Cache or in a database, calculating strange keys, etc.

No more! Net 2.0 has something called a PageStatePersister. It is an abstract class and every Page has one. In case no override occurs, the default is a HiddenFieldPageStatePersister, but you can also use the provided SessionPageStatePersister like this:
protected override PageStatePersister PageStatePersister
{
get
{
return new SessionPageStatePersister(this);
}
}


And that's it! It works with Ajax and UpdatePanel, too.

However, this is no "Silver Bullet", as the SessionPageStatePersister will have issues with multiple windows open with the same session (like pop up windows) as exampled in this nice article. Also check out this situation when, during Ajax callbacks, a full ViewState is returned due to the ever troublesome ImageButtons.

There is no reason not to create your own PageStatePersister, though. The abstract class is public (not internal and sealed as Microsoft likes their most useful classes) and you can inherit it. You can even store the state in the Cache! :)

A very comprehensive article on ViewState is here.

Wednesday, 25 April 2007

Buggy DataTable Select strikes again: Safe Filtering without Sorting

A while ago I wrote a post about the bug in the DataTable.Select method with columns with comma in their names.

Today I discovered another bug, when using DataTable.Select with an empty sort string, but not an empty filter string, there is an implicit sorting by the first column. Short example: a DataTable with a single column called "words" containing values c,b,a,d , when Selected with a filter like "words is not null" and a null or empty sort string, will return a,b,c,d.

The only solution for this was to drop DataTable.Select entirely and use DataView, with its NET 2.0 method DataView.ToTable. So the code to take a DataTable and return the filtered and sorted table would look like this:
public static DataTable Select(DataTable table, string filter, string sort)
{
if (table == null) return null;
var dv=new DataView(table);
dv.RowStateFilter=DataViewRowState.CurrentRows;
dv.RowFilter = filter;
dv.Sort = sort;
return dv.ToTable();
}

But DataView has the same problem with columns with comma in their names. We solve it in the same way we solved it in the previous post: we change the column names, the sort and filter strings, we select, then we change the column names back:
public static DataTable SelectSafe(this DataTable table, string filter, string sort)
{
var originalColumnNames = new Dictionary<string, string>();

foreach (DataColumn dc in table.Columns)
{
if (dc.ColumnName.IndexOf(',') > -1)
{
var columnName = dc.ColumnName;
var safeColumnName = columnName.Replace(",", ";");
var reg = new Regex(Regex.Escape("[" + columnName + "]"), RegexOptions.IgnoreCase);
dc.ColumnName = safeColumnName;
if (!String.IsNullOrEmpty(filter)) {
filter = reg.Replace(filter, "[" + safeColumnName + "]");
}
if (!String.IsNullOrEmpty(sort)) {
sort = reg.Replace(sort, "[" + safeColumnName + "]");
}
originalColumnNames[safeColumnName] = columnName;
}
}

var newTable = Select(table, filter, sort);

foreach (KeyValuePair<string, string> pair in originalColumnNames)
{
table.Columns[pair.Key].ColumnName = pair.Value;
newTable.Columns[pair.Key].ColumnName = pair.Value;
}
return newTable;
}

Tuesday, 24 April 2007

Monday, 23 April 2007

Ariel Basescu

I know, the third entry in my blog about Basescu doesn't say much about my IQ or style, yet now I know what I felt I needed to say, but didn't realise what it was. It is the similarity between the case of Traian Basescu and Ariel Constantinof.

It is amazing still that these two similar stories happened in the same time. Indeed, Basescu is like a high school student who is suspended from the school on the basis of his behaviour, without anyone really knowing if it is "kosher" to do so. Do the high school owners have the right to expel Basescu or is this a financially motivated blunder? Both of them are big mouthed smart asses, without being really malevolent, yet being rather naive. Just as Basescu, Ariel gets a lot of sympathy from bloggers and radio hosts (radio bloggers?) everywhere, but without any true support. On each of the blog pages that describe his ordeal there are hundreds of people that offer their moral support, but really not much else. Just as Ariel, Basescu gets only a bunch of people to at least voice their anger to the school directors.

Can the case of Ariel Constantinoff serve as a simulation of what will happen to the country in a few months? I don't know, but I really like Ariel more than Basescu. And at least he has parents, the chance to go to another school. For crying out loud, he's a kid! Teachers, leave the kids alone! But who will find enough sympathy in their hearts for an old, bald, shunned ex president who didn't yet catch on with reality?

That's it! No more Basescu for a while on this blog ;)