Acropolis and MFC

MFC is the C++ wrapper to Windows API. It was a great help when moving from DOS to Windows where the Windows API required a new mind set.

Now it’s WPF age, WFP/XAML is another big mind set change. Acropolis came to help this time. Its wizard askes something like “Do you want SDI or MDI?” and “Do you want menu bar, tool bar and status bar?”. They are famous questions in MFC wizard.

Add comment December 6th, 2007

ASP.NET MVC

Just saw a demo of ASP.NET MVC by Jeffrey Palermo on DevTeach Vancouver. The demo used StructureMap to construct the controller DI/IoC way, but actually key point of this framework is the “URL routing handler” that maps URL request to controller class’ method. The mapping is configurable and has intelligence to map automatically by parameter.

It somehow reminds me ISAPI Extension. In Delphi, it was as easy as adding a WebAction component, set path then code in the OnAction event which usually calls methods in another controller class…

The second key point is the “RenderView” method from base class Controller. It invokes aspx as a template engine. The result is that view state, server side event are no more available.

To me, ASP.NET MVC is as same as Web Client Software Factory that I will not jump on immediately.

Add comment November 30th, 2007

WPF team is prompting PM

Attended Jeremy D. Miller’s session about design patterns for WinForms where I finally learnt the differences between supervising controller and passive view.

As myself being a fan of “Presentation Model” and data binding, especially two-way data binding, I am glad to know from Jeremy that “Presentation Model is another name for the Model/View/ViewModel pattern being promoted by some of the WPF team at Microsoft.” from his presentation of his blog post.  

Update on 12/5/2007: Acropolis, the WPF client application framework is really using the presentation model explained in this video presentation.

Add comment November 30th, 2007

Post back

Before, my guidance to developers is to avoid post and try always GET.

This rule now changed. All because of the UpdatePanel which essentially dose partial page updates.

Started to like post back because only post back, not GET will work with UpdatePanel.

Add comment June 26th, 2007

Service without description is a pain

Too many debates are there about SOAP vs. REST, contract first vs. code first.

But here is my real life experience during developing WB Editor when it needs to connect web services through those famous RESTful style APIs.

First, the API documents usually have no schema definitions other than request and response XML examples.  Examples are good for human to read.  But after reading, where is the code that I can work with? I have to write code to parse those XML! - This is a pain. If there was schema, machine could generate client code stubs automatically. The nice “Add web reference” way.

Second, maybe the web service providers realized the issue mentioned above. Usually there are client libraries are also available, such as libraries for Java, for .NET, for PHP, for Python and for Javascript …. If using libraries, what is the differece between them to those C libraries ages ago? As long as the the library black box can talk to the server no needs to bother whether underneath it is HTTP, whether it is XML or binary.

I cannot imagine if in my company, when I publishing tones of web services to other departments or clients, I have to also deliver client libraries, for Java, for .NET ….

Tags: , , , , ,

Add comment June 8th, 2007

Object Databind is Great

No needs to rename every control from something like textBox1 to txtTitle :) , because no more code like:

txtTitle.Text = article.Title;
article.Title = txtTitle.Text;

How much time can we save if there are 20 controls on the screen?

Add comment May 20th, 2007

Data Extraction / Screen Scraping Using XPath

Google AJAXSLT is an implementation of XSL-T in JavaScript, intended for use in fat web pages, which are nowadays referred to as AJAX applications. Because XSL-T uses XPath, it is also an implementation of XPath that can be used independently of XSL-T.

Selenium Core uses AJAXSLT’s XPath function to locate element on plain html. Selenium IDE can generate the XPath very much same as Solvent.

Here is a sample to extracting data from a web page using XPath using AJAXSLT.

