Friday, April 24, 2009

.Net 下自定义控件创建(1):User Control 与 Custom Control 的关系、区别和使用

简而言之,两者是一个继承关系。UserControl继承Control   
  System.Object  
        System.MarshalByRefObject  
              System.ComponentModel.Component  
                    System.Windows.Forms.Control  
                          System.Windows.Forms.ScrollableControl  
                                System.Windows.Forms.ContainerControl  
                                      System.Windows.Forms.UserControl 

看到这里,大家应该可以猜到,继承UserControl应该简单一下。确实如此,UserControl基本使用方法是将若干个控件的功能合成一个可重新使用的单元。封装在公共容器内的 Windows 窗体控件的集合。此容器包含与每个 Windows 窗体控件相关联的所有固有功能,允许您有选择地公开和绑定它们的属性。用户控件的例子之一可能是已生成的显示数据库中客户地址数据的控件。该控件可能包括几个用来显示字段的文本框,几个用来通过记录定位的按钮 (Button) 控件。可以有选择地公开数据绑定属性,可以将整个控件打包并在应用程序之间重复使用。

而Custom Control相对就复杂了,通过从 Control 继承来完全从头地创建一个控件Control 类提供控件(例如事件)所需的所有基本功能,但不提供控件特定的功能或图形接口。与通过从用户控件或现有 Windows 窗体控件继承来创建控件相比,通过从 Control 类继承来创建控件需要耗费的心思和精力要多得多。因为作者必须为控件的 OnPaint 事件编写代码以及所需的任何功能特定代码,但同时也允许作者根据自己的需要,灵活地自定义调整控件。时钟控件即是一个自定义控件,它复制模拟时钟的外观和操作,自定义绘图将被调用来促使时钟指针走动,以响应内部计时器组件的 Tick 事件。处于下列情况时使用Custom Control:

  • 想要提供控件的自定义图形化表示形式。
  • 需要实现无法从标准控件获得的自定义功能。

如果大家创建一个c#工程,分别添加2种Item,就会发现区别了。这个系列第一篇就先给大家一个Hello World 级别的代码吧。后面将陆续介绍.net framework下自定义控件的制作。大家复制添加一个Custom Control,粘贴下面的代码,再新建一个Form,应该就可以把控件拖到窗口里了。

using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;


namespace CustomCtrl
{
public partial class HelloWorld : Control
{
public HelloWorld()
{
InitializeComponent();
this.Size = new Size(100, 40);
this.BackColor = SystemColors.ActiveBorder;
}

private string helloValue = "Hello World!";

[
Category("Demo"),
Description("Demo from idothink.com")
]
public String CustomValue
{

get
{
return helloValue;
}
set
{
helloValue = value;

// The Invalidate method invokes the OnPaint
Invalidate();
}
}

protected override void OnPaint(PaintEventArgs pe)
{
// Calling the base class OnPaint
base.OnPaint(pe);

// Custom paint code here
pe.Graphics.DrawString(
helloValue,
Font,
new SolidBrush(ForeColor),
ClientRectangle, new StringFormat());
}
}
}

Thursday, April 23, 2009

中小企业的项目管理方案 -- IT构架篇

德明泰作为一个专业的IT外包公司,有一套完善的项目管理方案。这一套方案是笔者在多年的工作中,集合了各色公司的精华而创立,因为知识产权的原因,不能详尽到如何配置解决,但在这里给大家介绍一下我们的管理流程和使用的工具,希望给创业团体在项目管理方面一些启示吧。

在介绍项目管理之前,就不得不提到我们的IT构架。今天首先介绍的企业局域网的架设。局域网的作用在现今这个互联网时代的作用越发重要。架设好一个适合企业的局域网,必须从企业的切实需求出发,而不是盲从的道听途说,或者聘请非专业人士。德明泰是一个面向企业提供软件IT服务的高新技术企业,我们选取的解决方案完全为企业量身定制,所以对于我们自家使用的解决方案也是千挑万选。我们从以下几个方面来考虑的:

  • 对开源系统和反盗版的支持
  • 解决方案的可重用性(打包销售给类似企业)
  • 企业的规模 (多办公地点,统一的PC管理)
  • 员工的网络自由度
  • 服务器的负载
  • 文件的集成备份

基于以上几点,我们排除了使用微软成套解决方案的可能性,而是DIY一套居于SMEServer的系统。 SMEServer是基于CentOS内核的Linux,从名字可以看出,他是一个支持中小公司的服务器,而且完全免费,有效的节约了创业初期的资金。由于服务器的操作系统选定,基于此操作系统的一系列软件配套也便完全免费了。使用开源的软件,也让我们可以方便的更改一些设置,定制出最适合企业的使用流程。通过SMEServer,对外我们将服务器作为防火墙,开设了标准的Apache+tomcat服务器。对内我们将服务器作为网关,负责内部的三个局域网(wire,wifi,openvpn)的网络服务,同时开设域名管理服务,管理企业内部标配的PC机。服务器在硬件上采用了RAID0, 并配置了不间断电源,软件上我们开发了配套不间断电源的管理软件,企业级备份软件(onsite & offsite),从两个层面保证数据的完善。同时为了减轻服务器负载,我们将系统瓶颈的IO部分单独提取出来,架设了内部文件共享系统,完美支持 SSH,SCP,FTP,Samba等多协议。

至此,我们企业的IT框架就基本成型了,接下来我会讲解一些关于我们如何构架团队协同合作工具的内容。

