GWT - Unicode Characters

December 2nd, 2009

Sometimes simple 1 minute tasks make you stop and spend 20 minutes figuring solution out.

I’ve got a request to replace the label “Up” by this arrow “▲” . What could be simpler? I quickly replaced “Up” by “▲” in my Java source code. Then I tried to save my code and got the Eclipse error “Some characters cannot be mapped using “Cp1252″ character encoding”…

The solution is simple. I used a nice online converter http://people.w3.org/rishida/scripts/uniview/conversion.php to get the Unicode code for the arrow character and then pasted it in my Java code like this:

String upArrrow = “\u25B2″;

-=Oleg=-

GWT - best practices

October 8th, 2009

GWT tutorials is a good way to learn basics and even to build simple prototypes, but it’s certainly not enough information to start building real life application. That’s why I was so glad to find this video from Google I/O 2009 which describes best practices for architectecting GWT application.

-=Oleg=-

New Direction - Google App Engine

October 2nd, 2009

As it often happened in developers life, as soon as you become an expert in something, the life throws you a new project which requires you to learn brand new  languages, platforms, frameworks, technologies, etc… Suddenly your work day routine changes from 80% coding and 20% research to 99% of learning and researching.

Only six month ago I started working with Silverlight. We had some fun playing with new power tool, we’ve built the a series of prototypes… and that was the end of Silverlight journey.

New mission is Google App Engine.  Our language of choice is Java. My experience with Java - none. So far looking at zillions of Java frameworks makes me dizzy. After spending 2 days on learning Struts 2 I’ve realized that the learning curve is expected to be very deep. I’m diving in… - wish me good luck.

-=Oleg=-

More about IIS performance

August 24th, 2009

One more article about IIS performance from trusted source i.e. from Microsoft:

http://blogs.technet.com/mscom/archive/2008/06/09/microsoft-com-operations-performance-analysis-of-iis-7-0-windows-server-2008.aspx

-=Oleg=-

SVN Rollback - restoring deleted files and folders

August 24th, 2009

Preface

I’m not an expert in SVN version control and I don’t like using command line. I’m regular Windows user and so it was easy for me to learn how to use “Commit” and “Update” buttons in TortoiseSVN. It was easy until one day when I had to figure out how to restore delete folders.

A day when sources disappeared

One beautiful morning I checked out my sources from SVN and discovered that the most of the files and folders are gone. Apparently the night before one of the developers was cleaning SVN working folder on his machine and … Well, if you don’t know what that big red button is for it might be not a good idea to press it…

So, if don’t know what to do - ask Google. Google said - don’t worry, it’s impossible to lose anything in SVN, just do the reverse merge using following command line params… 

The problem is I didn’t want to use command line. I wanted to use beautiful TortoiseSVN UI for that. So, I found “Revert to this revision” and “Revert changes from this revision” and thought my problem is solved, but for some reason SVN was failing this task with an error “‘/svn/sources/!svn/bc/373/Test’ path not found“. Finally, after asking an SVN expert, I figured that there was a small detail which I was missing. The revision of your working copy has to be a “HEAD”.

Steps to recover deleted files or undo the submit in SVN:

  1. Get the HEAD revision from SVN it to your working folder. Working folder is the key word here. (I suggest using temporary folder)
  2. Click on Show Log
  3. In the Log window, select revision you want to undo and click on the “Revert changes from this version” in the popup menu. This will execute the merge command of the corresponding revisions.
  4. Wait for SVN to update your working folder. Working folder is the key word again. SVN updates your working folder first, so you can review the change before you commit it to SVN.
  5. Make sure your sources merged correctly and then commit the change to SVN.

Best luck recovering your sources!

-=Oleg=-

IIS Performance

July 28th, 2009

Yesterday we had a little debate in the office about the max number or requests IIS can handle per second. So I did a little research and found that majority of the people are not able to go higher than 300-600 requests/sec, however some claim they were able to get 20000 req/sec. I guess it depends on how much processing work your request does i.e. if IIS is simply returning a HTML page or if it processes ASP.NET page doing authentication, making database requests and constructs the HTML page at the end.

