[Powershell] Script to install software

Today I want to check whether the Windbg is installed on the target machine with expected version, and if not, install the correct version with Powershell. It turns out that Powershell is really powerful to do such things.

$dbgApp = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" | where {$_.Caption -like '*Debugging Tools for Windows*'};
if ($dbgApp -eq $null -or !$dbgApp.Version.StartsWith("6.13"))
{
    msiexec /passive /i D:\Debug\dbg_amd64.msi;
}

Windbg + SOS complains Failed to load data access DLL, 0x80004005

When I debug one .Net 4.0 program with SOS. After .loadby sos clr then run any SOS command results in following errors:

Failed to load data access DLL, 0x80004005 Verify that
1) you have a recent build of the debugger (6.2.14 or newer)
2) the file mscordacwks.dll that matches your version of mscorwks.dll is in the version directory
3) or, if you are debugging a dump file, verify that the file mscordacwks_.dll is on your symbol path.
4) you are debugging on the same architecture as the dump file. For example, an IA64 dump file must be debugged on an IA64 machine.
You can also run the debugger command .cordll to control the debugger's load of mscordacwks.dll. .cordll -ve -u -l will do a verbose reload. If that succeeds, the SOS command should work on retry.
If you are debugging a minidump, you need to make sure that your executable path is pointing to mscorwks.dll as well.

By google, some posts were found with same error info. But most of them are focus on the debugging dump on another machine with differnt mscordacwks version. This is not the case as I’m doing living debug. From the 1) hint of the error message I check the Windbg version is 6.6 and then install the newest version 6.13.0006. It works!
~~~~~~~
The same error happened during debug a Waston dump. The solution is

0:000> .cordll -ve -u -l
CLRDLL: Unable to find mscordacwks_AMD64_AMD64_2.0.50727.5005.dll by mscorwks search
CLRDLL: Unable to find 'mscordacwks_AMD64_AMD64_2.0.50727.5005.dll' on the path
CLRDLL: Unable to find mscorwks.dll by search
CLRDLL: ERROR: Unable to load DLL mscordacwks_AMD64_AMD64_2.0.50727.5005.dll, Win32 error 0n2
CLR DLL status: ERROR: Unable to load DLL mscordacwks_AMD64_AMD64_2.0.50727.5005.dll, Win32 error 0n2

The version we are trying to find is 2.0.50727.5005, while check the attribute of file mscordacwks.dll under D:\Windows\Microsoft.NET\Framework64\v2.0.50727 it turns out its version is 2.0.50727.4454. Copying the mscordacwks.dll from the machine where the dump was generated to the root path where Windbg is installed and rename it to mscordacwks_AMD64_AMD64_2.0.50727.5005.dll. It works!

Patterns of Enterprise Application Architecture Chapter 1&2

After reading several design pattern books including “Head first design pattern” and “Java and Pattern” I turned my focus to one new book named Patterns of Enterprise Application Architecture. From the comments of amazon it seems that it’s one pretty good book. Considering the limited memory now, writing down some key ideas from the book should be able to keep the reading more interesting.
The preface section defines the scope of this book which is architecture for enterprise application. The common patterns of enterprise applications include data persistence, concurrent access, huge data process, complex UI, and integration to other enterprise application.  Here the UI involves Web and traditional rich client application. Also the authors gives some points on the measurement for performance. Finally the form of pattern is given which contains name, intention, summary,  how it works, when to use it and further reading, also some examples maybe also presented for better understanding.
The first chapter talks about layering. This topic starts from the evolution from the Client/Server model to three principal layers. One problem of the traditional C/S model is that the domain logic is hard to organized. It’s a bad idea to mix the logic in client UI directly which may easily causes duplicated code and maintain issues. Alternative way is putting them to the server side which usually presented as database store procedure. Here the store procedure is limited and may causes difficulty to switch to different database.
These short comes naturally involves idea to separate the domain logic in the object oriented world. This results in the new three principle layers including Presentation, Domain and Data source. one interesting point raised by author to think about the Presentation and Data source layer is that “Presentation is an external interface for a service your system offers to someone else, whether it be a complex human or a simple remote program. Data source is the interface to things that are providing a service to you”. Also one principle here is “The domain and data source should never be dependent on the presentation” which means we should be able to easily change our presentation layer without requiring changes in domain logic layer.
The benefits of layering contains: Easy to understand separated layer, minimize dependencies between different layers, substitute layers with alternative implementations of the same basic services. One obvious drawback of layering is that performance as we need to pass data to different layers. But compare to the benefits usually the cost is worthwhile.
The chapter 2 discusses about the way to organize domain logic.  Transaction Scripts, Domain Model, and Table Module. They all have pros and cons. The recommended way is Domain Model which is good at complexity when the problems scope increase.

