Posts filed under 'Programming'
I use Git Extensions when dealing with Git. As a Visual Studio user, I would like to see files status in solution explorer, which is not in Git Extensions, so I decided to make one myself. Now it is on Visual Studio Gallery and can be installed through Tools | Extension Manager within Visual Studio.
It is just to display to file status, not to replace or overlap the functions of Git Extensions. And it should be as much close to the existing Visual Studio experience with VSS and TFS as possible.
I use the blue lock icon for checked in (committed) files and red check icons for modified files. The fellow plus and i icons are new. They represent new files and staged files, which are not in VSS or TFS. They apply only to Git.
When testing with my Git controlled projects, the files’ state icons really give me a familiar experience of source controlling in Visual Studio and a pleasant view of the projects by seeing files are new, modified and staged.
Immediately, I feel that besides the eye candy part, more source control related functions will be handy for Visual Studio users, such as compare, view history, undo check out, check in …. I decided to implement only “compare file with last commit” and “undo file changes (restore file from last commit)”. Other things like view history, check in/out, switch branches will be left to Git Bash and Git Extensions.
I had a mistake while developing (Yes I am using this plug-in/extension while I am developing it). I committed to wrong branch. So it is important to see current branch name. It would be nice if I can display the current branch name in the solution node to make it “Solution ‘Solution1’ (1 project) (master)”. And on the context menu, make it “Git (master)”. I am working on this …
The project is on codeplex (http://gitscc.codeplex.com) and the source code is on GitGub (http://github.com/yysun/Git-Source-Control-Provider).
May 31st, 2010
Back to the time of using VSS, check-ins (commits) happened upon when you feel it’s the time to check in. One check in could contain changes for different purposes. Who cares. It is impossible to apply the changes to different branches anywhere.
With git, the commits are visualized like steps of how your software is developed. You would feel shame when seeing yourself mixed up changes together. Actually, if you organize them well, the commits are not only showing good history, but also they can be applied to other branches, called cherry picking. It really let you start thinking to make meaningful commits. And not to mix several changes into one big commit.
The commit message conventions have changed because of the meaningful commit idea. In VSS before, we mostly used the past tense, like “fixed bug 123”, “added new stored procedure”, and etc. It mean I finally have done something. Now in git, the present tense makes more sense. “Fix bug 123” means that if you pick this commit into your branch, it will fix the bug. “Add new stored procedure” means that the commit will you give a new stored procedure. This new style is helpful for cherry-picking. Now the history does not like feature announcements, but has many smaller atomic, maybe reusable steps.
Since we started to be careful on committing, very naturally we want to be able to fix our last commit by adding more changes to it, or even just add some comments. Git commit –amend let us achieve it easily. In Mercurial, that’s not allowed. because in Mercurial, change sets are immutable. It is difficult to make correct commits just one time deal.
February 17th, 2010
My branching and merging presentation to developers went really well. I demonstrated the 3-way merging (using KDiffs), then branching and merging in TFS and in Git.
Here is the scenario. There are conflicts in V1.1 and V 2.0.

Using 3-way merging, conflicts are automatically resolvable. That is something cannot be done using the 2-way merging.
I mentioned my one of my two big disappointments in TFS merging. By default TFS dose 2-way merging, not 3-way. The above scenario requires manual resolutions to the conflicts.
Update: after the presentation, I was able to set KDiff3 as the diff and merge tool in team explorer, followed this tips from this blog post. It then can automatically resolve the above conflicts. But I am still not sure if TFS will be as good as Git in more complicated scenarios.
Next, I compared TFS and Git on branching. TFS creates a copy folder for the new branch. For big projects, it could be slow.

I don’t really care about branching, but merging must be good. Here is my second disappointment about TFS. By default TFS can only merge branches that are direct parent or child. I cannot merge V 1.1 to V 3.0.
We still like the project management/work item tracking and build features of TFS.
How to use Git with TFS? My suggestion during the presentation was to check out TFS projects as master and use Git locally. Like it is described here. The source control binding information in solution and projects are headache to deal with though.
I tried git-svn and TFS SVN Bridge against codeplex. It works well. I am waiting svnBridge’s new lease that supports TFS 2010.
February 5th, 2010
My submission to the MIX 10K Challenge has been accepted and published.
http://mix10k.visitmix.com/Entry/Details/189
January 21st, 2010
While I was looking for a solution to backup my git repository, I started with the SyncToy. It was the tool I used on XP. Now on Windows 7, the offline files feature can sync network folders and files. On the web, there are Windows Live Sync and Window Live Mesh. They all can sync folders and files. So many tools and features, I am going to pick one by being picky.
SyncToy is easy to use, but it doesn’t support schedule. I am too lazy to to create scheduled tasks in windows.
Windows 7 Sync center can schedule syncs, but basically you are working on a network shared folder. I don’t want to write code on a shared folder. Plus git reports error when using UNC path, unless the shared folder is mapped to a drive.
Windows Live Sync syncs files between computers, not shared folders. Computers must be on the Internet and be running Live Sync program under my account. My wife is mainly using the other computer that I want to save a backup to. I need to create shares …
Live Mesh is similar to Live Sync. Further more, it actually copies files to its web storage. To have a backup in the cloud is a good option. No worries about my wife’s computer. I will chose Live Mesh. All I need to do is just to right click the folder and select “Add folder to Live Mesh …”
BTW, when right clicked, another menu showed up “Shared Folder Synchronization …”. What? Another sync tool, SharePoint Workspaces?
December 23rd, 2009
I want to copy my git repository to another computer for the purpose of backup. After installed the git on the other computer, I found out a SSH server is also needed on that Windows system. Fortunately followed this blog post, "8 ways to share your git repository", I used the shared folder option. It is not even needed to install git on remote computer.
The remote repository is a shared repository that I can push my branches to. This is great. But what I wanted is only to have a backup my repository. End of the day what I need is the Sync Toy.
Actually I have been playing the engine behind the sync toy for a while, the Microsoft Sync Framework. It seems that things come along together around the concept of disconnected and distributed. Git is. Sync is. It could be a big concept in application development.
December 23rd, 2009
I had a good impression about the Eclipse's Local History feature before, which allows me to view, compare and merge with my previously versions of the source code. Later on, I used an add-in for Visual Studio 2005/2008, called Visual Local History 2005. Now I started to use Git on my laptop. Suddenly I am able to do branching locally.
Branching used to be a scary thing that requires a lot of planning for server based source code management. E.g. In order to do a proper branching on Microsoft Team Foundation Server, we have to read, understand and follow a book, Team Foundation Server Branching Guidance. Git made it cheap and easy to do branching on local. This let us create as many as branches we want. Not only production and testing branches, but also experimental branches for features and try outs. I played it a little bit and here are some nice experiences.
One Repository and Switch Between Multiple Branchess
I created one repository for my solution which includes three projects to start with, a Silverlight class library, a Silverlight Application and a Web application to host Silverlight application. Then I created three branches, master, develop and tryout. In the tryout branch, I removed the web application project from the solution and made the Silverlight Application generate a test page instead.
Switching between develop and tryout branches (in terms of Git's terminology it is checkout), Visual Studio detects the solution file has been changed and will reload the solution file and source files accordingly. Git must be preparing/restoring files for the branches! No need to create workspaces and separated folders for branches! No need to mapping the working folders. One caveat though is that you cannot switch branch if there are pending commits.
Cherry-Picking and Mergee
I added all files before modifying the .gitignore file. The files in the bin and obj folders are included. To fix it, in tryout branch I deleted the two folders. Because I don't want to apply other changes back to the develop and master branches yet, I used the Git cherry-pick function to apply only the deletion back to the develop and master branches. Nice and easy. But to do it from the master branch is even easier.
For some reason the .pdb files weren't deleted (maybe I had the Visual Studio in debugging). They are still under source control. This is even easier to deal with. I switched to the master branch. Deleted the bin and obj folder again. Commit and Merged the deletion into the develop and tryout branch..
Next I am going to install Git on a desktop computer and push code from laptop.
December 21st, 2009
Within the patterns & practices SharePoint Guidance, there are a few reusable components, such as Hierarchical Configuration, Logging and Service Locator. They are basic infrastructure for SharePoint applications. Here are some my thoughts.
1) The hint is that to start build any types of application, web application, Silverlight application and etc, the first thing is to get configuration, logging, service locator/dependency injection ready.
2) In .NET base class libray, there should be generaric interfaces, such as ILogger, IConfig for custom implementation, like the GeoAPI.NET, which provides OGC/ISO standards based interfaces to .NET GIS projects. Today, the ILogger defined in Microsoft.Practices.SPG.Common is useless to other LOB DLLs.
3) Compare to the Enterprise Library monster, Microsoft.Practices.SPG.Common is much lighter. But the ILogger and IConfigurationManager are coupled w/ SharePoint, and there is no dependency injection.
I am looking into the possibilities to implement dependency injection to SharePoint development, as I did for ASP.NET MVVM.
December 1st, 2009
My stories with WCF:
1) WCF is very easy to expose functions through different endpoints by just configuring endpoints. I created a WCF in Web application to serve Silverlight 2. It has a basicHttpBinding endpoint and a mexHttpBinding. It worked perfectly w/o change to serve Sliverlight 3. Later on, I added webHttpBinding endpoint (enabled web script). It worked with ASP.NET AJAX Client data template (not cross domain yet). Next I will try if it is possible to add a custom binding with binary encoding for Silverlight 3.
2) WCF is still too hard for non .NET clients. My client was a Delphi 7 program. It dose not support wsHttpBinding (SOAP 1.2). Even with basicHttpBinding (SOAP 1.1), Delphi could not generate proxy from the WSDL, because the WSDL of WCF uses "include". End of the day I created a ASMX wrapper around the WCF interface and implemetation. It was a success, because the ASMX follows the important concept of service interface, service implementation, service host and etc, just like WCF. In the future, if ASMX is need, I will start with WCF and wrap it with ASMX.
3) Nightmare of configuing the SSL for WCF. It requires to configure the base address in web.config. It was every difficult for a server that has many virtual sites. Metabase Exploerer is need to configure the IIS 6′ SSL binding.
4) Both WCF(basicHttpBinding endpoint) and ASMX work perfectly with my basice authentication HttpModule. As well as the ASP.NET client application (authentication) service.
For future reference, I need to write down my wresting experiences with a few commoly used WCF binginds.
- basicHttpBinding - SOAP 1.1
- wsHttpBinding - SOAP 1.2 (looks like it is only good for .NET client)
- webHttpBinding - HTTP/REST
- for ASP.NET AJAX Client/JSON, in web.config created a new endpoint with address "/ajax", and defined the <endpointBehaviors> to have <enableWebScript />, now the URL …/xxx.svc/ajax/js and …/xxx.svc/ajax/jsdebug return proxy in Javacript. The proxy is used by the client template for data binding
- for REST, in web.config created a new endpoint with address "/xml" and defined the <endpointBehaviors> use <webHttp/>. now the [WebGet] attribute works for URL …/xxx.svc/xml/Id=123. [XmlSerializerFormat] was used to control the XML schema structure.
December 1st, 2009
In my article titled Presentation Model in Action, I demonstrated how to the Presentation Model pattern in web site, Windows Forms application and WPF application. Model View View Model pattern is another name of Presentation Model.
On the recently published on the MSDN magazines, there are two articles about using the Model-View-ViewModel (MVVM) pattern in WPF (February, 2009) and Silverlight (March 2009). Maybe on the next issue of MSDN magazine, they will publish another article for using MVVM in ASP.NET. I continue my research to introduce the Dependency Injection and Event Broker into the pattern and have created a new project, named ASP.NET MVVM framework on codeplex.
April 26th, 2009
Visual Studio 2008 isolated mode shell reminds me the Eclipse rich client platform (RCP).
The most important architectural characteristics of Eclipse is the Plug-in architecture, which has concept of Plug-ins, Extensions and Extension-Points.
Plug-ins are the smallest deployable and installable software components of Eclipse. The similar concept in VS is VSPackage. After this eveything began to be very different.
Eclipse plug-ins are pure Java libraries on Java platform.
VS Packages are .NET libraries on COM based on platform through COM interop and MPF.
Eclipse plug-ins are described in XML.
VS replies on registry. VS Packages are using pkgdef and pkgundef files and code attributes.
……
From the Visual Studio 2008 Shell offcial definition:
The Microsoft Visual Studio 2008 Shell provides a core integrated development environment (IDE) to help you build and ship specialized languages and development tools.
Looks like it is only targetting development tools, not general application platform.
What about DSL then? Bound DSL only to VS shell is really limitting the potentials of DSL.
March 9th, 2008
I have created two DSL projects on codeplex.com.
Agile Planner: A This tool is for agile project teams, who currently are using sticky notes on the wall. With this tool stories, backlog and iterations are managed in a graphic designer, saved as files within visual studio projects and can be exported to images, reports and etc.
SharePoint Services Site Top Navigation DSL: A DSL tool that models top navigation of WSS sites with a code generator that generates PowerShell scripts to create the navigation bar.
All successed with visual studio integrated mode (deploy as vspackages). All stucked with isolated mode (deploy as a stand alone application). It took me 2-3 day each to do DSL model. Now more than a week passed, I still did not finish a shell.
I wish I can host DSL designer directly, because it is really difficult to customize Visual Studio Isolated Shell. I explained in MSDN forum thread Re: Can we host DSL designer in a custom host application?
As using VS isolated shall for DSL, my first difficulty is to organize/hide the out-of-the-box packages, editors, templates. After copied the pkgundef file from the story board designer, web site template is gone, but something like “connect to database”, “class view”, “code definition window” are still there. Those GUIDs are pretty hard to manage.
Second difficulty is to deal with solution-project-file concept in VS. To implement custom project like in the story board designer is not easy. Actually I just want simple File | New, Open, Save …, not to use solution and project at all.
I thought maybe I can hide all out-of-box menus and supply my own menus. Then it comes to the thrid difficulty, which is to customize menus. VSCT is much better then CTC, but it requires editing XML file and matching GUIDs, IDs in code. Compare using visual studio cutomize ribbon and task pane for Word and Excel, how hard it is.
One day, customization of visual studio will become as easy as customization of Office applications. I believe that. But it will still face the requirement of integrating DSL designer with LOB applications. DSL has possible wider usage outside of development(code generation) world. DSL designer is expected to appear in custom applications, SharePoint sites and Office applications. For example, if the DSL designer is hosted in Word, our BA can then use the story board designer while writing the documents.
So please MSFT, consider unleashing the potentials of DSL. Follow the workflow designer brother, free the DSL designer to outside of VS shell.
IMHO, DSL itself can be a great product, not just a visual studio extension.
March 9th, 2008
I used to think controller in MVC is to separate the view and the model, until I saw this blog An Introduction to the Model-View-Controller, Model-View-Presenter, and Presentation-Abstraction-Control Patterns where Derek Greer wrote,
One common misconception about the relationship between the MVC components is that the purpose of the Controller is to separate the View from the Model. While the MVC pattern does decouple the application’s domain layer from its presentation layer, this is achieved through the Observer Pattern, not through the Controller. The Controller’s job is to mediate between the human and the application, not between the View and the Model.
While the original idea of the Presenter was seen by the Taligent team as a Controller elevated to an application level, the Dolphin team mistakenly considered it a replacement of the VisualWorks’ Application Model and maintained the Presenter as a mediating component within the triad.
- In MVC, controller is the human to model connector (intercepts user input).
- In Taligent MVP, the presenter is the subsystem component connector (manages application subsystems).
- In Dolphin MVP, the presenter is the presentation to domain connector (manages access to model updates).
- In Passive View, the presenter manages presentation logic.
- In Supervising Controller, the presenter assists with presentation logic.
February 10th, 2008
The code beside technology is used by the visual studio designer. E.g. for each Windows Form, visual studio designer generates two partial classes, one for creating UI elements, and the other one is the place to write code. I think it is a MVP/Passive View already.
- Windows Froms App, The SomeForm.designer.cs is the view and the SomeForm.cs is the presenter.
- ASP.NET, the aspx/ascx is the view and the aspx.cs/ascx.cs is the presenter.
- WPF, the xmal is the view and the xmal.cs is the presenter.
If it Visual Studio generates an interface, ISomeForm.cs. Then have SomeForm.cs reference to this interface, instead of being partial class of the view. It is exactly MVP/Passive View. This would make unit testing easy based on ISomeForm.cs and SomeForm.cs. I would not mind if Visual Studio does this (in fact it might be something good to suggest MS to do).
In SCSF and WCSF, there has to be another presenter class. This makes me feel it is a redundant, because presenter class ties/couples to the view. It can hardly be reused. And you have to create extra code to delegate user input/UI events to the presenter. That’s part of reasons why I am not satisfied w/ MVP in SCSF and WCSF.
The original force of MVP is to ease unit testing. Current unit testing on the presenter is to mock interfaces of view and model. Because there is no other better method, this leaves the mocking on interfaces only one to use practically.
What about to have a tool that generates mock object from aspx/ascx to make aspx.cs/ascx.cs unit test-able?
February 10th, 2008
ASP.NET framework is already a MVC framework that allows to implement MVC.
Within ASP.NET, there is a front controller.
The controller itself is usually implemented in two parts: a handler and a hierarchy of commands. The handler has two responsibilities:
Retrieve parameters. The handler receives the HTTP Post or Get request from the Web server and retrieves relevant parameters from the request.
Select commands. The handler uses the parameters from the request first to choose the correct command and then to transfers control to the command for processing.
The commands themselves are also part of the controller. The commands represent the specific actions as described in the Command pattern [Gamma95]. Representing commands as individual objects allows the controller to interact with all commands in a generic way, as opposed to invoking specific methods on a common command class. After the command object completes the action, the command chooses which view to use to render the page.
The upcoming ASP.NET MVC framework is another front controller implementation.
ASP.NET’s default front controller truns plain http request into view state and server side events. ASP.NET AJAX extended the ASP.NET web form to support partial page render.
ASP.NET MVC replaced (not extended) the default front controller, so that there won’t be view state, nor server side event any more, in order to have SEO/REST style URL. Not sure if it is worth to trade REST style URL with view state, server side events and partial page render.
February 10th, 2008
I have uploaded two articles to codeproject.com.
Presentation Model in Action
Presentation Model in SharePoint
In the second article, because I wanted it to be focused on Presentation Model itself, one peice omitted which is using SharePoint Designer 2007 to create a new aspx page.