Anyhow, I discovered that IIS 7  has some interesting features wich I was not aware of http://blogs.iis.net/bills/archive/2007/05/07/iis-vs-apache.aspx. I especially like the one that allows you to Troubleshooting Failed Requests Using Tracing in IIS 7.0 http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis-70/.

-=Oleg=-

Silverlight Styling

July 14th, 2009

Changing the styling of the Silverlight controls is simple. It’s somewhat similar to CSS, but it’s more robust and syntax is completely different. What is different in Silverlight and WPF is that you can completely re-define control’s UI and behavior using styles. It took me about 20 minutes from absolute zero to the “Aha!” moment and become an expert in styling WPF and Silverlight applications. Here are the 3 links that helped me to clear the mistery behind Silverlight styles:

1.       Using Style Elements to Better Encapsulate Look and Feel – a good example of how to change control’s properties using styles

2.       Using Control Templates to Customize a Control’s Look and Feel – a step further that shows how to make control look anyway you want. In other words how to draw control’s UI from scratch or combine several controls into one. All using styles! Pretty amazing yet simple.

3.       MSDN: Customizing the Appearance of an Existing Control by Using a ControlTemplate – the final piece of puzzle is about how to make control to react on events like Pressed or Disabled and change its appearance. Just few more words about this. Basically every control has a list of pre-defined events (they called states in Silverlight) which can be referenced by ControlTemplate. The list of states differs for each control. This information is available in MSDN on control’s Class page as a list of TemplateVisualStateAttribute attributes applied to the class.

-=Oleg=-

Silverlight 3 has been released

July 10th, 2009

Long awaited Silverlight 3 has been released. Here is the download link:

http://www.microsoft.com/silverlight/get-started/install/default.aspx