<html><head>
<title>XPath-Test</title>
<
script language=”JavaScript” type=”text/javascript” src=”xpath/misc.js”></script>
<
script language=”JavaScript” type=”text/javascript” src=”xpath/dom.js”></script>
<
script language=”JavaScript” type=”text/javascript” src=”xpath/xpath.js”></script>
<
script language=”JavaScript” type=”text/javascript”>
function
findElementUsingFullXPath(xpath, inDocument) {
 
var context = new ExprContext(inDocument);
 
var xpathObj = xpathParse(xpath);
 
var xpathResult = xpathObj.evaluate(context);
 
if (xpathResult && xpathResult.value) {
    return xpathResult.value[0];
  }
  return null;
};
function start() {
  alert(findElementUsingFullXPath(
“//*[.='b']“, window.document).innerHTML);
}
</script>
</
head>
<
body onload=”start()”>
<
div><p>aaaaa</p>test<div>bb</div><a>b</a></div>
</
body>
</
html>

 

Add comment May 16th, 2007

SQL CE database and ClickOnce Deployment

My default SQL CE database was deployed to ClickOnce Data Directory. If changed the database schema, ClickOnce will deploy the new database and keep the old database file (in .pre folder). Here is the psuedo code to migrate schema:

if (IsFirstRun)
{
   if (customMigrationORMergeNeeded)
   {
      string dataFolder = call the API
      // Database from V1 of the    app
      string oldDatabase = Path.Combine(dataFolder,”.pre\db1.db”);
      if (File.Exists(oldDatabase))
      {
         string newDatabase = Path.Combine(dataFolder,”db1.db”);
         //perform the task needed with old and new one
         DoPerformCustomMigrationORMergeAsNeeded();
      }
}

What about removed the program from control panel? Data are all gone.

Looks like better to copy database file to the application data folder.

Add comment May 15th, 2007

VBx - Visual Basic as Dynamic Language

One of the Mix07 presentation mentioned VBx along the Ruby and Python. I realized immediately it must be something interesting.

While searching related staff, I also found this diagram.  

Add comment May 6th, 2007

Web Service Description: RSD and RDF

Most popular blog servers/engines such as WordPress, Drupal, Neclues and etc. are using RDS (Really Simple Discovery) to help client software like WB Editor to find the services that can be used to retrieve, modified and delete the blog posts.

Those blog servers/engines are also generating RDF (Resource Description Framework) for each blog post to give more information about the post, e.g. track back url. But not enough. I am looking for,

  • RDF extension that describes the blog service API lisk WSDL dose for SOAP, so that WB Editor can generate dynamically proxies to the service.
  • RDF extension that describes which HTML elements can WB Editor extract data from and then send to the blog service.

Here are some interesting references:

Add comment May 6th, 2007

About


Add comment October 18th, 2006

Created a CAB workspace that has VS 2005 style Tabs

VS2005-Style-CAB-Workspace

1 comment August 17th, 2006

SharePoint Windows Authentication

In IE: open “Tools | Internet Options -> Security”, add the SharePoint sites in “trusted sites”

In firefox: open firefox browse to about:config find “network.automatic-ntlm-auth.trused-uris” modify the value and enter in SharePoint intranet sites that you must pass your username and password to. For some site i connect to i also had to add values to: “network.negotiate-auth.delegation-uris” “network.negotiate-auth.trusted-uris”

Add comment July 20th, 2006

Unit Test : MVP vs PM

Smart Client Software Factory team is recommending the “Model View Presenter” pattern. They have created Guidance Package for using this pattern.

From my experience, the “Presentation Model” pattern is better. When I asked if SC-SF can also include Guidance Package for PM, it looks like people may think MVP is more suitable for unit tests than PM. Read this thread.

To me, PM is even easier for unit testing, because it is less coupled.

MVP.pngPM.png

I have refactored the CAB Smart Part Quick Start project to use MVP and PM patterns and have also created unit test projects for comparison.

Source Code:

They can be added to the CAB Smart Part Quick Start solution.

 

 

Add comment June 14th, 2006

Refactor CAB Smart Part Quick Start Project to ” Model View Presenter”

In my previous post, I refactored CAB Smart Part Quick Start project to use Presentation Model. This time I refactored the project to use Model View Presenter. Note: the Presenter class is borrowed from Smart Client Software Factory, SC-SF.

Download: Source for PMSource for MVP

They can be added to Smart Part QuickStart Solution for comparison.

The difference is that in MVP the presenter uses the interfaces to push data into the views. That presenter refers to views. In PM, views pull data from the presentation model.  Views refer to pm via interface. The pm implements the interfaces. Personally,

I prefer PM to MVP. I successfully used the PM pattern in several projects.

My thougths are, 

What esstentially MVP and PM do is to take the state and behavior of the presentation out of view. The views are dumb. They do nothing other than data binding and bypass user inputs.

But in MVP, although it splits one “autonomous View” into two parts, actually presenter and view are logically one thing, physically two class. When adding a new view, a new presenter is required.

In PM, it is a decoupled structure. Presentation model has no idea about view(s). It just holds the state and raise events. Adding new views needs no changes to the PM. View can also choose to connect different presentation model.

The Smart Client Software Factory recommand MVP over PM, “The rationale behind MVP as implemented in SC-SF is to encourage unit testing …” Read this thread.

So, I created two projects for the two patterns. Next I will try to unit tests for them to see.

Add comment May 19th, 2006

Refactor CAB Smart Part Quick Start Project to “Presentation Model”

Composite UI Application Block (CAB) is really a powerful framework for smart client applications. It comes with samples implementing the Model View Control (MVC) pattern and the Model View Presenter (MVP) pattern. There is actually a third pattern called Presentation Model. See the pictures from http://jgoodies.com/articles/patterns-and-binding.pdf.

MVC MVP PM

As described in Martin Fowler’s article (MVP, PM), the presenter in MVP has no state and the views need to provide interface allow presenter to manipulate them. The Presentation Model holds and synchronizes the state, but no need to create view interfaces.

Choice between MVP and PM, as per Martin Fowler’s article:

This decision would be strongly influenced by a decent framework that supports such synchronization. If you have such a thing then Presentation Model seems the better choice.

Compare to MVC or MVP, I prefer using the Presentation Model, because it has a centralized place to store state/data and centralized event source to notify views to update themselves. The CAB’s Event Broker is perfect for notification. So I modified the Smart Part Quick Start Project to become the ”Presentation Model” pattern.  Here is the Source code.

What have I done?

  1. Refactor to extract interface ICustomerListView and ICustomerDetailView from the views*. 
  2. Added CustomerPresentationModel class that implements the above two interfaces. 
  3. Define the CustomerPresentationModel class as Service. **
  4. Inject the CustomerPresentationModel instances into views using service dependency injection. ***
  5. Published events CustomerSelected events CustomerCommentsSelected from the CustomerPresentationModel class.
  6. Subscribed the above events in BrowseCustomerWorkItem and ViewCustomerWorkItem

* Extract interface from the views sound very much similar to MVP, isn’t it? The difference is that in MVP, the presenter uses the interfaces to push data into the views, means that presenter refers to views. In PM, the controller implements the interface. The views pull data from the controller, means that views refer to controller. The “refer to” is a very good case of using depedency injection.

**

[Service]
public class CustomerPresentationModel: ICustomerDetailView, ICustomerListView
{
}

***
public partial class CustomerListView : TitledSmartPart
{
    private ICustomerListView controller = null;

    [ServiceDependency(Required = true, Type = typeof(CustomerPresentationModel))]
    public ICustomerListView Controller
    {
        set { controller = value; }
    }
    ….
}

Tags:

1 comment May 15th, 2006

P&P OB CAB EntLib

继续 VSLive Toronto 的后续故事。 上次记录了 SQL/e,这次是关于 Daniel Cazzulino 的发言 《Microsoft p&p ObjectBuilder》。听完这个演讲发现最近周围的事情还都发生了些关联。

首先是日前买了本书 《Head Up Design Patterns》。它的第一章就以一个引人入胜的故事介绍了设计模式的 Strategy Pattern。这个模式的好处多多,但是负作用是会产生了很多相互关联的类。如何按照合理地创建这些类,并把它们组和起来。这就引出了另外一个话题 Inversion of Control / Dependency Injection

这几天帮女儿复习准备乐理考试,还碰到了 Interval Inversion / Triad Inversion,搞得我就很头昏。Dependency Injection 好像还好理解些。

Daniel Cazzulino 讲的 ObjectBuilder 就是一个具有 dependency injection 功能的轻量级对象容器*。 ObjectBuilder 是 MS patterns & practices Composite UI Application Block 以及 Enterprise Library 的核心部分。

这就又引到了 CAB - Composite UI Application Block。也是不久前 WB Editor 3.0 的设计已经开始了。鉴于 2.0 版本中 RAD 流毒太深**,决定应该采用个好的系统结构,正在犹豫,是否用这篇 Implement a Microsoft Word-like Object Model for Your .NET Framework Application 文章介绍的方法呢,还是用 CAB

经过聆听 Daniel Cazzulino 的讲解,不但了解了 OB 的功能,还了解了其内部的一些机制。因此决定进一步学习了一下 CAB Hands on Lab。于是得到结论就是 WB Editor 3.0 将采用 CAB。

Daniel Cazzulino 还讲了个有用的内容,Guidance Automation Toolkit / GAT,值得再用一篇笔记介绍。
* 轻量级对象容器和 ** RAD 流毒也可以讲些故事。

Tags:

1 comment May 14th, 2006

Optimistic concurrency

During the WB Editor 2.5 testing, we found an interesting concurrency control issue. In this version, we allowed multiple program instance for ease of cross posting.

Now in multiple instance windows, user can setup blog server accounts differently. Which one is the winner?

“Last one wins” was disapproved by QA.

Maybe we need optimistic concurrency. I this case user will receive a dialog saying “another instance has modified the settings”, do you want to overwrite or discard or reload?

Another option is concurrency control with change notifications. Using FileSystemWatcher to detect changes of configuration file, but what should happen next in UI?

Tgas:     

 

Add comment May 10th, 2006

SQL/e

在 VSLive Toronto 上见到两个人物,Steve LaskerDaniel Cazzulino

Steve Lasker 介绍了使用 SQL Server Everywhere 的 Occasionally Connected SystemsSQL Server Everywhere(SQL/e) 何须人也?原来2-4年前做 Pocket PC 程序就相识,那时它叫 SQL Server CE,后来又叫 SQL Server Mobile。 Visual Studio 2005 带的 SQL Server Mobile 被限制只能运行在 Tablet PC 上。SQL/e 就是解除了这个限制的版本。SQL/e 因此能运行在台式 Windows 上。

SQL/e 计划在 2006年下半年发布。 Steve 演示了目前如何在 VS 2005 中试验开发的和可以通过 ClickOnce 安装的办法。

这就解决了一个版本 WB Editor 的数据库选择问题。 本来正在犹豫是否应该用 SQL Server 2005 Express (SQL/x)。这个家伙 55M,还需要 Admin 用户权限才能安装。 比较  SQL/x 和 SQL/e,SQL/e 才 1.4M。看来SQL/e 更加适合 WB Editor 3.0。

Daniel Cazzulino 讲的内容也很有用,将会在下一篇笔记内介绍。

Add comment May 8th, 2006

CurrentVersion - Explorer - SharedTaskScheduler

An icon in the system tray kept poping up a notification saying “Your computer is infected! …”. If clicked the message, it opens the browser and connects to spywarequake.com.

Scanned with Windows Defender and Windows Live Safety Center, they could not find anything …

Finally used the old Spy tool to catch that popup’s class name is “ballon window”. Then searched DLL to find out suprox.dll. In the registry:

[HKEY_CLASSES_ROOT\CLSID\{AC1B4DA2-12FA-31F2-1A7D-CD2B14E6AD4E}\InProcServer32]
@=”C:\WINDOWS\system32\suprox.dll”
“ThreadingModel”=”Apartment” 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\
CurrentVersion\Explorer\SharedTaskScheduler]
“{AC1B4DA2-12FA-31F2-1A7D-CD2B14E6AD4E}”=”USB Mouse Driver”

SharedTaskScheduler!, a new place to watch out.

Tags:  

Add comment April 15th, 2006

Next Posts Previous Posts


Categories

Links

Feeds


1