static public SVNUpdateResult Update(string dirFullPath) { var svnResult = new SVNUpdateResult(); try { using (var client = new SharpSvn.SvnClient()) { svnResult.IsSuccess = client.Update(dirFullPath); var workingCopyClient = new SharpSvn.SvnWorkingCopyClient(); SharpSvn.SvnWorkingCopyVersion version; workingCopyClient.GetVersion(dirFullPath, out version); svnResult.Revision = version.End; } CommonLib.DevLog.Write(string.Format("App서버 SVN 업데이트 성공 여부:{0}. 리비전:{1}", svnResult.IsSuccess, svnResult.Revision), CommonLib.LOG_LEVEL.INFO); } catch (Exception ex) { CommonLib.DevLog.Write(string.Format("예외 발생: {0}", ex.ToString()), CommonLib.LOG_LEVEL.ERROR); svnResult.ErrorMsg = ex.ToString(); return(svnResult); } return(svnResult); }
public SvnClient(string repository, string path, string user, string password, string email) { Url = new SharpSvn.SvnUriTarget(repository); ParentDir = path; User = user; Password = password; Email = email; Client = new SharpSvn.SvnClient(); Client.Authentication.DefaultCredentials = new NetworkCredential(User, Password); }
public Task <List <RepositoryCommit> > GetLastCommitsAsync(Project entity, AppConfiguration appConfiguration, IRepositoryAuthenticationInfo authInfo, CustomLogger runnerLogger, int count) { return(Task.Run(async() => { var info = authInfo as AuthInfo; if (info == null) { return null; } try { var checkoutResult = await ImportAsync(entity, appConfiguration, authInfo, runnerLogger); if (checkoutResult.HasErrors) { return null; } List <RepositoryCommit> result = null; using (var client = new SharpSvn.SvnClient()) { //client.Authentication.DefaultCredentials = new NetworkCredential(info.Username, info.Password); if (client.GetLog(checkoutResult.CheckOutDirectory, new SharpSvn.SvnLogArgs() { Limit = count }, out var items)) { result = items .Select(x => new RepositoryCommit(x.Revision.ToString(), x.LogMessage, x.Time.ToUniversalTime(), $"{x.Author}")) .ToList(); } } try { // Clean up the directory. Directory.Delete(checkoutResult.CheckOutDirectory, recursive: true); } catch (Exception exp) { runnerLogger.Error(exp); } return result; } catch (Exception exp) { runnerLogger.Error(exp); return null; } })); }
public Task <RepositoryImportResult> ImportAsync(Project entity, AppConfiguration appConfiguration, IRepositoryAuthenticationInfo authInfo, CustomLogger runnerLogger, string commitId = null) { return(Task.Run(() => { var folderName = $"{entity.Name}_{DateTime.UtcNow.Ticks}"; var path = Path.Combine(appConfiguration.BaseDirectory, folderName); var info = authInfo as AuthInfo; if (info == null) { return new RepositoryImportResult(string.Empty, true); } try { Directory.CreateDirectory(path); using (var client = new SharpSvn.SvnClient()) { client.Authentication.DefaultCredentials = new NetworkCredential(info.Username, info.Password); runnerLogger.Information("Checking out..."); bool result = false; if (commitId == null) { result = client.CheckOut(new SharpSvn.SvnUriTarget(entity.RepositoryUrl), path); } else { result = client.CheckOut(new SharpSvn.SvnUriTarget(entity.RepositoryUrl), path, new SharpSvn.SvnCheckOutArgs { Revision = new SharpSvn.SvnRevision(int.Parse(commitId)) }); } runnerLogger.Information($"Check out complete. Result = {result}"); } runnerLogger.Information(string.Empty); return new RepositoryImportResult(path, false); } catch (Exception exp) { runnerLogger.Error(exp); return new RepositoryImportResult(string.Empty, true); } })); }
public static SharpSvn.SvnClient Default() { SharpSvn.SvnClient client = new SharpSvn.SvnClient(); string configPath = Path.Combine(Path.GetTempPath(), "sharpsvn"); try { client.LoadConfiguration(configPath, true); } catch { if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } client.LoadConfiguration(configPath, true); } client.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override); return client; }
public string CreateRepository(string repositoryName, out string errorMessage) { errorMessage = null; if (!LoadSettings(out errorMessage)) { return null; } try { using (var client = new SharpSvn.SvnRepositoryClient()) { client.CreateRepository(settings.SVN_FilePath + repositoryName, new SharpSvn.SvnCreateRepositoryArgs() { RepositoryCompatibility = (SharpSvn.SvnRepositoryCompatibility)settings.SVN_Version }); } } catch (Exception ex) { errorMessage = ex.Message; return null; } string svnUrl = settings.SVN_Url + repositoryName; try { using (var client = new SharpSvn.SvnClient()) { client.RemoteCreateDirectory(new Uri(svnUrl + "/trunk"), new SharpSvn.SvnCreateDirectoryArgs() { LogMessage = "Creating trunk folder" }); client.RemoteCreateDirectory(new Uri(svnUrl + "/doc"), new SharpSvn.SvnCreateDirectoryArgs() { LogMessage = "Creating doc folder" }); } } catch (Exception ex) { errorMessage = ex.Message; return svnUrl; } return svnUrl + "/trunk"; }
private void GetLinkedFiles(string pathToAppDir) { SharpSvn.SvnClient client = new SharpSvn.SvnClient(); client.Authentication.Clear(); for (int i = 0; i < dgvFilesToImport.Rows.Count; i++) { //Relative || Link// string fileRelativePath = dgvFilesToImport.Rows[i].Cells["relativePath"].Value.ToString(); string fileLink = dgvFilesToImport.Rows[i].Cells["fileLink"].Value.ToString(); SharpSvn.SvnUriTarget target = new SharpSvn.SvnUriTarget(dgvFilesToImport.Rows[i].Cells["fileLink"].Value.ToString()); Directory.CreateDirectory(pathToAppDir + @"\" + dgvFilesToImport.Rows[i].Cells["relativePath"].Value.ToString()); try { SharpSvn.SvnExportArgs svnExportArgs = new SharpSvn.SvnExportArgs(); svnExportArgs.Overwrite = true; client.Export(target, pathToAppDir + @"\" + dgvFilesToImport.Rows[i].Cells["relativePath"].Value.ToString() + @"\" + Path.GetFileName(dgvFilesToImport.Rows[i].Cells["fileLink"].Value.ToString()), svnExportArgs); } catch (Exception ex) { FrontendUtils.LogError(ex.Message, ex); } } }
public void GetStatus() { pf = MAConf.instance.Configs[ap.ProductId]; System.Collections.ObjectModel.Collection<SharpSvn.SvnStatusEventArgs> ss; SharpSvn.SvnStatusArgs sarg = new SharpSvn.SvnStatusArgs(); sclient = new SharpSvn.SvnClient(); ld = new List<string>(); lver = new Dictionary<string, string>(); lpath = new Dictionary<string, Dictionary<string, bool>>(); lstatus = new Dictionary<string, Dictionary<string, SharpSvn.SvnStatus>>(); Dictionary<string, bool> tpath; // 临时变量 Dictionary<string, SharpSvn.SvnStatus> tstatus; // 临时变量 string ext; foreach (CommitCom c in ap.ComComms) { // 对于无变动和要删除的,不需要再生成SAW库信息;对于小包,不需要生成 SAW库信息 if (c.cstatus == ComStatus.NoChange || c.cstatus == ComStatus.Delete || c.ctype == ComType.Ssql) continue; if (!ld.Contains(c.sawfile.LocalPath)) { ld.Add(c.sawfile.LocalPath); lver.Add(c.sawfile.LocalPath, c.cver); } } foreach (string s in pf.CommitPublic) { if (!ld.Contains(s)) { ld.Add(System.IO.Path.Combine(pf.WorkSpace, s)); lver.Add(System.IO.Path.Combine(pf.WorkSpace, s), pf.logmessage); } } foreach (string k in ld) { try { sarg.Depth = SharpSvn.SvnDepth.Infinity; sclient.GetStatus(k, sarg, out ss); if (ss.Count > 0) { tpath = new Dictionary<string, bool>(); tstatus = new Dictionary<string, SharpSvn.SvnStatus>(); foreach (SharpSvn.SvnStatusEventArgs s in ss) { if (s.LocalContentStatus == SharpSvn.SvnStatus.NotVersioned) { ext = System.IO.Path.GetExtension(s.Path).ToLower(); if (ext == ".dcu" || ext == ".~pas" || ext == ".~dfm") log.WriteLog("[NotVersioned] " + s.Path, LogLevel.FileLog); else log.WriteLog("[NotVersioned] " + s.Path); continue; } if (s.LocalContentStatus == SharpSvn.SvnStatus.Normal) continue; tpath.Add(s.Path, true); tstatus.Add(s.Path, s.LocalContentStatus); } // 都是 Not Versioned 不需处理 if (tpath.Count > 0) { lpath.Add(k, tpath); lstatus.Add(k, tstatus); } } } catch (Exception ex) { MAConf.instance.WriteLog("获取状态失败" + ex.Message, LogLevel.Error); } } }
public void GetStatus() { pf = MAConf.instance.Configs[ap.ProductId]; System.Collections.ObjectModel.Collection <SharpSvn.SvnStatusEventArgs> ss; SharpSvn.SvnStatusArgs sarg = new SharpSvn.SvnStatusArgs(); sclient = new SharpSvn.SvnClient(); ld = new List <string>(); lver = new Dictionary <string, string>(); lpath = new Dictionary <string, Dictionary <string, bool> >(); lstatus = new Dictionary <string, Dictionary <string, SharpSvn.SvnStatus> >(); Dictionary <string, bool> tpath; // 临时变量 Dictionary <string, SharpSvn.SvnStatus> tstatus; // 临时变量 string ext; foreach (CommitCom c in ap.ComComms) { // 对于无变动和要删除的,不需要再生成SAW库信息;对于小包,不需要生成 SAW库信息 if (c.cstatus == ComStatus.NoChange || c.cstatus == ComStatus.Delete || c.ctype == ComType.Ssql) { continue; } if (!ld.Contains(c.sawfile.LocalPath)) { ld.Add(c.sawfile.LocalPath); lver.Add(c.sawfile.LocalPath, c.cver); } } foreach (string s in pf.CommitPublic) { if (!ld.Contains(s)) { ld.Add(System.IO.Path.Combine(pf.WorkSpace, s)); lver.Add(System.IO.Path.Combine(pf.WorkSpace, s), pf.logmessage); } } foreach (string k in ld) { try { sarg.Depth = SharpSvn.SvnDepth.Infinity; sclient.GetStatus(k, sarg, out ss); if (ss.Count > 0) { tpath = new Dictionary <string, bool>(); tstatus = new Dictionary <string, SharpSvn.SvnStatus>(); foreach (SharpSvn.SvnStatusEventArgs s in ss) { if (s.LocalContentStatus == SharpSvn.SvnStatus.NotVersioned) { ext = System.IO.Path.GetExtension(s.Path).ToLower(); if (ext == ".dcu" || ext == ".~pas" || ext == ".~dfm") { log.WriteLog("[NotVersioned] " + s.Path, LogLevel.FileLog); } else { log.WriteLog("[NotVersioned] " + s.Path); } continue; } if (s.LocalContentStatus == SharpSvn.SvnStatus.Normal) { continue; } tpath.Add(s.Path, true); tstatus.Add(s.Path, s.LocalContentStatus); } // 都是 Not Versioned 不需处理 if (tpath.Count > 0) { lpath.Add(k, tpath); lstatus.Add(k, tstatus); } } } catch (Exception ex) { MAConf.instance.WriteLog("获取状态失败" + ex.Message, LogLevel.Error); } } }
private void InitSvnClient() { Svn = new SharpSvn.SvnClient(); //Svn.Authentication.UserNameHandlers += Authentication_UserNameHandlers; //Svn.Authentication.UserNamePasswordHandlers += Authentication_UserNamePasswordHandlers; }