# Wednesday, July 08, 2009
A very nice thinking came by me from Rockford Lhotka. It is about future of OS. I quite agree with him. Soon we will have just thin client and everything will be in cloud.

http://www.lhotka.net/weblog/OSEvolution.aspx

Just think how many "cloud" things are you already using? A lot. Today is totally possible to have installed just a browser in you machine, and you can do (almost) everything.

posted on Wednesday, July 08, 2009 8:53:17 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Friday, June 12, 2009
I am looking for the clean, elegant and smart solution to remove namespaces from all XML elements. How would function to do that look like?

I have used StackOverflow. If you do not know this site, I can describe it as a really smart Q&A site, dedicated for programmers.

So I was searching for really great solution for removement of namespaces in XML. Based on one programmer answer I have created a solution which I really likes. You can clearly see, when you have to deal with tree data structure (which XML for sure is) recursion is simply the best approach to do anything with it:
private static XElement RemoveAllNamespaces(XElement xmlDocument)
{
    if (!xmlDocument.HasElements)
    {
        XElement xElement = new XElement(xmlDocument.Name.LocalName);
        xElement.Value = xmlDocument.Value;
        return xElement;
    }
    return new XElement(xmlDocument.Name.LocalName, 
xmlDocument.Elements().Select(el => RemoveAllNamespaces(el))); }
Do you likes? I love it. :)

I was totally convinced that exists some more smart .NET framework function, with which I could help. But I was wrong. The best .NET can do is something like this:
XmlDocument doc = new XmlDocument()
doc.Load(ms);
doc.DocumentElement.Attributes.RemoveAll();
All this function do, is to remove all attributes on root element only ... You could repeat this on every node with help of XPath, but since those selected nodes are immutable, this is little help.

posted on Friday, June 12, 2009 9:12:44 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Friday, June 05, 2009
Usually the explanation of object reference or pointer goes it is an address which reference something. Well in high level overview we can simplify this to that explanation, but today we well look the difference between the object reference and pointer and we well see why reference in not nearly the same thing as pointer.

Address
First we will look what the address is. Every data cell in memory have address, as every person have home address, basically that simple it is. Address just happen to be a property of some specific memory implementation, we could just have other way to access it.

Reference
Reference is really simple programming concept. It just reference to something. You have NO control over it. You can just reference and dereference it.

Pointer
Pointer is an abstract programming concept, which points somewhere and supports arithmetic operations. Strictly looking, pointer "per se" have no information, it just know where can find it. And you have control over it (arithmetic operations). What is connection between pointer and address? Well Pointer is not an address. Pointer is just implemented with address, because it just perfectly suits to what Pointer needs. To summarize, Pointer can do everything what can Reference plus more.

To better understanding I have made some simple diagrams, how looks those two concept in .NET:



posted on Friday, June 05, 2009 1:29:52 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Wednesday, June 03, 2009
I know, .NET 3.5 framework will soon became "old" framework, because .NET 4.0 is due to release. Anyway it is still the latest, and today we will look how to validate good old XML document with a given XML schema.

It the old days a XML validation took quite some code. For better understanding what I mean, look an XML validation article on CodeProject.

Now just look at this beauty:
        public bool CheckXmlAgainstGivenSchema(XmlHolder xmlHolder)
        {
            XDocument xmlDocument = XDocument.Parse(xmlHolder.XmlDocument);

            XmlSchemaSet xmlSchemaSet = new XmlSchemaSet();
            xmlSchemaSet.Add("myNamespace", XmlReader.Create(new StringReader(xmlHolder.XmlSchema)));

            bool isValid = true;
            xmlDocument.Validate(xmlSchemaSet, (obj, eventArgs) => { isValid = false; });

            return isValid;
        }
It is interesting that this small code snippet represent a lot of .NET 3.5 technology (LINQ to XML, Extension methods and Lamda expressions). This just show us how useful are those "new" concepts.

First we use XML manipulation class "XDocument", which allow us a really nice and smooth XML manipulation, compare to old XmlDocument. XDocument class have nice feature called "Validate", which turns out that this is just we have needed. :)

Validate method in an framework extension method and all it need is XML Schema, as you would expect of course and an event handler, which handle the situation if XML validation is failed.

We pass XML Schema as "XmlSchemaSet", this type is some kind of collection of the schemas. Validator just looks for a proper schema based on proper namespace and XML document elements. A passing delegate is nicely solved with lambda expression. Instead of it we could declare event handler and pass just a method reference (delegate).

posted on Wednesday, June 03, 2009 6:05:08 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Tuesday, June 02, 2009
I have added a Twitter counter for all you Twetties out there. If you would like to be informed about new blog posts, you will find there announcements, among other.

If you wish to be even more up to date, you can subscribe to the RSS feed. I have created one on the Feedburner is spite my blog already provide one (with feedburner you get nice counter and more control over feeds). RSS feed is a nice approach of reading blogs, since computer do the checking work for new content insted of reader.

