Times Reader 2.0

On May 12th, New York Times announced the Times Reader 2.0 is now available. This new version is powered by Adobe AIR and can run equally well on Windows, Mac, Linux platform. If you are member of New York Times website, you can free download it. Installing it, it becomes more convenient to read the news from New York Times.

There are many columns such as International, National, Opinion, Business, Sport etc in Times Reader. It will help you find the news which you are interested in. It also offers the latest news so that you can obtain the latest information in time. You can choose the news according to the publishing date. In fact, it provides all news in a week. In the Times Reader, you may change the browsed way. Even you can watch the news in video or pictures. It is the extraordinary experience.

timesreader01

Figure 1: Front Page

timesreader02Figure 2: News in Pictrures

timesreader03Figrue 3: Browse Mode

I remember that I had installed the oldest version of Times Reader a couple of years ago. It was developed by WPF which is a technology produced by Microsoft. I have to agree it was amazing experience at that time. It improved the readability and useability for us. If each of publishers of newspaper provided the reader like this, no one doesn’t like to visit the website maybe, I think.

The new version of Times Reader was dropping WPF/Sivlerlight for Adobe AIR. What does it mean? It means Microsoft lost the important customer? It means Adobe AIR is better than WPF/Silverlight? Both are right, maybe. After New York Times announced the new version of Times Reader, InfoQ reported the news which title is “New York Times Dropping WPF/Silverlight for Adobe AIR“. The author wrote: “The biggest hurdle [of WPF]was the lack of cross-platform support.” I agree his opinion. Additionally, the compatibility of WPF/Silverlight is the other issue.

In the field of Rich Client Application, Microsoft lost more and more customers this year. After one year of using Silverlight, MLB swithed back to Flash to show its boradcasted live on the internet on 2009. Now, New York Times choose Adobe instead of Microsoft. What does it happen? Perhaps Microsoft should think about its strategy and improve the quality of service.

Dragon Boat Festival

boatDragon Boat Festival is occuring on the fifth day of the fifth lunar month. It’s a significant holiday celebrated in china, and the one with the longest history. The Dragon Boat Festival is celebrated by boat races in the shape of dragon. Competing team rows their boats forward to a drumbeat racing to the finish end first.

The boat races during the Dragon Boat Festival are traditional custom to attempt to rescue the patriotic poet Chu Yuan. Chu Yuan drown on the fifth day of the fifth lunar month in 277 B.C. Chinese citizen now throw bamboo leaves filled with cooked rice into the water. Therefore the fish could eat the rice rather than the hero poet. This later on turned into the custom of eating tzungtzu and rice dumpling.

The celebration’s is a time for protection from evil and disease for the rest of the year. It is done so by the different practices such as Hanging healthy herbs on the front door, drinking the alcohol mixing into realgar. After researched by Chinese Culture researcher, protection from evil and disease is the real and original meaning of this festival. As for tzungtzu, the people in the Xia Dynasty had already this traditional food in fact. So called memorizing the great poet Chu Yuan, it was attached into the festival at the end of the Han Dynasty, and became into the dominant meaning of the Dragon Boat Festival. Since the essence of the Dragon Boat Festival had changed, it is not only a tradional holiday, but also a Chinese culture heritage.

On May 28th this year, let’s celebrate the Dragon Boat Festival!

Strategy Pattern and Delegate

Strategy Pattern will encapsulate a family of algorithm and make them interchangeable. So we can define the unified interface for the algorithm. It represents the polymorphism of OOD. For instance, we will develop a tool to calculate the tax. Assumed that the tax is divided into the personal income tax and enterprise tax. We can apply the Strategy Pattern into it and abstract the calculation of tax into the interface ITaxStrategy:

public interface ITaxStrategy

{

    double Calculate(double income);

}

 

The concrete tax strategies will implement the ITaxStrategy interface:

public class PeronalTaxStrategy : ITaxStrategy

{

    public double Calculate(double income)

    {

        //Implementation

    }

}

public class EnterpriseTaxStrategy : ITaxStrategy

{

    public double Calculate(double income)

    {

        //Implementation

    }

}

 

At the same time, we will define the utility class to provide the clients with convenient.

public class TaxOp

{

    private ITaxStrategy strategy;

    public TaxOp(ITaxStrategy strategy)

    {

        this.strategy = strategy;

    }

    public double GetTax(double income)

    {

        return strategy.Calculate(income);

    }

}

Now, the clients can invoke the related operation of TaxOp class to get the tax according to concrete strategy object which is passed as parameter of constructor.