Wednesday, April 22, 2009

海外生活点滴--斗争篇

国人有逆来顺受的习惯,笔者在海外生活了4年,渐渐习惯了凡事讲个理字,渐渐的变成了一个刁民。。今天讲几个斗争的故事吧。

前些天发现信箱里有一封定期存款通知。去柜台一问,才发现原来是定期到期,自动转存了。这个政策我一直是知道的,以前的定期如果不需要转存,我也都打电话去逐一说明了。最近事情忙,又没有收到电子版的到期通知,就没有打电话给银行,结果就是银行给我转存了一个利率最低的定期。当时要求把定期取消,答复是要交$35违约费。对方给出他们的服务条款给我看,说定期到期后6天内必须通知他们处理方式,否则自动转存。故事到这里,一般人也就放弃了,可我觉得这太不公平了,于是板下脸来,说这个太不合理了,你银行凭什么帮我做决定,如果为了我的利益,为什么又存一个这么低利息的定期?用鬼子话就是"Rip me off"。 柜台的员工是经过培训的,我不开心发发火,她也是笑眯眯说帮我投诉。打了2个电话未果,我变动用了孙子兵法最后一招,走为上策。 威胁了一下他们,就起了作用了。下一个电话里面,她就提及如果不妥善解决,这个客户就要走了,把存款贷款通通挪到隔壁的银行。那边着急了,一下午就办好了,并致电给我询问解决的是否满意。

这里还不得不提一下印象最深刻,和澳洲移民局的斗争了。由于金融危机,移民政策修改很快,导致有一些情况没有考虑全,本人比较倒霉,落入了一个尴尬地步,被迫就一些不合理政策投诉到底。详情我的另外一篇文章,办理技术移民澳大利亚的坎坷

这里让我想起了一个经典的句子。customer 斗争吧!

My 100th Post

I have waited serveral days to write this post, so that I can find a good topic and celebrate this 100th post. Ok, Here is what I found: “Why you are stilling waiting for Kevin Rudd Money”

 

Now the ATO has been saying since day one that the payments will take a while to get through to everyone - they’re telling people to not even bother calling to ask until mid-May because they’ve got more than 7 million people to pay. 

So here’s the answer: it’s entirely random… based on your postcode.  This is from the genuinely helpful ATO tax bonus FAQ page:

All cheque and EFT payments will be made using a post code selection process that is randomly generated, ensuring all post codes are evenly distributed to each state and territory each night (using the Australia Post predetermined percentage spread). For this reason and because of security concerns, we are not planning to publish a distribution schedule.

So there you go - it’s totally random who gets it and when.  And it looks like each night the ATO supercomputer picks some numbers out of thin air and doles out some cash.  And in an effort to spread an equal number of payments to each post code each night, it could be that you get your payment but your spouse/partner/flatmate/pet misses out.

Saturday, April 18, 2009

在未来五年内开发者将需要的10技能

如果您是开发人员寻找出人头地在您的领域(或在某些情况下,简单地停留雇用) ,这不是一个好时机因此而自满。 Justin James lists the skills you’ll want to work on now to maximize your future job prospects. 詹姆斯名单上的技能您想要的工作以最大限度地提高您现在的未来的就业前景。


With the recent changes in the economy, a lot of developers are focused on their short-term job prospects.与最近发生的变化,经济,许多开发商的重点是短期的就业前景。 At the same time, it’s important to make sure that you get the most bang for your buck when it comes to taking the time and energy to learn new skills.与此同时,重要的是要确保您获得最帮您降压时,采取的时间和精力学习新技能。 Here is our list of 10 skills you should be learning right now to make sure that your resume is relevant for the next five years.这里是我们的名单, 10技能,你应该学习现在,以确保您的简历是有关今后五年的。 The list is hardly exhaustive, and there are huge swaths of the industry it won’t cover (mainframe developers, for example).这份名单并不是详尽的,有巨大的工业地带,将不包括(大型机开发,例如) 。 Nonetheless, for average mainstream development, you can’t go wrong learning at least seven of these skills — not only to the point where you can talk convincingly about them at a job interview, but actually use them on the job.尽管如此,平均主流发展,你不能出错学习至少7这些技能-不仅是为了这一点,您可以令人信服地谈论他们在面试,但实际上利用他们的工作。

Note: This article is also available as a PDF download . 注:本文也可下载

1: One of the “Big Three” (.NET, Java, PHP) 1 :一个“三巨头” ( 。 NET中,爪哇岛, PHP )的

