SVN插件
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; using System.Threading; using System.Runtime.Remoting.Messaging; namespace CN100.SVNHelper { public class Operation { public delegate void ShowWaitingDialog(); public static event ShowWaitingDialog OnWaiting; public static event ShowWaitingDialog OnCompleted; public static void Update(string localUrl) { string cmd = string.Format("svn {0} {1} ", "update", localUrl); ExcuteSVNCommand(cmd); } public static void Update(string localUrl, string userName, string password) { string cmd = string.Format("svn {0} --username {2} --password {3} {1} ", "update", localUrl, userName, password); ExcuteSVNCommand(cmd); } public static void UpdateToVersion(string localUrl, long version) { string cmd = string.Format("svn {0} -r {1} {2}", "update", localUrl, version); ExcuteSVNCommand(cmd); } public static void UpdateToVersion(string localUrl, long version, string userName, string password) { string cmd = string.Format("svn {0} -r {1} --username {2} --password {3} {4}", "update", version, userName, password, localUrl); ExcuteSVNCommand(cmd); } public static void CheckOut(string serverUrl, string localUrl, string userName, string password) { string cmd = string.Format("svn {0} --ignore-externals --username {1} --password {2} {3} {4}", "co", userName, password, serverUrl, localUrl); ExcuteSVNCommand(cmd); } public static void CheckOutToVersion(string serverUrl, string localUrl, long version, string userName, string password) { string cmd = string.Format("svn {0} -r {5} --ignore-externals --username {1} --password {2} {3} {4}", "co", userName, password, serverUrl, localUrl, version); ExcuteSVNCommand(cmd); } public static void Commit(string serverUrl, string localUrl, string userName, string password) { string cmd = string.Format("svn {0} {1} --force | svn {2} --username {4} --password {5} {1} -m'{3}'", "add", localUrl, "ci", "add:" + DateTime.Now.ToString("MM/dd/yyyyHH:mm:ss"), userName, password); ExcuteSVNCommand(cmd); } public static void CleanUp(string path) { string cmd = "svn cleanup " + path; ExcuteSVNCommand(cmd); } public static void Export(string serverUrl, string localUrl) { string cmd = string.Format("svn export {0} {1}", serverUrl, localUrl); ExcuteSVNCommand(cmd); } public static void Import(string serverUrl, string localUrl) { string cmd = string.Format(" svn import -m 'New import' {0} {1}", localUrl, serverUrl); ExcuteSVNCommand(cmd); } public static void ExecuteCommad(params string[] cmd) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd.exe";//要执行的程序名称 p.StartInfo.UseShellExecute = false; //p.StartInfo.RedirectStandardInput = true;//可能接受来自调用程序的输入信息 p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息 p.StartInfo.CreateNoWindow = true;//不显示程序窗口 p.Start();//启动程序 foreach (string c in cmd) { p.StandardInput.WriteLine(c); Thread.Sleep(50); } p.StandardInput.WriteLine(@"exit"); p.WaitForExit(15 * 60 * 1000); string result = p.StandardOutput.ReadToEnd(); p.Close(); } public static void ExcuteSVNCommand(string cmd) { string exePath = Path.Combine(Environment.CurrentDirectory, "lib"); string dirCmd = string.Format(@"chdir /d {0}", exePath); cmd = dirCmd + "|" + cmd; string[] cm = cmd.Split(new char[] { '|' }); if (OnWaiting != null) { OnWaiting.BeginInvoke(Callback, null); } ExecuteCommad(cm); if (OnCompleted != null) { OnCompleted(); } } public static void Callback(IAsyncResult result) { ShowWaitingDialog handler = (ShowWaitingDialog)((AsyncResult)result).AsyncDelegate; handler.EndInvoke(result); } } }
需要在程序集下面subvesion组件,可以从网上下载一个最新版本安装好之后copy到项目下面!