Solution to Error RC1015: cannot open include file ‘afxres.h’

I have experienced problem with VS2008 Express edition to compile a program written with VS2008 Professional on another machine today. The error message is Error RC1015: cannot open include file ‘afxres.h’.
The solution is figured out after searching from Google and my analysis :). The file afxres.h is located at C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include directory, while VS2008 Express edition doesn’t have support for atlmfc library. Copy files afxres.h and winres.h from that directory on the machine with Visual Studio 2008 Professional edition  and place them under the solution root then we can make VS2008 Express edition able to compile the project!

Jeffrey Richter的讲座

周一的时候组里面几个人都去参加培训,打听一下知道是Jeffrey Richter的Advanced C# Programming的课程,听说座位比较空,于是参加了周二一天的课。可怜我的英语听力,不过去见识一下大师级的牛人也是非常不错的。从发的资料上来看,周一的重点在讲解C#中的GC机制和AppDomain的概念,看来也只有自己去啃Applied Microsoft .Net Framework Programming那本书去了。而周二上午主要是讲解C# 2.0中范型的概念和实现机制,还比较好理解。下午则是.Net 3.0中LINQ的实际机制,这个时候我可怜的英语听力,度数不够的眼镜以及昏昏欲睡的脑袋终于让我彻底迷糊了。
感觉如果只是学习一种技术倒还不算困难,而学以致用则是一个更高的台阶,通过实际的使用才能够更好地理解技术背后的思想,窥探其下一步发展的方向,如此才能主动地适应技术的变化而不是被动地去跟风。更难的是,在自己理解后,如果通过一种合适的方式传递给别人更是难上加难。对于.Net和C#,我还是仅仅处于学习的第一步,路漫漫啊。

C# UI处理耗时操作

昨天过去系统部,解决一个性能的问题。在项目中遇到一个问题,在UI程序中增加timer, 间隔为2秒,结果在其中进行了比较耗时的操作,于是UI变得慢得难以忍受。
遇到这个问题,显然是不应该在依靠Window消息机制实现的定时器中处理费时的操作,首先分析了一下该操作的耗时,平均值1.6s,最大值大概在2.4s,于是准备采用异步调用机制来解决这个问题,显然可以采用BeginInvoke或者自己创建新的Thread来处理,但在查MSDN发现BackgroundWorker更为适合来处理这种情况。
BackgroundWorker可以启动后台线程来处理费时的操作并在操作完成后调用主线程的方法,显然这个也可以通过委托的异步调用机制来实现,不过使用BackgroundWorker会简化许多工作,使用起来非常方便, 它包括三个事件:DoWork,  ProcessChanged和RunWorkerCompleted, 调用BackgroundWorker.RunWorkerAsync会触发DoWork事件,异步调用完成后会触发RunWorkerCompleted事件,BackgroundWorker.ReportProgress会触发ProcessChanged事件,这样就可以非常简单解决面对的问题。
在Form中通过工具箱增加一个BackgrondWorker,然后增加DoWork的处理函数,在其中调用费时的操作,然后在timer的处理函数中使用BackgroundWorker的RunWorkerAsync方法,不过要注意的是一个worker不能同时调用两个RunWorkerAsync方法,所以在timer中需要增加IsBusy的判断,于是问题解决。

运气好像有点差

感觉最近的运气不是很好, 先是MS9.27的miniTest没有成绩,问那边的人居然告诉我系统显示我没有参加这次笔试,在发信问有没有解决办法的时候却没有回复了.这样的结局实在让我意想不到.
然后是昨天IBM实习那边希望我去笔试面试走内部路线, 今天截至,但想不到的是昨晚知道上报的年底毕业名单中居然没有问,问了一圈到现在还没有搞定, 看来是没有办法去那边了,这个毕业的事情不搞定,说什么都是白扯.事情总是出乎我的预料.
不管怎么说, 也许该往好的地方想想,至少昨天老蒋还看了一下名单,不然估计我真的就得三年毕业了,至少还有时间处理。也许没有办法去走IBM内部路线未必是件坏事情,至少Google这边还没有结束呢。要往好的地方想。
努力,奋斗,相信自己!

Cisco面试