Unless there is a radical shift in the development world (akin to an asteroid hitting Redmond), most developers will need to know at least one of the Big Three development systems — .NET (VB.NET or C#), Java, or PHP — for the near future.除非有一个根本性的转变发展世界(即小行星击中微软) ,大多数开发商将需要知道至少有三大发展系统-的。 NET ( VB.NET或C # ) , Java或PHP的-在不久的将来。 It’s not enough to know the core languages, either.这是不够的,知道的核心语言,无论是。 As projects encompass more and more disparate functionality, you’ll need to know the associated frameworks and libraries more deeply.作为项目包括越来越多的不同的功能,您需要知道相关的框架和图书馆更深入。

2: Rich Internet Applications (RIAs) 2 :丰富的互联网应用程序(区域一体化安排)

Love it or hate it, in the last few years, Flash is suddenly being used for more than just animations of politicians singing goofy songs.爱或恨它,在过去几年中, Flash是突然被用于不仅仅是动画的政治家唱歌愚笨歌曲。 Flash has also sprouted additional functionality in the form or Flex and AIR.闪光还长出额外的功能在表格或Flex和空气。 Flash’s competitors, such as JavaFx and Silverlight, are also upping the ante on features and performance. Flash的竞争对手,如JavaFx和Silverlight ,还加大了赌注的功能和性能。 To make things even more complicated, HTML 5 is incorporating all sorts of RIA functionality, including database connectivity, and putting the formal W3C stamp on AJAX.为了让事情变得更加复杂, HTML格式5纳入各种免疫功能,包括数据库连接,并把正式的W3C邮票上的AJAX 。 In the near future, being an RIA pro will be a key resume differentiator.在不久的将来,作为一个记者Pro将是一个关键的恢复与众不同。

3: Web development 3 : Web开发

Web development is not going away anytime soon.网络的发展是不会消失的迹象。 Many developers have been content to lay back and ignore the Web or to just stick to “the basics” their framework provides them with.许多开发商已经奠定回的内容,而忽略了网站或只是坚持“基本”的框架内为他们提供。 But companies have been demanding more and more who really know how to work with the underlying technology at a “hand code” level.但公司一直在要求更多谁真的知道如何工作的基本技术在“手码”的水平。 So bone up on JavaScript, CSS, and HTML to succeed over the next five years.因此,骨上的JavaScript ,的CSS和HTML的成功,在未来5年。

4: Web services 4 :网络服务

REST or SOAP?休息或SOAP的? JSON or XML?简称JSON或XML ? While the choices and the answers depend on the project, it’s getting increasingly difficult to be a developer (even one not writing Web applications) without consuming or creating a Web service.虽然选择的答案取决于项目,它越来越难以开发(即使是不写Web应用程序)在消费或创建一个Web服务。 Even areas that used to be ODBC, COM, or RPC domains are now being transitioned to Web services of some variety.即使地区曾经是数据库的COM ,或RPC域名现正转移到Web服务的一些品种。 Developers who can’t work with Web services will find themselves relegated to legacy and maintenance roles.开发商谁不能工作,网络服务将发现自己降级到遗产和维护的作用。

5: Soft skills 5 :软技能

One trend that has been going for quite some time is the increasing visibility of IT within and outside the enterprise.一个趋势已经持续相当长的一段时间是增加知名度的IT之内和之外的企业。 Developers are being brought into more and more non-development meetings and processes to provide feedback.开发者们正在把越来越多的非发展会议和进程提供反馈。 For example, the CFO can’t change the accounting rules without working with IT to update the systems.例如,首席财务官不能改变会计规则不使用它来更新系统。 And an operations manager can’t change a call center process without IT updating the CRM workflow.和一个业务经理不能改变一个呼叫中心的进程没有它更新的CRM流程。 Likewise, customers often need to work directly with the development teams to make sure that their needs are met.同样,客户往往需要直接与开发团队,以确保他们的需要得到满足。 Will every developer need to go to Toastmasters or study How to Win Friends and Influence People ?将每一个开发商需要去演讲或研究如何赢得朋友和影响人们 ? No. But the developers who do will be much more valuable to their employers — and highly sought after in the job market.不可以,但谁做的开发商将是更有价值的雇主-和高度寻求在就业市场。

6: One dynamic and/or functional programming language 6 :一个动态和/或功能性编程语言

Languages like Ruby, Python, F#, and Groovy still aren’t quite mainstream –  but the ideas in them are.语言,如红宝石,蟒,女# ,和Groovy仍然不太主流-但他们的想法是。 For example, the LINQ system in Microsoft’s .NET is a direct descendent of functional programming techniques.例如, LINQ系统在微软的。 NET是一个直接后裔功能编程技术。 Both Ruby and Python are becoming hot in some sectors, thanks to the Rails framework and Silverlight, respectively. Ruby和Python都成为热点在一些部门,由于铁轨框架和Silverlight分别。 Learning one of these languages won’t just improve your resume, though; it will expand your horizons.学习其中一种语言不仅会改善您的简历,但它还将拓展您的视野。 Every top-flight developer I’ve met recommends learning at least one dynamic or functional programming language to learn new ways of thinking, and from personal experience, I can tell you that it works.每个顶级开发商我找到了我建议学习至少一个动态或功能的编程语言,了解新的思维方式,从个人的经验,我可以告诉你,它的作品。

7: Agile methodologies 7 :敏捷方法

When Agile first hit mainstream awareness, I was a skeptic, along with many other folks I know.当第一次击中敏捷的主流意识,我是持怀疑态度,还有许多其他人,我知道。 It seemed to be some sort of knee-jerk reaction to tradition, throwing away the controls and standards in favor of anarchy.这似乎是某种膝跳反应传统,扔掉的控制和标准有利于无政府状态。 But as time went on, the ideas behind Agile became both better defined and better expressed.但是,随着时间的推移,后面的思想敏捷成为双方更好地界定和更好地表达。 Many shops are either adopting Agile or running proof-of-concept experiments with Agile.许多商店都采用敏捷或运行概念证明型实验敏捷。 While Agile is not the ultimate panacea for project failure, it does indeed have a place on many projects.虽然敏捷不是灵丹妙药项目最终失败,但它确实有许多项目上。 Developers with a proven track record of understanding and succeeding in Agile environments will be in increasingly high demand over the next few years.开发人员跟踪记录证明理解和敏捷的环境中成功地将在越来越高的需求在未来几年。

8: Domain knowledge 8 :专业知识

Hand-in-hand with Agile methodologies, development teams are increasingly being viewed as partners in the definition of projects.携手与敏捷方法,开发团队正越来越多地被看作是合作伙伴的定义中的项目。 This means that developers who understand the problem domain are able to contribute to the project in a highly visible, valuable way.这意味着,开发商谁了解问题域能够有助于该项目在一个高度引人注目,有价值的方式。 With Agile, a developer who can say, “From here, we can also add this functionality fairly easily, and it will get us a lot of value,” or “Gee, that requirement really doesn’t match the usage patterns our logs show” will excel.与敏捷,开发谁可以说, “从这里,我们也可以加入这一功能很容易,而且将得到我们很多的价值” ,或“哎呀,这一要求并不符合我们的使用模式的记录显示“将Excel中。 As much as many developers resist the idea of having to know anything about the problem domain at all, it is undeniable that increasing numbers of organizations prefer (if not require) developers to at least understand the basics.正如许多开发商抵制想法知道什么问题域,这是不可否认的是,越来越多的组织希望(如果不是需要)开发商至少了解的基本知识。

9: Development “hygiene” 9 :发展“卫生”

A few years ago, many (if not most) shops did not have access to bug tracking systems, version control, and other such tools; it was just the developers and their IDE of choice.几年前,许多(如果不是大多数)商店没有获得bug跟踪系统,版本控制,以及其他类似的工具,它只是开发商和他们的IDE的选择。 But thanks to the development of new, integrated stacks, like the Microsoft Visual Studio Team System, and the explosion in availability of high quality, open source environments, organizations without these tools are becoming much less common.但由于发展的新的,综合性栈,如微软的Visual Studio Team System软件,并在爆炸中获得高品质的,开放源码的环境中,企业如果没有这些工具正变得更普遍。 Developers must know more than just how to check code in and out of source control or how to use the VM system to build test environments.开发商必须知道不仅仅是如何检查代码和源代码控制的或如何使用虚拟机系统,建立测试环境。 They need to have a rigorous habit of hygiene in place to make sure that they are properly coordinating with their teams.他们需要有一个严格的卫生习惯,以确保他们得到适当的协调与自己的团队。 “Code cowboys” who store everything on a personal USB drive, don’t document which changes correspond to which task item, and so on, are unwelcome in more traditional shops and even more unwelcome in Agile environments, which rely on a tight coordination between team members to operate. “典牛仔”谁存储上的所有个人USB驱动器,文件,不改变它的任务相符的项目,等等,都是不受欢迎的较传统的商店和更不受欢迎敏捷环境,依靠严密的协调团队成员操作。

10: Mobile development 10 :移动开发

The late 1990s saw Web development rise to mainstream acceptance and then begin to marginalize traditional desktop applications in many areas.上世纪90年代末增加了Web开发的主流接受,然后开始排斥传统的桌面应用程序在许多领域。 In 2008, mobile development left the launch pad, and over the next five years, it will become increasingly important.在2008年,移动开发离开发射台,并在未来五年内,它会变得越来越重要。 There are, of course, different approaches to mobile development: Web applications designed to work on mobile devices, RIAs aimed at that market, and applications that run directly on the devices.当然,不同的方法来移动开发: Web应用程序设计,在移动设备上,区域一体化协定,以市场和应用程序,直接运行的装置。 Regardless of which of these paths you choose, adding mobile development to your skill set will ensure that you are in demand for the future.不管哪种这些路径选择,加入到您的移动发展技能将确保您在未来的需求。

Tuesday, April 14, 2009

c# IIR Filter

This is an c# implementation of the matlab function Filter, which is a digital infinite impulse response IIR filter.  The code is fairly similar to the C++ version, which I use as an reference. Using the class below is much easier than use signal processing library. The default coefficient was the taken from Matlab documentation.

 class Filter
{
private List<double> a;
private List<double> b;

//default Filter
public Filter()
{

b = new List<double>();
b.Add(0.002899695497431);
b.Add(-0.006626465760968);
b.Add(0.004033620976099);
b.Add(0.004033620976099);
b.Add(-0.006626465760968);
b.Add(0.002899695497431);

a = new List<double>();
a.Add(1.000000000000000);
a.Add(-4.229081817661462);
a.Add(7.205853343227314);
a.Add(-6.177477993982333);
a.Add(2.662714482809827);
a.Add(-0.461394312968222);

}

public Filter(List<double> a, List<double> b)
{
this.a = a;
this.b = b;
}

public void Applyfilter(List<double> x, out List<double> y)
{
int ord = a.Count -1;
int np = x.Count -1;

if (np < ord)
{
for(int k=0;k<ord-np;k++)
x.Add(0.0);
np = ord;
}

y = new List<double>();
for(int k=0;k<np+1;k++)
{
y.Add(0.0);
}
int i, j;
y[0] = b[0] * x[0];
for (i = 1; i < ord + 1; i++)
{
y[i] = 0.0;
for (j = 0; j < i + 1; j++)
y[i] = y[i] + b[j] * x[i - j];
for (j = 0; j < i; j++)
y[i] = y[i] - a[j + 1] * y[i - j - 1];
}
/* end of initial part */
for (i = ord + 1; i < np +1; i++)
{
y[i] = 0.0;
for (j = 0; j < ord + 1; j++)
y[i] = y[i] + b[j] * x[i - j];
for (j = 0; j < ord; j++)
y[i] = y[i] - a[j + 1] * y[i - j - 1];
}
}
}

Monday, April 13, 2009

网络流行词:两男两女

经济适用男:

    从物质需求上看,“经济适用男”的经济实力虽然比不上“钻石男”,但他们会将大部分收入每月按时上交给老婆,这样便于开展稳健的家庭理财计划;从感情归属上看,“经济适用男”几乎把所有的时间和精力都投入到家庭生活中,因此他们对老婆忠心不二;从性格能力上看,他们大多是单位里的骨干,做事认真,责任心强。
    “经济适用男”的其基本条件:身高1.7米左右,长相一般,皮肤略白,五官圆润,戴近视眼镜,发型传统———总之,很难让人留下深刻印象。不吸烟、不喝酒、不赌钱,恋爱经验少之又少。职业范围涉及公务员、教育类、IT行业、机械制造、技术类等,月薪在3000元至10000元之间。
    “经济适用男”的形象代言人被一致推选为“沙和尚”,其当选的理由是,“他是勤恳的好员工,也是最具潜质的好老公、好父亲,可以称之为‘潜力股”。
    具体来说,“经济适用男”有以下一些特征:
1、长相普通,性格温和。
2、工资不一定高,但收入稳定,工作相对来说比较轻松。
3、在工作中,总是兢兢业业,任劳任怨。
4、也许买不起昂贵的戒指作礼物,但有更多的时间陪伴女友逛街、看电视......
5、与女友意见分歧时,能够耐心倾听、适当让步、和平解决。
6、能带给女友一种亲切自在的生活,没有多少压力,悠闲而轻松。
7、尊重女友的人生志向及爱好追求,不会以任何家庭理由牵绊她飞得更高更远。必要时还会勇于做出牺牲,帮助爱人实现人生理想。
8、作风过硬,纪律严明,对所爱的人忠诚不二。
9、有极强的家庭责任感,能坚守“终生相伴,永远不离不弃”的誓言。
总而言之,“比我老公顾家的没我老公有钱,比我老公有钱的没我老公顾家。”这是网上对“经济适用男”的经典描述。

三低男:
源自日本,继经济适用男后新流行的概念。有一篇来自日本的文章说,从前日本女性追求“三高”男人——高学历,高收入,高个子。现在的日本女人,要的是“ 三低”的男人——低姿态、低风险、低束缚。“三低男”的流行,表示日本女性想要找“倚靠”的心理渐淡,想要找“陪伴”的心意渐浓。她们已经开始摆脱“一结婚就变成一辈子服务业”的传统宿命。
简义而言,“三低男”,是指低姿态、低风险、低束缚的男性。
低姿态:“Ladyfirst”,换句话说就是不能“大男子主义”,必须能真诚有礼地对待女性,尊重女性。
低风险:从事职业的风险低,有份正当又安定的工作,且不会随意辞职者。
低束缚:不约束女方,在生活上能各自独立,家事与育儿能共同负担,双方均可以安心从事自己的事业。“三低男”的流行与越来越多的女性独立自主、在家庭中能与男性共同承担经济负担有关。也反映了金融危机下,女性更愿追求安稳的小康生活。


简单方便女:
“简单方便女”是又称“三不女”。不做作,清爽简单,洗完脸一扎头发就能出门;不拜金,看淡金钱,能自己养活自己;不败家,奉行物美价廉的购物观,会持家过日子;不复杂,感情经历简单,不爱折腾。
具体来说,“简单方便女”有以下一些特征:
1、做事做人不张扬,不容易一下子引起别人的注意,从不给旁人威胁感,让人放松。
2、没有过多花哨的包装,无论做朋友还是**人,她不是回头率最高的那种,但肯定是平实男人最乐意选择的指向。
3、用情专一,内心善良细腻。
4、不太讲究虚的或者是浪漫的东西,不是说不喜欢,而是撇开了这些东西,她也能知道如何分清虚情和实意。
5、懂得站在对方的立场上去考虑事物,也善于和对方沟通,做事能考虑到各方面的感受。
6、善于谅解别人,所以和她在一起,一点也不会感觉到疲累和压力。
7、她有很好的内在素质,旁人常常惊讶于她不经意间流露出的修养。

清汤挂面女:
清汤挂面女:名词,原意为很朴素、不做任何粉饰和装扮的女子,仿佛用白开水煮的面条一样。而在网络环境里,清汤挂面女一般来形容不拜金、不过分追求时尚、安于平常生活的精神层次容易满足的女子。
一位经济适用男眼里的清汤挂面女:
生活不仅仅需要和谐,更需要真实!生活绝对不是天天鲍鱼燕窝,吃多了你也会反胃。经过科学研究,最养人、最适宜人的是土豆和地瓜,作为老陕的我归类于经济适用男的角色,生活每一天最离不开就是清汤挂面,俺就中意天天清汤挂面足以果腹。不用太昂贵的成本,不用太繁杂的配料,不用太久时间去煎熬,这就是俺想要的“清汤挂面女”。首先是干干净净亭亭玉立,别总是整得像方便面一样曲里拐弯,俺更想看到素面朝天而无所畏惧的精神内涵;再就是一回家就能端在手中,热热乎乎能够暖在心窝,营养适中,可别到时候对于健康不利;最后就是真材实料,绝对不会忽悠。

Saturday, April 11, 2009

SVN使用规范:Branch Tag的区别和在Subversion中的使用 (转载)

  • Trunk would be the main body of development, originating from the the start of the project until the present.

  • Branch will be a copy of code derived from a certain point in the trunk that is used for applying major changes to the code while preserving the integrity of the code in the trunk. If the major changes work according to plan, they are usually merged back into the trunk.

  • Tag will be a point in time on the trunk or a branch that you wish to preserve. The two main reasons for preservation would be that either this is a major release of the software, whether alpha, beta, RC or RTM, or this is the most stable point of the software before major revisions on the trunk were applied.

In open source projects, major branches that are not accepted into the trunk by the project stakeholders can become the bases for forks -- e.g., totally separate projects that share a common origin with other source code.

Branching / Tagging

One of the features of version control systems is the ability to isolate changes onto a separate line of development. This line is known as a branch. Branches are often used to try out new features without disturbing the main line of development with compiler errors and bugs. As soon as the new feature is stable enough then the development branch is merged back into the main branch (trunk).

Another feature of version control systems is the ability to mark particular revisions (e.g. a release version), so you can at any time recreate a certain build or environment. This process is known as tagging.

Subversion does not have special commands for branching or tagging, but uses so-called “cheap copies” instead. Cheap copies are similar to hard links in Unix, which means that instead of making a complete copy in the repository, an internal link is created, pointing to a specific tree/revision. As a result branches and tags are very quick to create, and take up almost no extra space in the repository.

Creating a Branch or Tag

If you have imported your project with the recommended directory structure, creating a branch or tag version is very simple:

Figure 4.34. The Branch/Tag Dialog

The Branch/Tag Dialog

Select the folder in your working copy which you want to copy to a branch or tag, then select the command TortoiseSVN → Branch/Tag....

The default destination URL for the new branch will be the source URL on which your working copy is based. You will need to edit that URL to the new path for your branch/tag. So instead of

    http://svn.collab.net/repos/ProjectName/trunk


you might now use something like



    http://svn.collab.net/repos/ProjectName/tags/Release_1.10


If you can't remember the naming convention you used last time, click the button on the right to open the repository browser so you can view the existing repository structure.



Now you have to select the source of the copy. Here you have three options:


HEAD revision in the repository

The new branch is copied directly in the repository from the HEAD revision. No data needs to be transferred from your working copy, and the branch is created very quickly.




Specific revision in the repository

The new branch is copied directly in the repository but you can choose an older revision. This is useful if you forgot to make a tag when you released your project last week. If you can't remember the revision number, click the button on the right to show the revision log, and select the revision number from there. Again no data is transferred from your working copy, and the branch is created very quickly.




Working copy

The new branch is an identical copy of your local working copy. If you have updated some files to an older revision in your WC, or if you have made local changes, that is exactly what goes into the copy. Naturally this sort of complex tag may involve transferring data from your WC back to the repository if it does not exist there already.




If you want your working copy to be switched to the newly created branch automatically, use the Switch working copy to new branch/tag checkbox. But if you do that, first make sure that your working copy does not contain modifications. If it does, those changes will be merged into the branch WC when you switch.



Press OK to commit the new copy to the repository. Don't forget to supply a log message. Note that the copy is created inside the repository.



Note that unless you opted to switch your working copy to the newly created branch, creating a Branch or Tag does not affect your working copy. Even if you create the branch from your WC, those changes are committed to the new branch, not to the trunk, so your WC may still be marked as modified with respect to the trunk.



To Checkout or to Switch...




...that is (not really) the question. While a checkout downloads everything from the desired branch in the repository to your working directory, TortoiseSVN → Switch... only transfers the changed data to your working copy. Good for the network load, good for your patience. :-)