UPDATE: Oh yeah, my home site, have been completely renewed over weekend. You can check it out. Currently is more or less boring, because it contains almost no content, really. But I have plans. :) I will not revel them completely, you can already see now I will have more "open" blog (not just about software development) on it. When it will something interesting happen, I will post it. Then I (will) have picture gallery, same applies here as for personal blog. And more (I hope). Stay tuned. :)

posted on Tuesday, June 02, 2009 9:54:15 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
Have you ever asked yourself, why C# string type works somehow different than other reference types?
  • First, when you declare them, you don't have to use a reserved word, which is used for reference type initialization - "new". You can also easily "overwrite"* them.
  • Second, when it is passed as a parameter to method, it does not reflect possible changes of this parameter inside a method (as reference types would normally do).
So what this animal really is? To explain string behaviour in deep, you have to know all about:
- immutability
- value type vs. reference types
- parameter passing
- C# reserved word "implicit"
- ...

All these interesting topic I will cover in the following days.

*As straight forwards as it may seems, we will see this is not really true.

posted on Tuesday, June 02, 2009 1:09:08 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Wednesday, May 27, 2009
I always wish to have my own e-mail domain space. You know, something like yourName@yourDomain. It just rulez. :)

Well a lot of things is nice to have, but you have to ask yourself is it feasible? Optimal? The right question about having your own e-mail domain is: Is this optimal?

If you think about it, you will figure out that even nearly is not. First you have to have a server that's mean the hardware (even in virtual machine it demand some hardware resources), a fail safe one. It demands power, power costs ... And this is just beginning. Then you have to install and configure SMTP server, anti virus, anti spam software ... And all of this you have to maintain, backup ... If you sum up, despite if you are an computer geek. You do not want your own email server at home. It just takes too much resources and it is just too unreliable. Period.

But we still want our "own e-mail". What to do? Well it turns out that Google have an answer (as almost always). You surely hear about Google apps. It perfectly solve our problem. It provide e-mail address with our domain on well tested Gmail infrastructure. All you have to to is to play a little with CNAME settings at your domain provider and that's it.

It is perfect example of cloud computing service. It is personalized and it persist in internet realm, somewhere.

From now on I am officially in the cloud, you can reach me at peter@stegnar.com.

PS: You can start here. You can choose two account types. For normal usage, standard version will do.

posted on Wednesday, May 27, 2009 6:46:19 PM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Tuesday, May 12, 2009
It just come out - Stack Overflow DevDays conference will be held in couple of cities:

October 19 San Francisco
October 21 Seattle
October 23 Toronto
October 26 Washington, DC
October 28 London

We Europeans have only one choice- London. I have already make a reservation and so should you! I believe this will be great conference.

Right now about 2h after Joel's announcement are 231 and 14 tickets available of 300. In less then one day there will be none, when it seeds out (what I am actually doing right now).

posted on Tuesday, May 12, 2009 9:52:31 PM (Central European Daylight Time, UTC+02:00)  #    Comments [1] Trackback
# Monday, May 11, 2009
Most application need some kind of localization, really. Today I will represent one simple possible solution for this in ASP.NET.

This localization is based on .NET resources (.resx). As name tells us resource is, well (re)source of something, typically strings. So as it looks like this resource file seems like perfect for our localization problem.

Resource file is XML base file type, it looks like this:


It also exist a resource editor, where you can easily edit resources:



Let's say our web application need localization support for two languages, English (default) and Slovene. First we create resource file for each supported language and for default one. So we create something like that:


Here we have a default support language (English) and other supported languages (for our case Slovene). You have to be careful with naming - naming convention is resource_name.[language code].resx.

And to the best part - code. All you have to is to set a CultureInfo to a current thread, and ASP.NET will automatically resolve a proper resource file. You can set in in your ASP.NET application file (Global.asax) like:
 System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(cultureName);
Well, you a done, with localization of you application!

All is left is an actual use of it. Here you have one example:
 <asp:Literal runat="server" Text="<%$ Resources:Resource, strForm1Hello %>"/>
You can see I use build-in ASP.NET functionallity of resource reading instead of hard-coded string. Which is anyway good practice not to have it.


posted on Monday, May 11, 2009 7:59:23 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback
# Saturday, May 09, 2009
Yesterday I was debugging an ASP.NET application based on database (MS SQL Server). I was getting a strange error:
EXECUTE permission denied on object 'sp_sdidebug', database 'master', owner 'dbo'.
Well store procedure 'sp_sdidebug', enable debugging on SQL Server. Since this SP is in "master" database, you have to have proper access and execute rights on this master DB.

posted on Saturday, May 09, 2009 8:41:15 AM (Central European Daylight Time, UTC+02:00)  #    Comments [0] Trackback