public class App

{

    public static void Main(string[] args)

    {

        TaxOp op = new TaxOp(new PersonalTaxStrategy());

        Console.WriteLine(“The Personal Tax is :{0}”, op.GetTax(1000));

    }

}

 

It follows the idea of OOD. However, we can make use of the delegate syntax in C# for some simple algorithms. It will simplify our implementation. Maybe it will violate the idea of OOD, but it provides the extensibility also.

 

For the same example given before, we can modify the interface to delagate type:

public delegate double CalculateTax(double income);

 

Of course, we should provide the different implemenation:

public class Tax

{

    public static double CalculatePersonalTax(double income)

    {

        //Implementation

    }

    public static double CalculateEnterpriseTax(double income)

    {

        //Implementation

    }

}

 

Accordingly, we must modify the TaxOp Class:

public class TaxOp

{

    private CalculateTax calDel;

    public TaxOp(Calculate calDel)

    {

        this.calDel = calDel;

    }

    public double GetTax(double income)

    {

        return calDel(income);

    }

}

 

And the implementation of Clients program:

public class App

{

    public static void Main(string[] args)

    {

        TaxOp op = new TaxOp(new CalculateTax(Tax.CalculatePersonalTax));

        Console.WriteLine(“The Personal Tax is :{0}”, op.GetTax(1000));

    }

}

 

Two solutions are more or less the same. The code snippet is also similar. But the idea based on the essence of design is different completely. It’s the difference between OO and OP. The former encapsulates the behavior in an object; the latter handles the method directly, and uses the delegate to provide the extensibility. In fact, the delegate represents the feature of Functional Programming nearly. It seams like a pointer to the function in C++. In other words, the delegate is another ways of abstraction. It is more flexible than interface type. After C# 2.0 introduced the anonymous method, and C# 3.0 introduced the Lambda expression, delegate becomes more and more useful and popular on C# programming. Before C# 2.0, I prefer to interface; now I prefer to delegate. Even we may use the delegate type to provide the brand new implementation of some design patterns such as Strategy Pattern, Command Pattern etc.

Microsoft released BizTalk Server 2009

biztalkRecently, Microsoft released BizTalk Server 2009 which is the latest version for Biztalk Server. BizTalk Server Team Blog announced this news on April 28. It posted the key improvements in the BizTalk Server 2009 release:

  • New Application Lifecycle Management(ALM) exprience to make development teams more productive
  • New adapters and numerous enhancements that provide increased enterprise connectivity
  • New RFID mobile capabilities that will enable innovative solution to drive business value

The BizTalk Server 2009 release is the globalized product. It is available broadly in nine languages: Chinese simplified, Chinese traditional, English, French, German, Italian, Japanese, Korea and Spanish. Besides, it includes four edtions: Enterprise, Standard, Branch and Developer. The price of the new version is not change. More information about the price and upgrade, please visit “Pricing and licensing” provided by Microsoft.

If you want to update it from BizTalk Server 2006 R2 to 2009,Nick Heppleston had posted a great article on his blog called “A Quick Walkthrough of the BizTalk Server 2006 R2 Upgrade to BizTalk Server 2009 RTM“. It is detail guide and introduces how to upgrade it step by step.

BizTalk Server 2009 is widely concerned in the technology community. Abdul Rafay raise his opinion in his blog:
It supports the Windows Server 2008, VS 2008, .NET Framwork 3.5 and SQL Server 2008 which I think is a major change and will have advantages of the new advanced platform.

He briefly introduced the new adapters in BizTalk Server 2009:
Unlike the release of BizTalk Server R2, BizTalk 2009 comes with two new adapters Oracle E-Business Suites and SQL Server, while there has been an enhancement in the existing adapters which I still have to explore.

Microsoft also provided the roadmap of BizTalk Server. It said:”BizTalk Server 2009 represents the next release in Microsoft’s long-term strategy to enable the connected enterprise. ” The BizTalk Server 2009 continue to build on the investments made to address the concerns of Service Oriented Architecture and Enterprise Connectivity. Especially, the new release of BizTalk Server can take advantage of the latest virtualization improvements included as part of Windows Server 2008 Hyper-V. This capability can reduce the costs through lower hardware, energy and management overhead.

To learn more information about BizTalk Server 2009, Adlai Maschiach summarize some useful matirial on his blog including MSDN Documents, Virtual Labs and BizTalk Server 2009 Solutinos. Of course, you can visit the Official Website of BizTalk Server to learn more.