New features:

  • Media: New codec support (H.264, AAC, MPEG-4), raw bitstream Audio/Video API, and improved logging for media analytics
  • Graphics: GPU Acceleration and hardware compositing, perspective 3D, bitmap and pixel API, pixel shader effects, and Deep Zoom improvements
  • SEO: Deep linking
  • Application development: multi-touch support, 60+ controls available, and library caching support
  • Data: Data-binding improvements, validation error templates, server data push improvements, binary XML networking support, and multi-tier REST data support
  • -=Oleg=-

    How to serialize / deserialize ANY object using XmlSerializer

    June 30th, 2009

    There is a lot to say about object serialization. I just want to cover the gray area when you need to serialize object which has references to other objects, but references are not strongly typed. For example, if you have your classes structured like that:

        public class MainClass

        {

            public object Data { get; set; }

        }

        public class ChildClass1

        {

            //some properties

        }

        public class ChildClass2

        {

            //some properties

        }

     

    where Child Classes can be assigned to Data property of the MainClass and if you construct XmlSerializer object like this

    new XmlSerializer(typeof(MainClass));

    Then both serialization and deserialization will fail throwing an error saying that it has no knowledge of ChildClass1 or ChildClass2 classes. To resolve this error you need to provide XmlSerializer with additional class types which serializer may meet on its way when parsing XML string. Here is how to do that:

    new XmlSerializer(typeof(MainClass), new Type[] { typeof(ChildClass1), typeof(ChildClass2) });

    Here is the set of functions I use to serialize / deserialize my objects:

            public static string SerializeToString(object aObject)

            {

                return SerializeToString(aObject, null);

            }

     

            public static string SerializeToString(object aObject, Type[] extraTypes)

            {

     

                XmlSerializer aSerializer;

                if (extraTypes == null)

                    aSerializer = new XmlSerializer(aObject.GetType());

                else

                    aSerializer = new XmlSerializer(aObject.GetType(), extraTypes);

                MemoryStream aMemoryStream = new MemoryStream();

                StreamReader aStreamReader = new StreamReader(aMemoryStream);

     

                XmlWriterSettings aXMLWriterSettings = new XmlWriterSettings();

                aXMLWriterSettings.Encoding = new UTF8Encoding(false);

                aXMLWriterSettings.ConformanceLevel = ConformanceLevel.Document;

                XmlWriter aXMLWriter = XmlWriter.Create(aMemoryStream, aXMLWriterSettings);

     

                aSerializer.Serialize(aXMLWriter, aObject);

                aXMLWriter.Flush();

                aXMLWriter.Close();

                aMemoryStream.Position = 0;

                return aStreamReader.ReadToEnd();

            }

     

     

            public static object DeserializeFromString(string aMessage, System.Type aType)

            {

                return DeserializeFromString(aMessage, aType, null);

            }

     

            public static object DeserializeFromString(string aMessage, System.Type aType, Type[] extraTypes)

            {

                XmlSerializer aXMLSerializer;

                if (extraTypes == null)

                    aXMLSerializer = new XmlSerializer(aType);

                else

                    aXMLSerializer = new XmlSerializer(aType, extraTypes);

                System.IO.StringReader aStringReader = new StringReader(aMessage);

     

                return aXMLSerializer.Deserialize(aStringReader);

            }

     

    -= Oleg =-

    My experiences with LINQ (basic use with C#)

    June 25th, 2009

    So here’s how it started:

    “Fill an object that consists of lists of other objects that consist of lists of other objects from the database”

    Meaning, I have to retrieve data from 4-5 different tables, efficiently and bring it in to my app. My first idea: Iterate through the object and write separate queries that will populate each list, and than iterate through each object in the list and fill that one in turn. The number of transactions would be huge… so not such a great idea. Finally I came to the conclusion that an XML record set

     (SELECT
                    itemType AS '@type',
                    Id AS 'Id'
    FROM MyDataTable WHERE Id = @Id
    FOR XML PATH('Item'), TYPE)

    with a few of those nested, would be a more sensible approach.

    After spending a day linking my tables and selecting which values I need and which are junk, I started with the XML parsing. Of course this can be done in many ways, ranging from straight parsing with XPathNavigator to serialization straight into the object, or even transforming the XML using an XSL transform and than serializing it into an object. All those are fun approaches, but this time I decided that I’ll use that handy little tool that Microsoft has: LINQ.

    Language-integrated Query they call it. Mainly it’s used for writing XML files, and unfortunately most examples are regarding that. Of course, as with anything new that I do, I browsed the net for some examples, and gave up after about 5 minutes, and just started fiddling around with it… Here are my discoveries:

    The basic statement to use is:

    var vComponents = from item in sampleXML.Descendants("component")
                 select item;

    this gives you a list of items which you can iterate through with something like:

    foreach (var vComponent in vComponents)

    you may notice that this is a generic type (var) which is a LINQ free-form variable. In this case vComponents is a System.Linq.Enumerable and the vComponent is an XML container (the inner workings of LINQ are not my main concern).

    To extract a value from the XML container you might want to use something like:

    int myValue = int.Parse(vComponent.Element("myValue").Value);
    Guid myGuid = new Guid(vComponent.Attribute("id").Value);

    which is pretty straight forward. The fun thing is that you can than take your node vComponent, and use it as you would with any other XML document, so you can say something like:

    var vElements = from item in vComponent.Descendants("Element")
                  select item;

    or even:

    string itemName = vElements.Element("ItemInfo").Element("ItemName").Value;

    Of course, doing stuff like this with XML is risky, because let’s say one of your JOINS from the database yielded some NULL values, so you might want to first check for the element to not be NULL before you query for the value, like:

    if (vElements.Element("ItemInfo").Element("ItemDescription") != null)
        itemDescription = vElements.Element("ItemInfo").Element("ItemDescription").
              Value;

    just in case the description field was left NULL.

    Of course, you might want to wrap it all up in some try{ … } catch { … } statements just to prevent any other nasty errors from popping up.

    In conclusion, I guess all I can say is: “XML parsing made easy” using Linq. It’s good for iterating through multiple nodes of the same type, but I’d expect some nicer way for it to handle errors (like if a node is non existant, don’t throw an error just return a NULL value, like serialization does). Hopefully I’ll find some time and write a bit about serialization as well…

    alex~