tag:blogger.com,1999:blog-15459430024549367642024-03-12T19:51:55.491-07:00Java 2 C#tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.comBlogger35125tag:blogger.com,1999:blog-1545943002454936764.post-37830153182472223082012-09-13T06:20:00.001-07:002012-09-13T06:22:46.452-07:00Where do the unit test code files go?Recently I came into some <a href="http://www.bryancook.net/2008/05/tdd-tips-unit-test-namespace.html" target="_blank">very old post about handling unit test code name space and locations</a>. It really looked a lot of effort for very simple tasks.<br />
<br />
I don't put my unit test code into a separate project/assembly. The reason is simple, the unit test codes is not secondary citizen and shall be treated as seriously as "production" codes, if not more seriously. You may argue that shipping unit test codes to end user is meaningless. While, I kind of agree. So if you do want stripping the unit tests off your production assembly, a little trick will help, wrap all your unit test codes with a macro check:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#if DEBUG</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">using NUnit.Framework;</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><span style="font-size: x-small;">namespace your.name.space</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span><br />
<br />
and the final release build will not contain any unit test codes. Still your assembly will depend on NUnit assembly and by default the NUnit DLL will appear in your release folder. Removing it won't do any harm.<br />
<br />
I came from Java camp and had the habit to put source code and test code side by side, that is, source code is under "project_root\src\" and test code under "project_root\Test\" folder. I know it's not a common practice in .NET world to have a "src" folder, but it does no harm and give me the feasibility to put more resource under the project root folder, besides the benefit of separate the unit test codes into different folders, so I'm going to stick with it. If you happen to have some convention to make folder structure appear in namespace structure, then another trick to overcome it is, in project browser, select the "src" folder and press F4 to bring up the property windows, then set the "contribute to namespace" option to false.<br />
<br />tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-51381334742506812502012-08-23T08:10:00.004-07:002012-08-23T08:10:47.473-07:00Recover Windows 7's Explorer from "No such interface supported" errorYesterday I experienced a disaster. After I installed and removed Google Drive client, Windows 7 seemed gone crazy: if I click on a document, some times it was opened, sometimes it was not; if I click on an application, nothing happens; if I input the application name, e.g. cmd.exe, in the Run dialog, it always complains "No such interface supported".<br />
<br />
I tried almost all the ways I could think / googled of:<br />
<br />
<ul>
<li>using Windows restore to restore to the point before Google Drive was removed, it did not work. I could only find 1 restore point, which was wired.</li>
<li>try to use some registry cleaner as suggested by some internet posts, it did not work too. (though the way I start the application is a little trick that I'll talk about)</li>
<li>re-register all the DLLs on my hard drive, as some posts suggested, which also did not work</li>
</ul>
<div>
Here is the trick to execute an application, when Explorer and Run dialog does not work: it seemed in my case the shell extension to open some of the linked file extensions was still partially working, so I created a file with a non-registered extension and dbl click to open it, then select the application you want to execute. This way, I managed to still execute applications. But applications started from this way could not elevate to administrator mode. Luckily I already made cmd.exe by default run under administrator, so it was not a problem to me.</div>
<div>
<br /></div>
<div>
Back to the problem, I was lucky to have a backup <i>local</i> user account with administrator rights, and I decided to try it out and it was not poisoned as my <i>domain </i>account. So I guess that the problem was the registry database of my domain account. So <b>after I have backup my files</b>, I went to the "advanced system settings" dialog (type the quoted string in the search box on start menu), pressed the "settings" button in the "User profiles" group box, and deleted my domain's profile. All the files under my "C:\Users\MyUser" folder was gone. So do remember backup your files!</div>
<div>
<br /></div>
<div>
This worked for me, use at your own risk.</div>
tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-54880442652459079912012-08-22T09:53:00.000-07:002012-08-23T08:11:27.564-07:00Push back to Gitblit over https, without a valid certificateNow I have a Gitblit server running, waiting to be connected. The good thing about Gitblit is, you do not even need Git on the server, its package contains a Java implementation of Git. In the long run, you still need it, since the document says git-gc is not properly implemented.<div>
<br /></div>
<div>
If you already have a Git repository on your local PC, and you want to push it to Gitblit, it's quite simple:</div>
<div>
<br /></div>
<div>
1. Using Gitblit's web GUI to create a new repository, assign share mode. If you want to block anonymous access, make sure you select "authenticated view, clone & push".<br />2. Open the repository you just created, and you'll see a link started with https://, click the copy to clipboard icon to copy the link to clipboard<br />3. Start Git console and navigate to your local Git folder<br />4. Run below command: (
you shall be able to paste the link from clipboard )<br /><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> git remote add origin https://yourpcname:yourport/git/yourrepo <br /> git push origin master</span></div>
<div>
and bang! you'll hit below error:<br /><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> "SSL certificate problem, verify that the CA cert is OK."</span></div>
<div>
This is because Git will verify if the server's certificate is a valid certificate. If you are a poor man as I am, you probably don't have a valid certificate. Set an environment variable will make Git skip the verification step (I put this line in the ~/.bashrc file to avoid type it each time)<br /><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $ export GIT_SSL_NO_VERIFY=true </span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> $ git push origin master</span></div>
<div>
<br /></div>
<div>
This will push you master branch to Gitblit. Then you can go to web UI to verify it.</div>
<div>
<br /></div>
<div>
Another way to overcome this certificate issue is to create your own root certificate, import it as trusted root certificate, then create a certificate and sign it with the root certificate. </div>
tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-21040642975548860092012-08-22T06:41:00.003-07:002012-08-22T09:30:34.397-07:00Setup Gitblit on windows server 2003Git is by its nature friendly to *nix systems. So <a href="http://java2cs2.blogspot.com/2010/08/setting-up-git-server-using-apache-on.html" target="_blank">setting up a Git repository on Windows</a> has been really painful: quite several tools need to be integrated, sophisticated steps need to be performed. In short, it's time consuming, error prone, and hard. I tried it once, and do not want to try it again.<br />
<br />
Recently I read about (forgot the article, sorry) this new OS project, <a href="http://gitblit.com/" target="_blank">Gitblit</a>, which really make hosting Git repository on Windows a easy task. It's a Java application, which means it runs on not only *nix, but also Windows! They provide several packages for different usage scenarios, and also good document.<br />
<br />
The setup process is very easy:<br />
<br />
<ul>
<li>Download the "Gitblit Go" package, unzipped to the folder you plan to hold the software</li>
<li>Go to the folder, edit the installService.cmd file and change the "SET ARCH= " line. My server is x86 based, while the default setting is amd86</li>
<li>Edit the gitblit.properties, point git.repositoriesFolder to the folder where you hold your Git repositories. Note you should use forward slash even on Windows, e.g C:/GitRepo/. Change server.httpsBindInterface to empty to bind https to all ip addresses. By default it only binds to localhost, which will not allow other computers accessing it</li>
<li>Run makekeystore.cmd to create a self-certified key for https</li>
<li>Run installService.cmd to install it as a Windows service
</li>
<li>Start the service and launch browser to navigate to https://yourpcname:8443, and login with admin/admin</li>
<li>Change the password of admin immediately.</li>
</ul>
And you are done!<br />
<br />
You will want to examine the gitblit.properties for possible configurations. Most of the items are documented very well so for most items you can just read through the config file and config properly without searching through documents.tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com2tag:blogger.com,1999:blog-1545943002454936764.post-2109408371262681952012-07-06T07:56:00.005-07:002012-07-06T07:56:45.010-07:00Some Bash tips from othersI'm mostly a Windows guy. All my computers are loaded with Windows. I know how to use *nix, though not very efficiently. Since I started using Git, I have to deal with Bash more and more, through MinGW. Thus it's better to pickup some tricks of Bash to work more efficiently.<br />
<br />
<br />
<ol>
<li><span style="font-family: 'Courier New', Courier, monospace;">!$</span>: will be replaced with the last parameter to the last command. For example, if you just executed a command like this:<br /> <span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> ls /a/very/long/path</span><br />and then you want to know the detail of what's in the path, a simple way of doing it is:<br /><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;"> ls -l !$<br /><span style="font-family: 'Times New Roman'; font-size: small;">If !$ is modified with :h, then the last part of the path is removed.</span></span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">^</span>: leading ^ will start replacing last command line with something new. Coming from last example, if part of the path is wrong, then you can try this:<br /> ^wrong^correct</li>
</ol>
<div>
More info can be found in this link: <a href="http://samrowe.com/wordpress/advancing-in-the-bash-shell/">http://samrowe.com/wordpress/advancing-in-the-bash-shell/</a></div>
tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-28221635902272612242012-06-11T07:39:00.003-07:002012-08-23T08:11:39.137-07:001st try on VS2012After several hours download and installation, I finally can start trying the RC. From first sight, I really can not say I like the UI. Too much change and all black-white icon really make it hard to find the correct icon. Luckily I'm mainly a keyboard guy and does not use toolbars often. With R# EAP version installed, I don't really need to even drop down the stupid all capital case MENU. BTW, install the removeCAPS extension can help you easily turn it back to normal.<br /><br />There are things I like about it. Even it's not released version, it's really stable, and the responsiveness is much better than VS2010. Also I can work with VS2010 solution file and project files without any problem. This is a must have feature for try out on projects you share with team.tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-9468427984322977252012-05-10T09:24:00.002-07:002012-09-13T06:24:22.414-07:00MSysGit mergetool broken after 1.7.7I've been <a href="http://cbilson.blogspot.de/2008/10/using-beyond-compare-as-git-mergetool.html">using Git on Windows (MSysGit) happily with BeyondCompare 3</a> for quite a while. Mostly I use BC3 to view changes. Occasionally I use it to merge conflicts. I don't merge very often, thanks to Git's powerful merging capability. It has worked fine. Recently I upgraded to version 1.7.10-preview20120409, and suddenly the git's merge command always fail with below error messages:<br />
<br />
<pre>
Merging:
my/path/filename.cs
Normal merge conflict for 'my/path/filename.cs':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (BC3):
git_path/libexec/git-core/mergetools/BC3: line 9: bcompare: command not found
my/path/filename.cs seems unchanged.
Was the merge successful? [y/n] n</pre>
<br />
<br />
Where is this line 9? It turns out that it seems MSysGit (or Git?) has put all merge tools to a folder named "git_path/libexec/git-core/mergetools/". In my installation, I can already find quite a bunch of tools:<br />
<br />
<pre>
araxis
bc3
defaults
deltawalker
diffuse
ecmerge
emerge
kdiff3
kompare
meld
opendiff
p4merge
tkdiff
tortoisemerge
vim
xxdiff</pre>
<br />
<br />
and they are actually bash scripts. For example, the bc3 file is like below:<br />
<br />
<pre>
diff_cmd () {
"$merge_tool_path" "$LOCAL" "$REMOTE"
}
merge_cmd () {
touch "$BACKUP"
if $base_present
then
"$merge_tool_path" "$LOCAL" "$REMOTE" "$BASE" \
-mergeoutput="$MERGED"
else
"$merge_tool_path" "$LOCAL" "$REMOTE" \
-mergeoutput="$MERGED"
fi
check_unchanged
}
translate_merge_tool_path() {
if type bcomp >/dev/null 2>/dev/null
then
echo bcomp
else
echo bcompare
fi
}</pre>
<br />
<br />
and there is really is a line 9! Of course directly modify the file will do the trick. But I guess there are better ways. After testing around, trying to override the merge_tool_path environment variable, <b>I found it's easier if I just put BC3's folder to path, and nothing else need to be changed!</b>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-57209415536208399412012-05-04T07:20:00.001-07:002012-08-23T08:12:12.003-07:00Git: generate patches, after or before commit happens.Occasionally, if not often, I need to generate patches to be applied to another git copy. This can happen either before I commit or after. It turns out, the ways to do it for the two scenarios are different.<br />
<br />
If the change set is already committed, then below command line can generate the patch:
<br />
<pre></pre>
<pre></pre>
<pre></pre>
<pre>git format-patch -1</pre>
<br />
This will create a patch in the current folder with file name like <span style="font-family: 'Courier New', Courier, monospace;">0001-comments-in-the-commit.patch</span>. <br />
<pre></pre>
-1 in the command line means generating patch for last one commit. If you want to patch in more commits, specify the number here. If you don't like the default file name and want to specify your own output file name, then you can direct output to stdout and the redirect stdout to a file, like below:
<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"> git format-patch -1 --stdout > your_file_name.patch
</span><br />
<br />
So how do you do it when you don't want to commit the changes? A simple way is to generate the diff output and redirect it to a file. The problems is, like most people, I'm not satisfied with git's diff output and I use a graphical tool, BeyandCompare, to do the diff viewing. If I execute <br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"> git diff > pathfile.txt</span>
<br />
<br />
<br />
the BC is invoked and there is nothing redirected to the patch file, unsurprisingly. So how to force the diff command to skip the GUI tool? As in most of the cases, a command line switch comes to help: --no-ext-diff. Below command line will happily output the result to console and skip BC:
<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;"> git diff --no-ext-diff</span>
Applying patches generated with <span style="font-family: 'Courier New', Courier, monospace;">git diff</span> is simple:
<br/>
<span style="font-family: 'Courier New', Courier, monospace;">patch -p1 < patch-file.txt</span>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-28367486890950542172012-02-14T08:22:00.004-08:002012-08-23T08:12:11.998-07:00git diff: ignore the deleted files and newly added filesI have a project that has gone through some serious refactoring, during which a lot of garbage files were removed. Then during a code review, the HEAD was compared with the last release tag and bang!, BeyandCompare UI was popped up so many times that we had to abort it after a while.<br /><br /><pre class="prettyprint"><br />git diff sha-for-pre-release<br /></pre><br /><br />Then I though there must be a way to skip this and it turned out there is. When using git diff, there is an option, <tt>--diff-filter</tt>, among tons of others. And below are excerpted from the manual:<br /><br /><pre><br />--diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]] <br />Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type(i.e. regular file, symlink, submodule, …) changed (T), are Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected. <br /></pre><br /><br />My favorite option is <tt>--diff-filter=MRT</tt>, which will skip added and delete files.tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-81919880413591603002012-02-04T06:12:00.000-08:002012-02-04T06:51:59.761-08:00Configurations of application using IoC, Spring.NETI have being using Spring when I worked in Java world. Now that I'm in C# part of the world, I'd naturally go with Spring.NET. To be honest, before using Spring.NET, I did not even heard about StructureMap, Windsor, Autofac, NInject, let alone the Funq, Munq, Light.Core, etc. In general, I could live with XML configuration, and some configuration feature derived from XML really makes passing configuration data much easier, by putting below object definition in the container, you can isolate your often changed settings to a file without writing any glue code:<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> <object id="SYSTEM.ConfigPropertyHolder" type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core"><br /> <property name="LastLocationOverrides" value="true"/><br /> <property name="ConfigSections" value="config.app"/><br /> <property name="Locations"><br /> <list><br /> <value>~/Config/config.app.xml</value><br /> </list><br /> </property><br /> </object><br /><br /></code></pre><br /><br />now I can use a file named "config.app.xml", in folder Config, to hold my config settings:<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code><br /><?xml version="1.0" encoding="utf-8" ?><br /><configuration><br /> <configSections><br /> <section name="config.app" type="System.Configuration.NameValueSectionHandler, System" /><br /> </configSections><br /><br /> <config.app><br /> <add key="value1" value="some data" /><br /> <add key="value2" value="other data" /><br /> ...<br /> </config.app><br /></configuration><br /><br /></code></pre><br /><br />and in the container definition xml file, I can use the settings defined in the config file:<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> <object id="obj_id" type="type.name"><br /> <constructor-arg name="para1name" value="${value1}"/><br /> <property name="pro1name" value="${value2}"/><br /> </object><br /><br /></code></pre><br /><br />And since most of Spring.NET's objects are defined with an id, there is even a further way to do the customization, using another class "Spring.Objects.Factory.Config.PropertyOverrideConfigurer, Spring.Core". Put such an object definition in container, <br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code><br /> <object id="SYSTEM.ConfigPropertyOverride" type="Spring.Objects.Factory.Config.PropertyOverrideConfigurer, Spring.Core"><br /> <property name="IgnoreResourceNotFound" value="true"/><br /> <property name="ConfigSections" value="config.system"/><br /> <property name="Locations"><br /> <list><br /> <value>~/Config/config.sys.xml</value><br /> </list><br /> </property><br /> </object><br /><br /></code></pre><br /><br />you gain the capability to directly change object properties in config.sys.app:<br /><br /><pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code> <config.system><br /><br /> <!--the key must be a <object_in_context>.<property>--><br /> <add key="obj_id.someProperty" value="12345"/><br /> <add key="another_obj.anotherProp" value="good!"/><br /> ...<br /> </config.system><br /><br /></code></pre><br /><br />Ugly or not, it's really convenient and powerful. In general, Spring.NET is really a feature rich software package, not only a IoC container. And also the document is really good, comparing to most other OSS projects. <br /><br />So what's the problem? The problem is I'm getting more and more tired with the angle brackets, and I would like to try something new, like NInject, Autofac.tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com2tag:blogger.com,1999:blog-1545943002454936764.post-77387408633953690102012-02-02T07:29:00.000-08:002012-08-23T08:12:12.008-07:00SubWCRev.exe and its dependenciesOur team is using Subversion as CVS, and thus it's natural to use SubWCRev.exe to retrieve source code version and embed into VersionInfo.cs file, so we can already rebuild the software when we get a bug report.<br /><br />The problem is when the build process is running on build server, there is no TortoiseSVN installed on the server and I don't want to install it on all the build agents. So I took some time to find out the dlls that SubWCRev.exe depends on, in case I forget it:<br /><br /># intl3_tsvn32.dll<br /># libapr_tsvn32.dll<br /># libaprutil_tsvn32.dll<br /># libsasl32.dll<br /># libsvn_tsvn32.dlltcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-61290987678679644502012-01-21T05:16:00.000-08:002012-08-23T08:12:12.006-07:00tell Git to do ignore your changes to some filesNormally Git is so powerful with its branching capabilities, that you seldom need this feature. But sometimes it can be handy if you can simply tell Git to "pretend" that you have not changed some files, even they have really been changed.<div><br /></div><div>If you are using Git as a SVN client, like I do, you will know that Git refuses sync with SVN with local changes. In a large project, it can be that there is a common development environment with a common deployed application server so the client developers can connect and debug without worrying about setup their own instances. So it's also common that when you checkout codes out of the server, in my case it's a SVN repository, the config file contains URL pointing to that common server. If you are the server side developer, then you have to start your own instance and use a client to connect to it. Then you have to change the config file to point the URL to your instance and remember never commit the changes ,otherwise your colleague will kill you :)<div><br /></div><div>There are a bunch of ways to overcome this. You can first only check in your changes without the config files, then stash the config files and then commit to SVN. Or you can create your own local branch with your config files, checkout and rebase the branch each time you want to debug with your config, which is what I'm doing now. </div><div><br /></div><div>A new way I realized today while reading <a href="http://kozmic.pl/2012/01/18/testing-framework-is-not-just-for-writing-tests">this post</a> was, I can tell Git simply ignore the changes you have made to some files, with below command: </div></div><div><blockquote>git update-index --assume-unchanged somefile.txt</blockquote></div><div>this way Git will assume the file is never changed and will perform happily whatever command you want that can normally only be performed to a clean copy. So what happens that the file is changed in upstream repository? By manual, "Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually."</div><div><br /></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-11469460632455908042012-01-20T01:59:00.000-08:002012-01-20T02:05:00.857-08:00Trick to make LiveMeeting addon for Outlook 2007 automatically connected.Yes, my company uses Microsoft Office and related tools to handle normal communication. But some times it happens that the add-on is loaded but not really activated. You'll still see the LiveMeeting toolbar in outlook toolbar, but just one button "Enable LiveMeeting" there. This is annoying since you have to remember to push it each time you start outlook.<div><br /></div><div>There is a simple solution to it: go to "start->all programes->microsoft office->microsoft office tools" and select the "microsoft office 2007 language settings", change the language to some other value, save it. Then open it again and change it back to your preferred language. Then start outlook again, you'll find the add-on is activated automatically with 3 buttons.</div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-49286371286077835812012-01-17T08:39:00.000-08:002012-09-13T06:25:18.740-07:00Simple.Data, is it really a good idea?I've been keeping an eye on <a href="http://yobriefca.se/blog/2011/06/21/microorms-for-dotnet-inserts-updates-deletes/">micro ORMs</a> for a while. Yesterday I decided to give <a href="https://github.com/markrendle/Simple.Data">Simple.Data</a> a try. From the introduction, it looks brilliant, the fluent API, the briefness, the simplicity,..., everything seems to be perfect... well, until I started coding.<div><br /></div><div>Once I'm in VS, I immediately realized that Simple.Data might not be the one I wanted. Its magical syntax heavily depends on .NET's new dynamic feature (yes, it's .NET 4 and above only). That means you loose the static language's best capability: compile time checking. And also you loose the productivity from your tool, there is almost no intellisense provided by VS. You might say, what's the big deal, the syntax is cool. Yes, it's cool. But the problem is, if you make an accident typing or a normal typo (who doesn't?), then compiler won't be there for you and you'll only get the null at runtime. Maybe through unit test coverage may resolve this. But from where I stand, it seems to be just a better alternative of HQL dressed with a new cloth named fluent API.</div><div><br /></div><div>But I did find some part that really make me happy. It seems Simple.Data recognizes fields separated by underscore. I've got a table with columns like CUSTOMER_ID, and Simple.Data can happily map it to a property named CustomerId. If I rename CUSTOMERID, then Simple.Data still works fine. This is clever!</div><div><br /></div><div>There is a tool, Simple.Data.Pad, to address this issue. So far I haven't been able to make it work with sqlite yet.</div><div><br /></div><div>In general, I'm not so convinced yet, but I'll continue on the project to work with it, let's see where I'm going to end with.</div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-62422268551929123932012-01-15T08:49:00.000-08:002012-09-13T06:25:18.742-07:00.Net code contractsI knew there is something new in .NET 4 called code contracts and I also saw some simple code snippets about it. Without digging in, I though it was just some fluent code sugar to help you replace assertions like <div><blockquote><span> if (input_int > 0) throw new ArgumentException("some msg");</span></blockquote></div><div>with </div><div><div><blockquote><span>Contracts.Requires<argumentexception>(input_int > 0);</span></blockquote></div>and come on, this fluent sucks, requires an exception? I would have written a better one!</div><div><br /></div><div>But I was wrong! </div><div><br /></div><div>I had some free time today and I opened a long bookmarked <a href="http://msdn.microsoft.com/en-us/magazine/ee236408.aspx">url</a> and took a look at it. After reading through the first section, I knew I was wrong. There was post compile code weaving and checking. Without it, there is not much virtual inside, but with the post process, everything can happen. And it turns out to be a very much valuable technology than I thought. Kudos!</div><div><br /></div><div>Some simple googling led me to <a href="http://www.abhisheksur.com/2011/02/code-contracts-in-net-40-its-internals.html">this blog</a> that provides some analysis I would also do, using Reflector on the generated code, to see the magic there. Also in their <a href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx">home page</a>, there is a video at the bottom(?!) of the page, after some random comments!</div><div><br /></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-13610617197831586902012-01-11T08:51:00.001-08:002012-09-13T06:25:18.737-07:00Differences between event and delegate in C#I did not realized some of them until I came across <a href="http://blog.monstuff.com/archives/000040.html">this article</a>. In short, <div><br /></div><div><ol><li>event is a modifier and delegate is a normal type declaration</li><li>thus event can be used in interfaces and delegates can not</li><li>event can only be accessed by the class defines it, not even the child classes (an in-direct access through protected method is possible), while delegate is more like a member</li><li>normally event follows a convention on signature: <i style="color: rgb(51, 51, 51); font-family: palatino, georgia, verdana, arial, sans-serif; line-height: 26px; text-align: justify; background-color: rgb(255, 255, 255); font-size: small; ">foo(object source, EventArgs e)</i></li></ol><div style="text-align: justify;"><span ><span style="line-height: 26px;"><i><br /></i></span></span></div></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-55057239767458023322012-01-08T14:20:00.001-08:002012-01-08T14:49:48.039-08:00Start on PythonIt's being quite a while since my last blog and I would like to have something really new to start the new year, Python.<br /><br />Recently I started teaching my son Python. I don't know Python before. So I have to learn it while teaching him. I intended to learn Python for quite some time, but time has always been my biggest enemy, together with my memory: it's getting worse every year. If I learn something and don't use it immediately, then it's quite possible after 3 months, I'm new to it again. So I start blogging it, trying to make my memory last longer.<br /><br />Python is an elegant language, it's very expressive and has very brief syntax - though this can be a double side sword - to a experienced programmer with long time Java/C#/C++/C experience, it takes some time to be used to it.<br /><br />Some points about Python I'd like to note down:<br /><br /><ol><li>Python started at 1989, and first public appeared at 1991</li><li>CPython is the C implemented version of Python, then standard Python</li><li>Python generally has 2 kinds of primary types: numbers and strings, though array/list and hashtable/dictionary is first class member of the language.</li><li>Python use space indention to indicate sub-scope. The indent does not have to be unified within program, but must be the same for the same scope</li><li>like most script languages, variables do not need to be pre-claimed before being used</li><li>Python can be compiled into byte codes, like Java class files, with extension .pyo or .pyc</li><li>using '''/""", you can have multiple line strings</li><li>raw string starts with a 'r': <b>r</b>"c:\a\path\file"</li><li>unicode string starts with a 'u': u"this is unicode"</li><li>raw_input() will return anything you input as a string, while input() will try to evaluate your input as Python code! For example:<br /><blockquote>>>> a = 3<br />>>> b = input()<br />a+11<br />>>> b<br />14</blockquote></li><li>Python as +=, -=, *=, /=, similar to other languages, but no i++, ++i, i-- or --i. But ++i or --i won't give you any syntax error, since the +/- are treated two time sign prefix!</li></ol>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-70048121145799027652011-10-04T07:30:00.000-07:002011-10-04T07:43:39.767-07:00substring in unix shell scriptsRecently I need to handle quite some unix shell scripts and find <a href="http://www.arachnoid.com/linux/shell_programming.html">some tricks</a> about strings that is less known.<div><br /></div><div><span class="Apple-style-span"><b>1. substring</b></span></div><div>Most of my searches resulted using awk. I don't mind using it, but it make the script less readable. Luckily there is a easy way:</div><div><blockquote><span class="Apple-style-span">one_str="this is a string"<br />sub_str=${one_str:5:2} # ${org_str_var:0_based_index:length}<br /># now sub_str contains "is"</span></blockquote></div><div><span class="Apple-style-span"><b>2. string search and replacement</b></span></div><div>Again, most search results say you should use "sed" or other external commands. But below line will also do the trick:</div><div><blockquote><span class="Apple-style-span">alpha="This is a test string in which the word \"test\" is replaced." beta="${alpha/test/replace}" #replace only the 1st insance<br />beta="${alpha//test/replace}" #replace all insances</span></blockquote><br /></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-79527232348550216942011-09-23T06:42:00.000-07:002011-09-23T06:46:59.869-07:00.NET/windows Debugger list.It's been quite a while since my last post. Anyway, I don't have any followers and this is just for myself to keep some ideas here.<div><br /></div><div>This <a href="http://blogs.msdn.com/b/dau-blog/archive/2011/09/22/debugging-tools-survival-guide.aspx">link</a> gives a description of several debuggers/tools and their best usage scenarios. Though it seems to be quite powerful, I really hope some tools that can do debugger record and play <a href="http://www.infoq.com/articles/recording-jvm-debuggers">like the Java world has now.</a></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-75538051806147273382011-07-15T01:58:00.000-07:002011-07-15T03:01:21.104-07:00Git as SVN client: rollback to previous versionGit is a very power content based DCVS. I use it as a SVN client, since my company is still using SVN. I've been quite happy until yesterday: I made a mistake in a commit and need to roll it back. The problem is I already checked in to SVN and it broke some unit tests I did not cover on my local run, but the CI server did. I'm used to local reset to revert some bad changes, but this will only help when you have not pushed changes to remote sites:<div><blockquote><span class="Apple-style-span"> <span class="Apple-style-span">git reset HEAD~</span></span></blockquote></div><div>Above command will reset your master pointing to the previous commit. From Git's point of view, it's done. The current HEAD (master) now points to the desired copy of the codes you want to have. But the problem is once you do a synchronization with SVN, it's going to be reset back to the copy you want to get rid of. This is because Git is treating master tag as a pointer. When you do the above reset, it just move the pointer back without doing any real commit. So here what we really need is a "real" commit, which "git revert" provides. </div><div><blockquote><span class="Apple-style-span">git revert HEAD</span></blockquote>After this, if you look at the history, you'll find a commit with the new result. Now synchronize with SVN and you'll find a new commit in it and the changes you made has been rolled back.</div><div><br /></div><div>Note, <span class="Apple-style-span">git revert</span> should only use when you have pushed your changes to remote sites. Then it gives you a chance to fix the problem. If your change is still local, <span class="Apple-style-span">git reset</span> is recommended.</div><div><br /></div><div>Maybe this is stupid, but it took me a while to figure this out, hope this helps some one out there who is also bothered by this.</div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-63447819541423112192010-09-28T06:02:00.000-07:002010-10-04T07:52:04.208-07:00Installing Redmine on WindowsRedmine is an excellent project/issue/bug tracking tool. As of this writing, V1.0.1 is just released. I guess V2 is going to be based on RoR V3.<br /><br />Most of the installation is just no brainer, following the <a href="http://www.redmine.org/wiki/redmine/RedmineInstall">directions in their website</a>. I used a MySql and setup a initial DB is also very easy, though I did have to follow the installation instruction to download the <a href="http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll">MySql Dll</a>.<br /><br />Now you should be able to start the application from command line. But wait, normally you should <a href="http://noobonrails.blogspot.com/2006/06/how-to-setup-mongrel-as-native-windows.html">use mongrel </a>or webrick as your webserver. A "gem install mongrel" will do the trick. And further, you might want to run your website as a service, following <a href="http://noobonrails.blogspot.com/2006/06/how-to-setup-mongrel-as-native-windows.html">most of the advices </a>to run mongrel as a windows service will require you build a native dll. I don't want to install cygwin or gcc to just compile those stupid dlls. Therefore I followed the <a href="http://www.redmine.org/boards/1/topics/4123">advice in Redmine's website. </a>Actually if you download the Win 2003 Res Kit, you can find the directions also in help on topic srvany.exe.<div><br /></div><div>Another bloody experience, which took me 3 hours to figure out was, don't run the service under LocalSystem account, which will prevent network access. It seems this will block subversion access!<br /><br />Integrating SVN to Redmine can be a little tricky.<br />1. You need the svn.exe file on system path. Don't forget to re-open a cmd window after you have changed the system path.<br />2. If you use https protocol, another trick is, you have to run below command to accept the certificate (permanantly) from the server, then everything will be fine.<br />3. And if you specify any special user rights to your repository, don't forget to grant at least read-only access to the user you specified in Redmine.<br />4. If you are integrating to a repository with huge history, the intial importing can take a long time.<br /><br />Authenticating using Active Directory is also a little tricky. You can use this image as a reference.<br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghrt54jPB9P73TS6LBgFdV2slZBFP3GowLXKxIthji5NWGVG_mu8t6sE73wKTjkgH72KP9S-LOWjwy9r2Z4kHMjL4IdGbf8Ab-X-3TNNMp8FnzLM6INXEJoQMBzRgk6vLqwA5m9KZSNb51/s1600/Redmine-AD-Auth.PNG"><img style="MARGIN: 0px 10px 10px 0px; WIDTH: 221px; FLOAT: left; HEIGHT: 320px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5521955864625026786" border="0" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghrt54jPB9P73TS6LBgFdV2slZBFP3GowLXKxIthji5NWGVG_mu8t6sE73wKTjkgH72KP9S-LOWjwy9r2Z4kHMjL4IdGbf8Ab-X-3TNNMp8FnzLM6INXEJoQMBzRgk6vLqwA5m9KZSNb51/s320/Redmine-AD-Auth.PNG" /></a></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-16523362532757219622010-08-09T13:41:00.001-07:002010-08-09T13:55:33.056-07:00TDD, it's not about testing.I subscribed a lot of blogs and it seems in their world, TDD is something that needs not to explain, at least the name it self is as clear as the name of "Unix". But sadly I discovered this might only be true in some software house, but not in most of the IT departments in normal companies. <div><br /></div><div>Anyway, I found some <a href="http://www.bigvisible.com/asroka/what-is-test-driven-development/">good explanation</a> about TDD, which is very insightful. TDD is not about testing, it's about design. The tests to guarantee quality, to weave the safe-net is a valuable byproduct.</div><div><br /></div><div>I recall one of the API for a report generator. The report format looks complex. I decided to design a model for the report, and once the model is done, generating the report should be straight forward. I started with some tests to generate part of the data the report needs, this forced me to think about the model structure and API in another angle. And finally it turned out a very different, if not completely different, but simple API. I reviewed it and was glad about its elegance. I would not be able to design such a nice API if I test after!</div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-57970809397702230072010-08-01T08:13:00.000-07:002012-08-22T09:55:14.262-07:00Setting up Git server using Apache on WindowsUpdate: <a href="http://java2cs2.blogspot.de/2012/08/setup-gitblit-on-windows-server-2003.html" target="_blank">Gitblit is a better choice!</a><br />
<br />
I posted <a href="http://java2cs2.blogspot.com/2010/03/setup-git-server-on-windows-machine.html">an article</a> to setup a Git server on windows using MSysGit, with Git's native transport protocol. Though it works good, the setup of SSH server and client is not a easy cake to some. Git's HTTP support on Windows was known to be less efficient. But given today's hardware and especially if you are using it in an enterprise environment, this can hardly be a problem than the complex setup process of SSH ways. Recently I found a way of creating <a href="http://www.jeremyskinner.co.uk/2010/07/31/hosting-a-git-server-under-apache-on-windows/">Git server using Apache</a> and it's both simple and comprehensive. So take a look.tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-11954471607654302992010-05-28T14:13:00.000-07:002010-05-28T14:17:16.568-07:00Great FitNesse tutorial!I was attracted by FitNesse recently and found this<a href="http://schuchert.wikispaces.com/FitNesse.Tutorials"> great tutorial</a> from <span class="Apple-style-span" style="font-family: 'Times New Roman', serif; line-height: 16px; ">Brett who is working with uncle bob at ObjectMentor.</span><div><span class="Apple-style-span" style="font-family: 'Times New Roman', serif; line-height: 16px; "><br /></span></div><div><span class="Apple-style-span" style="font-family: 'Times New Roman', serif; line-height: 16px; ">The tutorial is great since it not only introduced the concept, but also a really good example to guide you through the door. Meanwhile, without bending rules by ugly codes.</span></div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0tag:blogger.com,1999:blog-1545943002454936764.post-62484295024432422152010-05-28T12:37:00.001-07:002010-05-28T13:53:07.521-07:00Is public field still so evil in C#?In Java, there is a rule: "never make your field public". This rule is borrowed by C# when a lot of Java programmers jumped to .NET. I'm one of them and I loyally kept that habit, you will find no public field defined in classes from my hand. While, not exactly. That changed recently.<div><br /></div><div>One of the main reason of "keep fields private" in Java was, field accessors and method calls are very different. If you expose your field as public, then all dependent applications will use <span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size:small;">obj.fieldName</span></span> to access it; while if you encapsulate it using a access method, it's like <span class="Apple-style-span" style="font-family:'courier new';"><span class="Apple-style-span" style="font-size:small;">obj.getField()</span></span>. So if you have make the field public, and then you need to introduce some business logic on the field, then you've got a headache: you need to change all the depending source codes. With IDEs like IDEA and Eclipse, this kind of change can be much easier and robust than before, but still it's going to take effort, which is a waste.</div><div><br /></div><div>Since the first day of C#'s birth, it has a special language feature, Property, which I believe was borrowed by the success of <a href="http://www.embarcadero.com/products/delphi">Delphi</a>. By this feature, a field can be encapsulated by a property and accessed in the same syntax as field, except under the hood, it's really a method call, and if you disassembly the IL code, there is really setField and getField methods generated. So in this case, is it still so evil to mark your field private and provide a property for it? In most of my applications (and I believe in most of most programmers' applications) the property is nothing but just a dummy get/set pair. And to make this pain less painful, MS invented the "auto-property". But the question is, is this encapsulate really necessary?</div><div><br /></div><div>I don't think so! For C# applications, the "private-field-rule" is not applicable any more. Since if you want to change a field to a property, none of the dependent codes should change (unless if you use reflection). The only thing a field can not do is, it can not be marked as virtual while properties can; and fields can not be put into interfaces while properties can be (you can make a property writeonly and not field, might be useful for setting injection by IoC). So if you need to make a NHibernate friendly entity, or if you need to define interfaces to other module, use property. For most of rest, try to use field, until you find the needs to introduce property. This will help you get code clean.</div>tcmasterhttp://www.blogger.com/profile/12229570806153597807noreply@blogger.com0