VS 2008 Shortcut Key

visualstudio2008logoThere are many useful shortcut keys in VS 2008. In this post, I’ll write some most useful key which are always used by myself.
Shift&Alt&Enter: Switch to Full-Screen mode;
Ctrl&Tab: Similar with Alt-Tab in Windows OS, it can switch windows that have been open currently in VS;
Ctrl&-: To navigate backward to previous place. For example, if you want to explore some class’s definition, you will select “go to definition” item from context menu to navigate the definition detail. After you view it, in the most case, you want to back the previous place, so you can press this shortcut key. That’s great and convenient for the developer. It seems like “Undo” feature;
Ctrl&Shift&-: To navigate forward to next place.

Design is an island

islandRecently, Kent Beck wrote a post which raise an opinion about software disign. It’s a nice metaphore for disign. That is: design is an island.

Kent wrote: Designing, then, is like walking an island. As long as you don’t get your feet wet, your design is okay. It means that we should try to design enough to meet the current set of requirement, otherwise you might fall into the water.

The “water line” is always changed because the tides always change the sea level. It means the change of requirement. That is inevitable. So we must beware not to let your feet wet. Kent said:”Design that are acceptable at other time of the year break down in the 10% of the year when you do 50% of your business.” So you should keep your design fresh. It’s the feature of the excellent architecture.

“Climbing higher on irland requires effort, just as improving designs require effort.” That’s right. You should spend your money and time to improve your disign.

Kent recoginzed the distributed application such as SOA and REST as the archipelago. It’s interesting. The analogy is perfect. It’s the extension of metaphore of island.

Kent alos raise his opinions, for example earthquake and island sank. More details visit the kent beck’s blog here. Enjoy it!

Using Extension Methods to Verify the Method Calling

Using the extension method provided by C# 3.0 as the new feature, you can add the new methods for the compiled assembly to meet the need of extensible. In addition to this, extension method can also be effective to reduce duplicate code and improve the reusability of system if you are able to combine the generic and type inference. For example, the method like this:

public class CustomerDAL

{

    public IEnumerable<Customer> FindCustomers(string roleName)

    {

        return from customer

            in context.Customer

               where customer.RoleName.Equals(roleName)

               select customer;

    }

}

It will throw the NullReferenceException if you invoke it by this way as below when it returns null:

Customer customer = new CustomerDAL().FindCustomers(Role.Admin).First();

So we have to verify the result. If it is null, the custom exception should be thrown:

public IEnumerable<Customer> FindCustomers(string roleName)

{

    IEnumerable<Customer> customers = from customer

            in context.Customer

            where customer.RoleName.Equals(roleName)

            select customer;

    if (customers == null)

    {

        throw new MyException(“Cann’t find the customers.”);

    }

    return customers;

}

 

The logic of verification implemetation will spread through the everywhere in the system if there are too many methods which need to be verified. It is difficult to reuse these code, and it is bad smell absolutely.

Craig Andera post the blog to solve this problem. He wrote:
A NullReferenceException would be thrown, but we wanted something more specific. So we came up with this:

public static T OrThrow<T>(this T obj, Exception e) {

    if (obj == null) {

        throw e;

    }

    return obj;

}

 

Using the OrThrow() method, the invoking way might be changed like this:

Customer customer = new CustomerDAL().

    FindCustomers(Role.Admin).OrThrow

    (new MyException(“Can’t find Customer”)).First();

 

Craig continues to say:
the OrThrow extension method is generic on the type it’s invoked on, and it returns that type, so you can insert it into a chained expression and you don’t lose any intellisense. And because of type inference, you don’t actually have to specify the type, which cleans up the expression a bit.

That is, OrThrow() method can be applied to any type. Following this idea, we can create an instance as default value to avoid to throw the NullReferenceException using the extension method:

public static T Instance<T>(this T obj) where T:new()

{

    if (obj == null)

    {

        obj = new T();

    }

    return obj;

}

 

Due to type parameter T need to create an instance, we must add the constraint with new(). So that we can’t use the Instance<T> extension method for abstract type or interface type such as IEnumerable. But it is effective to method like this:

public class ListObject

{

    public List<string> Foo()

    {

        return null;

    }

}

 

Through by using Instance() method, we can invoke the related properties and methods of List instance safely. For example, we can use the Count property as below:

Console.WriteLine(new ListObject().Foo().Instance().Count);

 

The result value is 0. If Instance() method is not used, the NullReferenceException should be thrown.