上个周日,在上海,周六晚上做火车过去,精神还行,大概在12点多一点到的,首先是照相。然后
总共五轮,提供了饮水和绿茶,看到自己喜爱的绿茶,感觉自信了许多。。。
第一轮,英文的,感觉自己其实对英语面试还是不够自信。首先介绍一下自己最近的项目,就拿IBM做的事情,也正好是最近的,发现真的是要靠平时的积累的。然后是智力题,5L和3L的杯子量出4L的水,时针和分针的夹角,都轻松搞定,讨论了一下Java里面的GC机制,这个问题以前被问过,还是随便提了一下,感觉回答得不是很好,但也还行,最后写了一个Fib数列的递归程序。关于问题就请教了一下他对GC理解。
第二轮,中文的,一个GG和一个MM,首先介绍自己的项目,还是说IBM的,中文说还是比较流利的,然后问了几个问题,轻松搞定,然后问了一下多态的问题。可能是感觉简单的问题对我没有啥杀伤力,就说要问了一个难度比较高的问题,就是寻找最大和子数组的问题,其实以前是见到过的,不过没有真地去看,于是告诉他我不知道,最后还是提问,问一下是否都是中国人,结果回答是否定的,自己居然没有看出来那个MM不算中国人的。出来。
第三轮,是一个看上去年纪相对比较大的人,首先英文介绍自己,做得不好,然后他就告诉我不要紧张,然后问了C++语言方面的问题,一般感觉,然后让我写一个链表排序的问题,有思路但没有写好,可能自己不写这种程序时间太长了。然后时间差不多了。
第四轮,轻松,是他们的老板,感觉不是个普通人,大概三四十岁吧,问题包括随便聊天,然后是介绍他们要做的东西,问了一下Log2(32K)等于多少,我的回答估计让她很郁闷,我直接说1K=1024=2^10,所以很简单她说我很滑头,1K=1000的,显然我得问她要多精确的,她说一般的估计把。那太简单了,1024是15,那么1000差不多是14.x,呵呵。然后问我为什么想来这个公司,期望的薪水,公司如果不录取我的三个理由,最后她给我的评价是小小年纪怎么这么贫,是不是跟北京小混混学的,真是冤枉…老板还是很Nice的.
第五轮,清华88年毕业的一个师兄,首先喊一吧师兄好,被经过的老板说这就开始套近乎了:),面试很轻松,C++的灵巧指针问题,乒乓球比赛问题,矩形相交问题,都轻松搞定,聊了聊,告诉我刚才的那个老板不是个简单的人物,说了说学校的事情,然后撤了。
唯一比较失败的是我把车票弄丢了,于是现在只能报销一张车票。不过都是一种经历,不必在意,心态要好。

IBM暑期实习生一面

6016房间,10:45的,我大概10:20没到就到了,在6013等待,无聊便和周围的人瞎扯,渴了发现没有带水,找那个喊人的要水喝,告诉我没有。偏偏我对应的房间的hr面的非常缓慢,到11:30才把我叫进去。我本来想见识一下传说中PP的hrJJ,结果是个男的,失望-_-,于是直接告诉他你的房间面的太慢了。潜台词是你快点放人哈…
把简历和证书复印件给他,估计别人都是一堆,我只复印了两张+一张简历…
1. 开始让我用中文自我介绍一下,说了三四句,说没了,hr问就这么点?然后他介绍了一下他是chinahr的.
2. 然后问投的职位,就自己最想去的职位提问,我的是SWG的IT specialist, 问为什么投这个职位,说一下对这个职位的理解我除了BBS上看了下,根本就没有理解,胡扯了一通.
3. 你对IBM的产品熟悉不? 直接告诉他IBM五大软件产品中DB2熟悉点,其他都不熟悉,直接被BS
4. 不熟悉产品如果做技术支持?我说都是可以学的
5. 你五年后有什么规划?我真想告诉他没有规划…,于是扯了一下技术路线和管理路线。
切换英文
6. What do you do in your spare time? …
7. Do you have girlfriend? 问到这里就知道他下面想问啥了
8. How do you keep balance between work and family?
估计我的英文hr已经不能忍受了,又切回中文
9. 事业和感情上的矛盾你如何处理?
10. 告诉我一周后有结果,问我有没有什么问题,问了两个不痛不痒的问题,走人。
本以为BS到这里结束,结果走的时候还丢了把人,hr的包和我的挺像的,拿着就走了,还好后来想起来,跑去换了,估计又被BS…