To be able to work with your freshly generated branch or tag you have several ways to handle it. You can:





  • TortoiseSVN → Checkout to make a fresh checkout in an empty folder. You can check out to any location on your local disk and you can create as many working copies from your repository as you like.





  • Switch your current working copy to the newly created copy in the repository. Again select the top level folder of your project and use TortoiseSVN → Switch... from the context menu.



    In the next dialog enter the URL of the branch you just created. Select the Head Revision radio button and click on OK. Your working copy is switched to the new branch/tag.



    Switch works just like Update in that it never discards your local changes. Any changes you have made to your working copy which have not yet been committed will be merged when you do the Switch. If you do not want this to happen then you must either commit the changes before switching, or revert your working copy to an already-committed revision (typically HEAD).





  • If you want to work on trunk and branch, but don't want the expense of a fresh checkout, you can use Windows Explorer to make a copy of your trunk checkout in another folder, then TortoiseSVN → Switch... that copy to your new branch.







Figure 4.35. The Switch Dialog



The Switch Dialog



Although Subversion itself makes no distinction between tags and branches, the way they are typically used differs a bit.





  • Tags are typically used to create a static snapshot of the project at a particular stage. As such they not normally used for development - that's what branches are for, which is the reason we recommended the /trunk /branches /tags repository structure in the first place. Working on a tag revision is not a good idea, but because your local files are not write protected there is nothing to stop you doing this by mistake. However, if you try to commit to a path in the repository which contains /tags/, TortoiseSVN will warn you.





  • It may be that you need to make further changes to a release which you have already tagged. The correct way to handle this is to create a new branch from the tag first and commit the branch. Do your Changes on this branch and then create a new tag from this new branch, e.g. Version_1.0.1.





  • If you modify a working copy created from a branch and commit, then all changes go to the new branch and not the trunk. Only the modifications are stored. The rest remains a cheap copy.



Myeclipse Hibernate Session 在查询数据库后不更新的问题解决方案

最近的一个项目, 在更改数据库之后,再次查询,发现返回值总是在变化,有时候和数据库一致,有时候却仿佛回滚到了原来的状态。 这个问题是查询的时候,使用了以前的Session缓存。 虽然在数据更改之后,Hibernate会更新缓存,但是以前的session没有在finally关掉,所以缓存存在周期超过了一个transaction; 同时,又没有设置查询不使用缓存,所以造成了这个问题。

这个问题应该非常的常见,因为使用的代码是Hibernate生成的。 修复的办法是修改Hibernate生成的代码,设置Session不使用缓存(session.setCacheable ),然后在finally里面关掉Session.close(),并且每次都把Session清空(这个是在HibernateSessionFactory里面的getSession里面,加上Session.clear())。三管齐下,不过这是专门用来解决需要每次查询都更新的情况。 具体的对缓存的管理,大家还是按照项目的需求具体设置吧。

首先,遗弃原始的getSession() 方法, 使用新版的getClearSession() 方法。

    public static Session getClearSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
session.clear();
return session;
}
然后在需要的地方调用新方法,并设置关闭缓存

    public List findRefreshAll() {
log.debug("finding all TkTimeEntry instances");
try {
String queryString = "from TkTimeEntry";
Query queryObject = getClearSession().createQuery(queryString);
queryObject.setCacheable(false);
return queryObject.list();
}
catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
最后,在transaction使用session的时候,关闭session.
    public List<TkTimeEntry> RetrieveAllTimeEntry() {
TkTimeEntryDAO dao = new TkTimeEntryDAO();
Transaction trans = null;
try {
trans = dao.getSession().beginTransaction();
List<TkTimeEntry> timeEntryList = dao.findRefreshAll();
trans.commit();
return timeEntryList;

}
catch (HibernateException e) {
if (trans != null)
trans.rollback();
log.fatal(e);
return null;
}
finally
{
dao.getSession().close();
}

}

Thursday, April 9, 2009

How long can you hold your house prices, Australia?

Saw a news earlier today Titled “New Zealand’s March House Prices Fall 9.3% From Year Earlier” What a shocking news! How long can you hold your house prices, Australia?

New Zealand house prices fell 9.3 percent in March from a year earlier as a deepening recession and rising unemployment deterred buyers.

The drop in average prices was the biggest since the series began in 2005, Quotable Value New Zealand Ltd., the Wellington- based government valuation agency, said in an e-mailed report. Prices have been declining since July.

Buyers are cautious amid forecasts New Zealand’s recession may be prolonged until 2010 and the jobless rate may surge to an 11-year high of 7.2 percent by early next year. Falling property prices add to signs consumer confidence and spending will remain weak and central bank Governor Alan Bollard will cut interest rates again this month.

“There remains widespread uncertainty over what the coming months may bring,” said Blue Hancock, a spokesman for Quotable Value. “The extent to which broader economic factors, particularly job security, will affect the property market remains unclear.”

New Zealand’s economy is in its worst recession in more than three decades and may not start growing until the first quarter of 2010, the Treasury Department said this week. Most workers say their job is less secure, according to a survey by Westpac banking Corp. and McDermott Miller Ltd.

Seven of 13 economists surveyed by Bloomberg News expect Bollard will respond to falling business confidence and a weak property market by cutting the official cash rate by a half- point to 2.5 percent on April 30. Six forecast a quarter-point reduction.

Auckland Worst-Hit

Lower interest rates may spark demand for homes. Fifty- three percent of 600 people surveyed in February by ASB Bank Ltd. said it is a good time to buy property compared with 45 percent in the previous survey in November.

“Our valuers are reporting increased buyer activity with more people attending open homes and more sales occurring,” Hancock said.

The biggest price declines are in Auckland, the nation’s biggest city, region, where they fell 10.1 percent from a year earlier. Prices are stabilizing in other areas, Hancock said. Prices in Wellington fell 8.7 percent from a year earlier, less than the 9.3 percent drop in February.

Wrap Username and Password as Authentication token in .Net Web Service

The following code block was written in C# to combine username and password together. As you can notice, strings is a sequences of characters ending in '\0' , which here I used Convert.ToChar(0) to generate.

 

        public static String WrapUsernamePassword(String username, String password)
{
String package = username;
package += Convert.ToChar(0);
package += password;
return package;
}

public static void ParseToken(String token, out String username, out String password)
{
String[] tokenParts = token.Split(new Char[] {Convert.ToChar(0)});
if(tokenParts.Length == 2)
{
username = tokenParts[0];
password = tokenParts[1];
}
else
{
username = "";
password = "";
}
}

Wednesday, April 8, 2009

How to: Throw Custom Exception in Jax-ws

There is an excellent article on Faults and exceptions in JAX-WS, however, it doesn’t say how to throw custom exception clearly. Another post mentioned the below information, which I found most useful after google search to solve the problem. Again, it is still not correct solution.

Make the exception look like a normal JAX-WS generated exception.   That
would basically mean defining a JAXB bean for the data that has all the
getter/setters and such for the data and making the exception look like:
@WebFault
public class MyException extends Exception {
     MyFaultInfo faultInfo;
     public MyException(String msg, MyFaultInfo mfi) {
            ...
     }
     public MyFaultInfo getFaultInfo() {
         return faultInfo;
     }
}
That is basically the "JAX-WS" standard way of doing it and would be portable.  
The entire schema for the exception is defined in the JAXB MyFaultInfo bean.

If you look into jax-ws defination of @WebFault, it is basically on the client side, and was automatically generated! There is no point putting them in the server code. I had to admit that the explanation was clear and I write the following code to solve this problem

public class CustomException extends Exception {

private WSStatus faultInfo = null;

public CustomException(String message, WSStatus faultInfo)
{
super(message);
this.faultInfo = faultInfo;
}
public CustomException(String message, WSStatus faultInfo, Throwable cause)
{
super(message,cause);
this.faultInfo = faultInfo;
}

public CustomException(Exception ex)
{
super(ex.getMessage(),ex.getCause());
}

public WSStatus getErrorCode()
{
if(faultInfo==null)
faultInfo = new WSStatus();
return faultInfo;
}
}


Note that the generated code on client side would be something like CustomException_Exception extends Exception, so make sure you catch/throw the right exception.

Monday, April 6, 2009

Jax-ws on Tomcat: reconnect from Hibernate to MySQL using c3p0 connection pool

You are on this page because you have seen the following error:

org.hibernate.util.JDBCExceptionReporter: The last packet successfully received from the server was 56697 seconds ago. The last packet sent successfully to the server was 56697 seconds ago, which  is longer than the server configured value of ‘wait_timeout’. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem.

I guess you have already using ?autoReconnect=true in the JDBC URL (this evidently wasn’t working) and wonder why.

I also guess that you have tried google tons of articles trying to solve this problem. Well, you have come to the right place. I spend sometime on this issue and finnally solved this problem, almost encountered every bit of chaos.

Firstly, I would like to reference few good posts:

  • http://www.databasesandlife.com/automatic-reconnect-from-hibernate-to-mysql/
    • This one throws some light, but it is a bit old, so the connection pool was old fation and the author suggest to “ create a file c3p0.properties which must be in the root of the classpath with content c3p0.testConnectionOnCheckout=true” , which is expensive and not used anymore. Read it yourself for details. 
  • c3p0 - JDBC3 Connection and Statement Pooling This is offical document so refer to this when you can’t decide what to do! 
    • Hibernate's C3P0ConnectionProvider explicitly sets 7 c3p0 configuration properties, based on your hibernate configuration, overriding any configuration you may have set in a c3p0.properties file. If you are using Hibernate's C3P0ConnectionProvider you must set the following properties in your hibernate configuration, using hibernate-specific configuration keys. All other properties must be defined as usual in a c3p0.properties file. This is confusing, and will hopefully be simplified some time in the future, but for now...
    • The following properties must be set in your hibernate configuration:
    • 未命名
    • Remember -- these, and only these, properties must be defined in your hibernate configuration, or else they will be set to hibernate-specified defaults. All other configuration properties that you wish to set should be defined in a c3p0.properties file.
    • The easiest way to set these are actually using myeclipse hibernate.cfg.xml configuration editer. Make sure you set all config related to c3p0 and add “hibernate.” before the setting. For instance, change “c3p0.min_size” to “hibernate.c3p0.min_size”. See above table as well. If you are not using myeclipse, just edit the xml in text editor.

With the above information, You are almost there, except you need the jar files in the classpath. Otherwise, you will get exception java.lang.NoClassDefFoundError for HibernateSessionFactory. In myeclipse, jar is not included as default hibernate support, so you need to add advanced support.

This problem annoying me for almost two weeks, and everytime I check my log4j and tomcat log, I saw this warning. Not sure if it really is a serious problem, but using connection pool definately enhance Hibernate performace.

Friday, April 3, 2009

Ebook: Building Websites with Joomla 1.5

The best-selling Joomla! tutorial!!!

Free PDF download at Here  (Support the author and buy one at amazon ^_^ if can afford)

Editorial Reviews

Product Description
This book takes a practical step-by-step approach of teaching the installation and configuration of Joomla! 1.5, customizing it, creating your templates and extensions, and finally, building your own website. This book is suitable for web developers, designers, webmasters, content editors, and marketing professionals who want to develop a website in a simple and straightforward process. It does not require any detailed knowledge of programming or web development, and any IT-confident individual will be able to use the book to produce an impressive website.
About the Author
Hagen Graf was born in July 1964. Born and raised in Lower Saxony, Germany, his first contact with a computer was in the late seventies with a Radioshack TRS 80. As a salesperson, he organized his customers' data by programming suitable applications. This gave him a big advantage over other salesmen. With the intention of honing his skills, he joined evening courses in programming and became a programmer. Nowadays he works in his wife's consulting company as a trainer, consultant, and programmer (http://www.cocoate.com). Hagen Graf has published other books in German, about the Apache web server, about security problems in Windows XP, about Mambo, and about Drupal. Since 2001, he has been engaged in a nonprofit e-learning community called "machm-it.org e.V.", as well as in several national and international projects. All the projects are related to content management, community building, and harnessing the power of social software like wikis and weblogs. He chose Joomla! CMS because of its simplicity and easy-to-use administration. You can access and comment on his blog (http://www.bloghouse.org/en/hagen).


Product Details

  • Paperback: 384 pages
  • Publisher: Packt Publishing (March 28, 2008)
  • Language: English
  • ISBN-10: 184719530X
  • ISBN-13: 978-1847195302
  • Product Dimensions: 9.2 x 7.6 x 0.9 inches
  • Shipping Weight: 1.2 pounds (View shipping rates and policies)
  • Average Customer Review:
  • Amazon.com Sales Rank: #64,588 in Books (See Bestsellers in Books)
  • (Publishers and authors: Improve Your Sales)