To do so, the code needs to be in aspx and created the file, web.config needs to be modified to allow compilation on the page.
<pageparserpath VirtualPath= “/Customer4.aspx” CompilationMode=”Always” AllowServerSideScript=”True” AllowUnsafeControls=”True” />
February 10th, 2008
Refers to an operation that produces the same results no matter how many times it is performed. For example, if a request to delete a file is successfully completed for one program, all subsequent requests to delete that file from other programs would return the same success confirmation message if the delete function were idempotent. In a function that is not idempotent, an error would be returned for the second and subsequent requests indicating that the file was not there, and that error condition might cause the program to halt. If all that were desired was to ensure a certain file was deleted, an idempotent delete function would return the same success result no matter how many times it was executed for the same file.
January 21st, 2008
Story began when I was customizing some wordpress templates on my vista powered PC. I was curious what kind of PHP source code is behind the “the_content” tag, so that I tried to type word “the_content” in the windows explorer’s search box. This search did not appear to work. No file found.
This triggered a long journey digging into how to search the text in php files.
Method 1: Use Visual Studio, Edit | Find in files … (27 files found)
Method 2: Use FINDSTR in command prompt.
>findstr /si the_content *.php
Method 3: Use PowerShell
> dir . *.php -r | select-string the_content | group-object Path | select-object Name, @{Expression={$_.Group | foreach {$_.LineNumber} }; Name=”Line Numbers”}, Count | format-list (c.f. this post)
Had so much fun learning PowerShell. :) Spent a lot time on this.
However, why Vista cannot search? The answer is the php files’ index options was “Indexing Properies”, but should be ”Indexing Properties and File Contents” in Control Panel - Classic View - Indexing Options - Advanced - File Types.
Finally also learnt that Vista search is word based, not character based. And maybe Vista search tokenized “the_content” same as “the content”, because the files have “the content” showed up, when searching “the_content”.
What a weekend, just like the comedy channel said, Time Well Wasted
January 20th, 2008
Here are the slide deck and source code used in my presentation about C# features for fellow developers. Topics include:
C# feature demo: Find even number from a list of integers:
- C# 1.x – Loop in Collection (Array)
- C# 1.x – Delegate (Custom Delegate)
- C# 2.0 – Iterators (yield return)
- C# 2.0 – Delegate (Predicate<T>)
- C# 2.0 – Anonymous Method
- C# 3.0 – Lambda Expression
- C# 3.0 – LINQ (Language integrated Query)
- C# 3.0 – Extended Method
LINQ demo: Match orders with appraisers
- Select: Default, Anonymous Class, Dictionary
- Where: Static, Dynamic Query
- Group: Aggregation, e.g. count
- Join: Inner Join, Out Join, Group Join
- Order: e.g. order by count desc
December 28th, 2007
Remebered the first Flash tutorial I saw was to morph/transform a rectangle into a circle. But This simple task cannot be done in Expression Blend 1.
Now with Expression Blend 2 preview, it is possible. This feature is called “Vertex Animation”.
Wait, I actually morphed a circle to rectangle, by converting circle into path on key frame 1 and editing the path to rectangle on key frame 2. It is not exactly same as the “Tweening: shape, Blend: Angular ” in Flash
How about morph text?
How about doing things like in the beginning Flash tutorials?
December 27th, 2007
Previous Posts