用C#去除代码的SourceSafe管理(续篇)

** 用 C# ** ** 去除代码的 SourceSafe ** ** 管理(续篇) **

作者:秋枫

三、测试使用

程序测试运行界面,

界面部分代码大多数由设计器生成,下面列出了主要添加代码,

// 委托,更新文本框

private delegate void AppendTextHandler( string content);

// 标记转换操作是否完成

private int convertOK =0;

private System.Windows.Forms.TextBox textBoxFolder;// 路径文本框

private System.Windows.Forms.Button buttonFolder;// 浏览按钮

private System.Windows.Forms.TextBox textBoxInfo;// 信息显示框

private System.Windows.Forms.Button buttonOK;// 运行按钮

private System.Windows.Forms.Button buttonCancel;// 退出按钮

按钮处理函数用来打开一个路径选择框,

private void buttonFolder_Click( object sender, System.EventArgs e)

{

FolderBrowserDialog myDialog = new FolderBrowserDialog();

myDialog.ShowNewFolderButton = false ;

myDialog.Description = " 选择需要处理的解决方案或项目目录 ";

if (myDialog.ShowDialog()==DialogResult.OK)

this .textBoxFolder.Text = myDialog.SelectedPath;

myDialog.Dispose();

}

运行函数,在这里面实例化 VssConverter 类,并调用了 RemoveVss 方法,运行时把几个按钮禁了,里面注册了两个事件,起信息传递作用,不过对于直接在地址栏中输入非法路径没有做具体判断,

private void buttonOK_Click( object sender, System.EventArgs e)

{

if ( this .textBoxFolder.Text.Length>1)

{

this .textBoxInfo.Clear();

this .convertOK = 0;

this .buttonOK.Enabled = false ;

this .buttonFolder.Enabled = false ;

this .buttonCancel.Enabled = false ;

this .textBoxFolder.Enabled = false ;

VssConverter vssConverter = new VssConverter( this .textBoxFolder.Text);

vssConverter.OperateNotify += new OperateNotifyHandler(vssConverter_OperateNotify);

vssConverter.ThreadCompleted += new EventHandler(vssConverter_ThreadCompleted);

vssConverter.RemoveVss();

}

else

MessageBox.Show(" 请输入解决方案或项目路径! ");

}

下面是两个事件处理函数,第一个是用来在前台即时显示当前处理的文件信息,第二个函数是用来通知线程的执行结果。函数如下,

// 信息通知

private void vssConverter_OperateNotify( object sender, VssEventArgs e)

{

AppendTextHandler ath = new AppendTextHandler( this .textBoxInfo.AppendText);

this .textBoxInfo.BeginInvoke(ath, new object []{e.Message+Environment.NewLine});

}

// 线程结束通知

private void vssConverter_ThreadCompleted( object sender, EventArgs e)

{

if ( this .convertOK==0)

this .convertOK++;

else

{

this .buttonOK.Enabled = true ;

this .buttonFolder.Enabled = true ;

this .buttonCancel.Enabled = true ;

this .textBoxFolder.Enabled = true ;

this .textBoxInfo.AppendText("#### 转换完成 ####");

}

}

总结,程序通过搜索指定目录下的文件,根据扩展名进行相应的操作来完成处理,其中为了加快运行速度增加了线程来处理。欢迎大家交流,我的邮件地址 [email protected]. csdn 技术论坛。

Published At
Categories with Web编程
Tagged with
comments powered by Disqus