您的位置:首页 > 其它

XcodeFactory 功能再度增强!

2005-07-09 16:58 405 查看
今天周末,加班做一个监控系统,涉及到了需要配置的部分,比如,需要配置TCP端口、完成端口的工作者线程个数、是否开启加密等配置信息。在XcodeFactory1.1以前的版本中有自动生成XML配置文件和对应的解析类的功能,很好。但是,我还是要自己写个UI界面来显示和修改XML配置文件中的内容,这就很乏味了,把几个控件在窗体上拖来拖去,排放整齐,加个“确定”按钮和“取消”按钮,然后写处理函数,真是无聊。
这种事情应该交给工具来自动生成,于是我决定让XCodeFactory来为我自动生成这个配置窗体。我首先定义了配置窗体的基础接口,看起来像这个样子。
public interface IConfigForm
{
void Initialize(string configPath) ; //初始化xml配置文件解析类
void SaveConfig() ; //将配置内容写入配置文件
void DisplayConfig() ; //将配置文件的内容显示到UI
}
XCodeFactory所要做的就是根据配置的具体内容生成IConfigForm的实现类,完全是很简单的问题。花了将近两个小时的时间,为XCodeFactory实现了这一功能,并将XCodeFactory版本更新为1.2 。
下面是XCodeFactory自动生成窗体的界面截图(没有经过任何改动哦):



生成的主要代码如下:
#region Initialize
public void Initialize(string configPath)
{
this.theConfigParser = new MonitorSystemConfigParser(configPath) ;
this.DisplayConfig() ;
}
#endregion

#region DisplayConfig
private void DisplayConfig()
{
this.textBox_Port.Text = this.theConfigParser.Port.ToString() ;
this.textBox_SmsSpan.Text = this.theConfigParser.SmsSpan.ToString() ;
this.textBox_SmsComNum.Text = this.theConfigParser.SmsComNum.ToString() ;
this.textBox_SmsRate.Text = this.theConfigParser.SmsRate.ToString() ;
this.checkBox_UserValidated.Checked = this.theConfigParser.UserValidated ;
}
#endregion

#region SaveConfig
private void SaveConfig()
{
this.theConfigParser.Port = int.Parse(this.textBox_Port.Text) ;
this.theConfigParser.SmsSpan = int.Parse(this.textBox_SmsSpan.Text) ;
this.theConfigParser.SmsComNum = int.Parse(this.textBox_SmsComNum.Text) ;
this.theConfigParser.SmsRate = int.Parse(this.textBox_SmsRate.Text) ;
this.theConfigParser.UserValidated = this.checkBox_UserValidated.Checked ;
}
#endregion

#region buttonClick
private void button_save_Click(object sender, System.EventArgs e)
{
this.SaveConfig() ;
MessageBox.Show("成功修改配置!") ;
this.Close() ;
}

private void button_cancel_Click(object sender, System.EventArgs e)
{
this.Close() ;
}
#endregion
真是太方便了,我对此功能相当满意!以后的任何关于配置的问题都可以全部交给XCodeFactory来解决。
如果你想试试,可以email向我索取最新版本的XCodeFactory。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: