public IEnumerable <Commit> GetLatestLogs(long lastRevision, int limit) { IList <Commit> commits = new List <Commit>(); var projects = new ProjectService(new UnitOfWork()).GetAll(); using (SvnClient svnClient = new SvnClient()) { svnClient.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); svnClient.Authentication.ForceCredentials(Username, Password); foreach (var project in projects) { var repository = RemoteRepro(project); SvnLogHandler handler = new SvnLogHandler(project, commits); svnClient.Log( repository, new SvnLogArgs() { Range = new SvnRevisionRange(lastRevision + 1, SvnRevision.Head), Limit = limit }, handler.Handler); } } return(commits); }
public CommitDiff GetRevisionDiffs(long revision) { CommitDiff result = null; SvnChangeHandler handler = new SvnChangeHandler(); using (SvnClient svnClient = new SvnClient()) { svnClient.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); svnClient.Authentication.ForceCredentials(Username, Password); svnClient.Log( RemoteRepro, new SvnLogArgs() { Range = new SvnRevisionRange(revision, revision) }, handler.Handler); SvnTarget target = SvnTarget.FromUri(RemoteRepro); using (MemoryStream ms = new MemoryStream()) { svnClient.Diff(target, new SvnRevisionRange(revision - 1, revision), ms); ms.Position = 0; StreamReader reader = new StreamReader(ms); result = GetRevisionDiffs(revision, handler.FileChanges, reader); } } return(result); }
public override Revision GetRevision(string alias) { string url = Url.TrimEnd('/'); string tempFolder = Context.Current.MapPath(Core.Settings.rootPath + "/svnRepoTemp/"); if (System.IO.Directory.Exists(tempFolder)) { System.IO.Directory.Delete(tempFolder); } using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); client.Export(folderTarget, tempFolder); RevisionStorage rs = new RevisionStorage(); var r = rs.GetFromDirectory(alias, tempFolder + alias); rs.Save(r, alias); rs.Dispose(); return(r); } return(null); }
public TestSourceResult TestConnection(SourceControlVersion sourceControlVersion) { NetworkCredential credentials = new NetworkCredential( sourceControlVersion.SourceControl.GetStringProperty("Login"), sourceControlVersion.SourceControl.GetStringProperty("Password")); using (SvnClient client = new SvnClient()) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.DefaultCredentials = credentials; try { SvnInfoEventArgs info; client.GetInfo(new Uri(this.GetVersionURI(sourceControlVersion)), out info); } catch (SvnException e) { return(new TestSourceResult() { IsSuccess = false, ErrorMessage = e.Message }); } return(new TestSourceResult() { IsSuccess = true, }); } }
public override string[] GetAvailableRevisions() { string url = Url.TrimEnd('/'); using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); List <String> filesFound = new List <String>(); Collection <SvnListEventArgs> listResults; if (client.GetList(folderTarget, out listResults)) { foreach (SvnListEventArgs item in listResults) { if (item.Entry.NodeKind == SvnNodeKind.Directory && !string.IsNullOrEmpty(item.Name)) { filesFound.Add(item.Name); } } return(filesFound.ToArray()); } } return(new string[0]); }
public LoadSourcesResult LoadSources(SourceControlVersion sourceControlVersion, string path) { NetworkCredential credentials = new NetworkCredential( sourceControlVersion.SourceControl.GetStringProperty("Login"), sourceControlVersion.SourceControl.GetStringProperty("Password")); try { using (SvnClient client = new SvnClient()) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.DefaultCredentials = credentials; if (!Directory.Exists(path)) { return(this.LoadSourcesFromScratch(sourceControlVersion, path, client)); } return(this.LoadSourcesWithUpdate(sourceControlVersion, path, client)); } } catch (SvnException e) { throw new AspNetDeployException("SvnClient failed to load sources", e); } }
SvnClient MakeNewSvnClient() { SvnClient client = new SvnClient(); try { // load configuration right away so exceptions during loading can be catched client.LoadConfigurationDefault(); } catch (SvnFormatException) { // workaround for exception "Can't determine the user's config path" for special users like NetworkService // -> try again loading from some specific path client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "SharpSvnApi")); } client.Authentication.UserNameHandlers += (s, e) => e.UserName = _user; client.Authentication.UserNamePasswordHandlers += (s, e) => { e.UserName = _user; e.Password = _password; }; client.Authentication.SslServerTrustHandlers += (s, e) => { e.AcceptedFailures = SharpSvn.Security.SvnCertificateTrustFailures.MaskAllFailures; }; return(client); }
public IList <string> GetCurrentVersionOfFile(long revision, string filename) { IList <string> lines = new List <string>(); using (SvnClient client = new SvnClient()) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.ForceCredentials(Username, Password); SvnTarget target = new SvnUriTarget(new Uri(RemoteReproAuthority + filename), revision); using (MemoryStream ms = new MemoryStream()) { client.Write(target, ms, new SvnWriteArgs() { Revision = new SvnRevision(revision) }); ms.Position = 0; using (StreamReader reader = new StreamReader(ms)) { string line = reader.ReadLine(); while (line != null) { lines.Add(line); line = reader.ReadLine(); } } } } return(lines); }
public override string[] GetAvailableRevisions() { string url = Url.TrimEnd('/'); using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); List<String> filesFound = new List<String>(); Collection<SvnListEventArgs> listResults; if (client.GetList(folderTarget, out listResults)) { foreach (SvnListEventArgs item in listResults) if (item.Entry.NodeKind == SvnNodeKind.Directory && !string.IsNullOrEmpty(item.Name)) filesFound.Add(item.Name); return filesFound.ToArray(); } } return new string[0]; }
private void checkout(string alias) { string projectUrl = Url.TrimEnd('/') + "/" + alias; string tempFolder = TempFolderPath(alias); bool workingCopy = false; if (Directory.Exists(Path.Combine(tempFolder, ".svn"))) { workingCopy = true; } using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); if (!workingCopy) { if (Directory.Exists(Path.Combine(TempFolderPath(string.Empty), ".svn"))) { SvnUriTarget target = new SvnUriTarget(projectUrl); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } Collection <SvnInfoEventArgs> info; bool res = client.GetInfo(target, new SvnInfoArgs { ThrowOnError = false }, out info); if (res) { client.CheckOut(target, tempFolder); } } else { SvnUriTarget target = new SvnUriTarget(Url); Collection <SvnInfoEventArgs> info; bool res = client.GetInfo(target, new SvnInfoArgs { ThrowOnError = false }, out info); if (res) { client.CheckOut(target, TempFolderPath(string.Empty)); } } } else { client.Update(tempFolder); } } }
public LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string path) { NetworkCredential credentials = new NetworkCredential( sourceControlVersion.SourceControl.GetStringProperty("Login"), sourceControlVersion.SourceControl.GetStringProperty("Password")); Revision latestRevision = sourceControlVersion.Revisions.OrderByDescending(r => r.CreatedDate).FirstOrDefault(); if (latestRevision == null) { return(new LoadSourcesInfoResult { SourcesInfos = new List <SourcesInfo>() }); } SvnRevisionRange range = new SvnRevisionRange(long.Parse(latestRevision.Name), long.Parse(latestRevision.Name)); if (latestRevision.ParentRevision != null) { range = new SvnRevisionRange(long.Parse(latestRevision.ParentRevision.Name) + 1, long.Parse(latestRevision.Name)); } try { using (SvnClient client = new SvnClient()) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.DefaultCredentials = credentials; Collection <SvnLogEventArgs> logEventArgs; client.GetLog(path, new SvnLogArgs { Range = range }, out logEventArgs); return(new LoadSourcesInfoResult { SourcesInfos = logEventArgs.Select(e => new SourcesInfo { CreatedDate = e.Time, Author = e.Author, Message = e.LogMessage }).ToList() }); } } catch (SvnException e) { throw new AspNetDeployException("SvnClient failed to load sources", e); } }
public static void CheckOut(string source, string target, string SVNUser, string SVNPassword) { using (SvnClient client = new SvnClient()) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.SslServerTrustHandlers += delegate(object sender, SvnSslServerTrustEventArgs e) { e.Cancel = false; }; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(SVNUser, SVNPassword); client.CheckOut(new SvnUriTarget(source), target); } }
public static FileInfo DownloadFileUsingSvnCheckout(Dto.SqlFile sqlFile, NetworkCredential networkCredential, string serverPath) { using (var client = new SvnClient()) { client.LoadConfiguration(serverPath); client.Authentication.DefaultCredentials = networkCredential; client.Export(new SvnUriTarget(sqlFile.URL), serverPath); } return(new FileInfo(Path.Combine(serverPath, sqlFile.Name))); }
public override void CommitRevision(Revision revision) { string localPath = PackagingManager.Instance.OutputDirectory; string url = Url.TrimEnd('/') + "/" + revision.Directory; using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); //client.Export(folderTarget, tempFolder); } }
private void SvnUpdate(bool isMandatory, string[] targetDirs) { string workingCopyPath = ConfigurationManager.AppSettings["WorkingCopy.Path"]; string svnUsername = ConfigurationManager.AppSettings["Svn.Username"]; string svnPassword = ConfigurationManager.AppSettings["Svn.Password"]; using (SvnClient client = new SvnClient()) { client.Authentication.ForceCredentials(svnUsername, svnPassword); client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "sharpsvn"), true); SvnPathTarget local = new SvnPathTarget(workingCopyPath); SvnInfoEventArgs clientInfo; client.GetInfo(local, out clientInfo); SvnLockInfo lockInfo = clientInfo.Lock; if (lockInfo != null) { client.CleanUp(workingCopyPath); lockInfo = clientInfo.Lock; if (lockInfo != null) { client.Unlock(workingCopyPath); } } SvnUpdateArgs updateArgs = new SvnUpdateArgs(); updateArgs.AllowObstructions = false; updateArgs.Depth = SvnDepth.Infinity; updateArgs.IgnoreExternals = false; updateArgs.UpdateParents = true; updateArgs.Revision = SvnRevision.Head; updateArgs.Conflict += new EventHandler <SvnConflictEventArgs>(UpdateArgs_Conflict); foreach (string targetDir in targetDirs) { string localPath = workingCopyPath + targetDir; if (isMandatory) { ClearFiles(client, localPath, targetDir, 0); } foreach (string file in Directory.GetFiles(localPath, "*.css")) { File.Delete(file); } client.Update(localPath, updateArgs); } } }
private static SvnClient InitializeSvnClient(string SVNUser, string SVNPassword) { SvnClient client = new SvnClient(); client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.SslServerTrustHandlers += delegate(object sender, SvnSslServerTrustEventArgs e) { e.Cancel = false; }; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(SVNUser, SVNPassword); return(client); }
public override void CommitRevision(Revision revision) { string localPath = PackagingManager.Instance.OutputDirectory; string url = Url.TrimEnd('/') + "/" + revision.Directory; using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); //client.Export(folderTarget, tempFolder); } }
/// <summary> /// 获取权限 /// </summary> /// <param name="client"></param> private void GetPermission(SvnClient client, string username, string password) { client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.UserNamePasswordHandlers += new EventHandler <SvnUserNamePasswordEventArgs>( delegate(object s, SvnUserNamePasswordEventArgs e) { e.UserName = username; e.Password = password; }); client.Authentication.SslServerTrustHandlers += new EventHandler <SvnSslServerTrustEventArgs>( delegate(object s, SvnSslServerTrustEventArgs e) { e.AcceptedFailures = e.Failures; e.Save = true; }); }
/// <summary> /// 是否合法svn地址 /// </summary> /// <param name="svnuri">svn路径</param> /// <returns></returns> public bool IsExistsUri(string svnuri) { if (string.IsNullOrEmpty(svnuri)) { return(false); } using (SvnClient client = new SvnClient()) { var username = ConfigHelper.GetValue("SVNUser"); var pwd = ConfigHelper.GetValue("SVNpwd"); client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); Uri targetUri = new Uri(svnuri); var target = SvnTarget.FromUri(targetUri); Collection <SvnInfoEventArgs> info; bool result = client.GetInfo(target, new SvnInfoArgs { ThrowOnError = false }, out info); return(result); } }
public IEnumerable <Commit> GetLatestLogs(long lastRevision, int limit) { SvnLogHandler handler = new SvnLogHandler(); using (SvnClient svnClient = new SvnClient()) { svnClient.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); svnClient.Authentication.ForceCredentials(Username, Password); svnClient.Log( RemoteRepro, new SvnLogArgs() { Range = new SvnRevisionRange(lastRevision + 1, SvnRevision.Head), Limit = limit }, handler.Handler); } return(handler.Logs); }
public override SvnClient CreateSvnClient() { var client = new SvnClient(); if (!string.IsNullOrEmpty(_userName) && !string.IsNullOrEmpty(_password)) { client.Authentication.ForceCredentials(_userName, _password); } client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true); client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers += (sender, e) => { e.AcceptedFailures = e.Failures; e.Save = true; }; return client; }
public void Init() { try { mClient = new SvnClient(); //Configure the client profile folder string configPath = Path.Combine(Path.GetTempPath(), "sharpsvn"); if (!Directory.Exists(configPath)) { Directory.CreateDirectory(configPath); } mClient.LoadConfiguration(configPath, true); mClient.Authentication.DefaultCredentials = new System.Net.NetworkCredential(mSourceConnectionDetails.SourceUserName, mSourceConnectionDetails.SourceUserPass); } catch (Exception ex) { mClient = null; throw ex; } }
public override Revision GetRevision(string alias) { string url = Url.TrimEnd('/'); string tempFolder = Context.Current.MapPath(Core.Settings.rootPath + "/svnRepoTemp/"); if (System.IO.Directory.Exists(tempFolder)) System.IO.Directory.Delete(tempFolder); using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); SvnTarget folderTarget = SvnTarget.FromString(url); client.Export(folderTarget, tempFolder); RevisionStorage rs = new RevisionStorage(); var r = rs.GetFromDirectory(alias, tempFolder + alias); rs.Save(r, alias); rs.Dispose(); return r; } return null; }
private void Commit(string alias, string svnFolder, string revFolder) { var reviFiles = System.IO.Directory.GetFiles(revFolder, "*.*", System.IO.SearchOption.AllDirectories); var svnFiles = System.IO.Directory.GetFiles(svnFolder, "*.*", System.IO.SearchOption.AllDirectories); Dictionary <string, string> reviFileIndex = new Dictionary <string, string>(); Dictionary <string, string> svnFileIndex = new Dictionary <string, string>(); string url = Url.TrimEnd('/') + "/" + alias; string tempFolder = TempFolderPath(alias); bool workingCopy = false; if (Directory.Exists(Path.Combine(tempFolder, ".svn"))) { workingCopy = true; } else if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } foreach (string s in reviFiles) { DirectoryInfo parent = Directory.GetParent(s); if (!parent.Name.StartsWith(".")) { reviFileIndex.Add(s.Substring(revFolder.Length).Trim('\\'), s); } } foreach (string s in svnFiles) { if (!s.ToLower().Contains(".svn")) { svnFileIndex.Add(s.Substring(svnFolder.Length).Trim('\\'), s); } } using (SvnClient client = new SvnClient()) { client.LoadConfiguration("path"); client.Authentication.DefaultCredentials = new NetworkCredential(Login, Password); if (!workingCopy) { client.Add(tempFolder); } SvnUriTarget target = new SvnUriTarget(url); //remove not needed files foreach (var key in svnFileIndex.Keys) { if (!reviFileIndex.ContainsKey(key)) { client.Delete(svnFileIndex[key]); } } //add missing files foreach (var file in reviFileIndex) { string newPath = Path.Combine(svnFolder, file.Key); bool add = false; if (!File.Exists(newPath)) { add = true; ensureDirectory(Directory.GetParent(newPath).FullName, false); } System.IO.File.Copy(file.Value, Path.Combine(svnFolder, file.Key), true); } SvnAddArgs saa = new SvnAddArgs(); saa.Force = true; saa.Depth = SvnDepth.Infinity; foreach (var dir in Directory.GetDirectories(svnFolder)) { if (!dir.Contains(".svn")) { client.Add(dir, saa); } } SvnCommitArgs args = new SvnCommitArgs(); args.LogMessage = "Comitted from Courier 2"; args.ThrowOnError = true; args.ThrowOnCancel = true; client.Commit(tempFolder, args); } }