經常看一些的程序
一
同沒有受Source Safe代碼管理的工程相比
SccProjectName =
SccLocalPath =
SccAuxPath =
SccProvider =
GlobalSection(SourceCodeControl) = preSolution
SccNumberOfProjects =
SccLocalPath
……
SccLocalPath
CanCheckoutShared = false
EndGlobalSection
二
既然文件增多了
功能
using System;
using System
using System
using System
namespace ZZ
{
/// <summary>
/// 操作信息事件代理
/// </summary>
public delegate void OperateNotifyHandler(object sender
/// <summary>
/// VssConverter 處理解決方案或項目的SourceSafe關聯
/// </summary>
public class VssConverter
{
//操作根目錄
private string operatePath;
/// <summary>
/// 操作信息事件
/// </summary>
public event OperateNotifyHandler OperateNotify;
/// <summary>
/// 線程結束通知事件
/// </summary>
public event EventHandler ThreadCompleted;
/// <summary>
/// 構造函數
/// </summary>
/// <param name=
public VssConverter(string operatePath)
{
this
}
OperatePath屬性
/// <summary>
/// 設置解決方案工程路徑
/// </summary>
public string OperatePath
{
get{return this
set{this
}
下面是一個public 修飾符的函數
/// <summary>
/// 去除Source Safe代碼管理
/// </summary>
public void RemoveVss()
{
Thread deleteThread = new Thread(new ThreadStart(DeleteVssFile));
Thread RemoveVssIdentifyThread = new Thread(new ThreadStart(RemoveVssIdentify));
deleteThread
RemoveVssIdentifyThread
}
後來測試了一下deleteThread的完成要比RemoveVssIdentifyThread快一些
這裡使用了遞歸來刪除相關文件
/// <summary>
/// 線程委托函數
/// </summary>
private void DeleteVssFile()
{
DeleteVssFile(this
//通知刪除文件結束
OnThreadCompleted(this
}
/// <summary>
/// 遞歸函數
/// </summary>
/// <param name=
private void DeleteVssFile(string path)
{
DeleteFile(Directory
DeleteFile(Directory
DeleteFile(Directory
foreach(string dir in Directory
DeleteVssFile(dir);
}
/// <summary>
/// 刪除文件
/// </summary>
/// <param name=
private void DeleteFile(string [] files)
{
foreach(string file in files)
{
FileInfo fi = new FileInfo(file);
fi
File
OnOperateNotify(this
}
}
對於
/// <summary>
/// 線程委托函數
/// </summary>
private void RemoveVssIdentify()
{
RemoveVssTag(this
//通知去除標簽結束
OnThreadCompleted(this
}
/// <summary>
/// 去除
/// </summary>
/// <param name=
private void RemoveVssTag(string path)
{
RemoveTagContent(Directory
RemoveTagContent(Directory
foreach(string dir in Directory
RemoveVssTag(dir);
}
下面的函數用來分析處理文件的修改
/// <summary>
/// 去除
/// </summary>
/// <param name=
private void RemoveTagContent(string [] files)
{
foreach(string file in files)
{
string strStart; //Vss標簽文本開始內容
string strEnd; //標簽文本結束內容
int offSet;//結束標簽文本的偏移量
FileInfo fi = new FileInfo(file);
fi
if(fi
{
strStart =
strEnd =
offSet =
}
else//如果是項目文件
{
strStart =
strEnd =
offSet =
}
try
{
int start;//Vss標簽文本開始索引
int end;//Vss標簽文本結束索引
string content;//文件內容
using(FileStream fs = new FileStream(file
{
StreamReader sr = new StreamReader(fs);
content = sr
sr
start = content
}
if(start!=
{
using(FileStream fs = new FileStream(file
{
end = start+content
content = content
StreamWriter sw = new StreamWriter(fs);
sw
sw
}
OnOperateNotify(this
}
}
catch(Exception ex)
{
OnOperateNotify(this
}
}
}
當此為止
/// <summary>
/// 操作信息事件通知
/// </summary>
/// <param name=
/// <param name=
protected virtual void OnOperateNotify(object sender
{
if(OperateNotify!=null)
OperateNotify(sender
}
/// <summary>
/// 線程結束事件通知
/// </summary>
/// <param name=
/// <param name=
protected virtual void OnThreadCompleted(object sender
{
if(ThreadCompleted!=null)
ThreadCompleted(sender
}
}
相對於事件中的參數
/// <summary>
/// 消息通知事件參數類
/// </summary>
public class VssEventArgs : EventArgs
{
private string message;
/// <summary>
/// 構造函數
/// </summary>
/// <param name=
public VssEventArgs(string message)
{
ssage = message;
}
/// <summary>
/// 消息內容
/// </summary>
public string Message
{
get{return ssage;}
}
}
}//命名空間
From:http://tw.wingwit.com/Article/program/net/201311/13178.html