public bool Update(int i) { bool ok = false; try { var sua = new SvnUpdateArgs { Revision = new SvnRevision(i) }; events(); ok = SC.CleanUp(GetAppLoc()); ok = SC.Update(GetAppLoc(), sua); } catch(Exception ex) { ShowInfo("更新时遇到问题:" + ex.Message + "\r\n"); WriteError(ex); } ShowInfo("更新完成...."); return ok; }
public void TestNotify() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; int n = 0;; SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { Assert.That(e.FullPath, Is.EqualTo(WcPath)); switch (n++) { case 0: Assert.That(e.Action, Is.EqualTo(SvnNotifyAction.UpdateStarted)); break; case 1: Assert.That(e.Action, Is.EqualTo(SvnNotifyAction.UpdateCompleted)); break; } }; Client.Update(WcPath, ua); Assert.That(n, Is.EqualTo(2)); n = 0; Client.Update(new string[] { WcPath }, ua); Assert.That(n, Is.EqualTo(2)); }
/// <summary> /// Update a file to a revision /// </summary> /// <param name="filePath"></param> /// <param name="revision"></param> /// <returns></returns> public bool UpdateToRevision(string filePath, long revision) { var svnUpdateArgs = new SvnUpdateArgs(); var svnRevision = new SvnRevision(revision); svnUpdateArgs.Revision = svnRevision; return(_svnClient.Update(filePath, svnUpdateArgs)); }
public override void Update(FilePath path, bool recurse, IProgressMonitor monitor) { var args = new SvnUpdateArgs(); BindMonitor(monitor); args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children; client.Update(path, args); }
public void TestDirObstruction() { SvnSandBox sbox = new SvnSandBox(this); string dir = sbox.GetTempDir(); string sd = Path.Combine(dir, "NewDir"); SvnUpdateResult ur; Client.CheckOut(sbox.CreateRepository(SandBoxRepository.Empty), dir, out ur); Client.CreateDirectory(sd); Client.Commit(dir); SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = ur.Revision; Client.Update(dir, ua); Directory.CreateDirectory(sd); ua = new SvnUpdateArgs(); bool gotIt = false; bool gotConflict = false; ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { if (e.Action == SvnNotifyAction.ConflictResolverStarting || e.Action == SvnNotifyAction.ConflictResolverDone) { return; } if (e.FullPath != sd) { return; } gotIt = true; Assert.That(e.Action, Is.EqualTo(SvnNotifyAction.TreeConflict)); Assert.That(e.NodeKind, Is.EqualTo(SvnNodeKind.Directory)); }; ua.ThrowOnError = false; ua.AddExpectedError(SvnErrorCode.SVN_ERR_WC_OBSTRUCTED_UPDATE); ua.Conflict += delegate(object sender, SvnConflictEventArgs e) { gotConflict = true; }; Assert.That(Client.Update(dir, ua), "Update failed"); Assert.That(gotIt, "Got obstruction notification"); Assert.That(gotConflict, "Got conflict event"); Client.Status(sd, delegate(object sender, SvnStatusEventArgs sa) { Assert.That(sa.Conflicted, Is.True, "Has tree conflict"); Assert.That(sa.LocalNodeStatus, Is.EqualTo(SvnStatus.Deleted)); Assert.That(sa.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); }); }
private static void PerformUpdate(CommandEventArgs e, ProgressWorkerArgs wa, SvnRevision rev, bool allowUnversionedObstructions, bool updateExternals, bool setDepthInfinity, IEnumerable <UpdateGroup> groups, out SvnUpdateResult updateResult) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = rev; ua.AllowObstructions = allowUnversionedObstructions; ua.IgnoreExternals = !updateExternals; ua.KeepDepth = setDepthInfinity; updateResult = null; HybridCollection <string> handledExternals = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object ss, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.UpdateExternal) { if (!handledExternals.Contains(ee.FullPath)) { handledExternals.Add(ee.FullPath); } } }; e.Context.GetService <IConflictHandler>().RegisterConflictHandler(ua, wa.Synchronizer); foreach (UpdateGroup group in groups) { if (handledExternals.Contains(group.WorkingCopyRoot)) { continue; } group.Nodes.Sort(StringComparer.OrdinalIgnoreCase); // Currently Subversion runs update per item passed and in // Subversion 1.6 passing each item separately is actually // a tiny bit faster than passing them all at once. // (sleep_for_timestamp fails its fast route) foreach (string path in group.Nodes) { if (handledExternals.Contains(path)) { continue; } SvnUpdateResult result; wa.Client.Update(path, ua, out result); if (updateResult == null) { updateResult = result; // Return the primary update as version for output } } } }
// // 编写测试时,可以使用以下附加特性: // // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码 // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码 // [ClassCleanup()] // public static void MyClassCleanup() { } // // 在运行每个测试之前,使用 TestInitialize 来运行代码 // [TestInitialize()] // public void MyTestInitialize() { } // // 在每个测试运行完之后,使用 TestCleanup 来运行代码 // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void TestMethod1() { //http://docs.sharpsvn.net/current/ using (SvnClient client = new SvnClient()) { // Checkout the code to the specified directory client.Authentication.Clear(); // Clear a previous authentication client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("", ""); // client.CheckOut(new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT/"), "d:\\sharpsvn"); Uri targetUri = new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT"); var target = SvnTarget.FromUri(targetUri); Collection <SvnInfoEventArgs> info;//System.Collections.ObjectModel bool result2 = client.GetInfo(target, new SvnInfoArgs { ThrowOnError = false }, out info); //Assert.AreEqual(result2, false); // Assert.Equals(info, ""); SvnUpdateArgs ua = new SvnUpdateArgs(); SvnLogArgs args2 = new SvnLogArgs(new SvnRevisionRange(500, new SvnRevision(SvnRevisionType.Head))); Collection <SvnLogEventArgs> logitems; ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(e.Action); Console.WriteLine(e.FullPath); }; // Update the specified working copy path to the head revision client.Update("d:\\sharpsvn", ua); SvnUpdateResult result; client.Update("d:\\sharpsvn", out result); client.GetLog(targetUri, out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; DateTime checkindate = logentry.Time; } // client.Move("c:\\sharpsvn\\from.txt", "c:\\sharpsvn\\new.txt"); // Commit the changes with the specified logmessage //SvnCommitArgs ca = new SvnCommitArgs(); // ca.LogMessage = "Moved from.txt to new.txt"; // client.Commit("c:\\sharpsvn", ca); } }
public void TestChangeListAndLog() { var svnService = new Utry.Core.Services.SvnService(); //http://docs.sharpsvn.net/current/ using (SvnClient client = new SvnClient()) { // Checkout the code to the specified directory client.Authentication.Clear(); // Clear a previous authentication client.Authentication.DefaultCredentials = new System.Net.NetworkCredential("", ""); //client.CheckOut(new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT/"), "d:\\sharpsvn"); Uri targetUri = new Uri("http://ip:9001/svn/CCMS/trunk/CCMS_V6/DOCUMENT"); var target = SvnTarget.FromUri(targetUri); Collection <SvnInfoEventArgs> info;//System.Collections.ObjectModel bool result2 = client.GetInfo(target, new SvnInfoArgs { ThrowOnError = false }, out info); SvnUpdateArgs ua = new SvnUpdateArgs(); SvnLogArgs args2 = new SvnLogArgs(new SvnRevisionRange(500, new SvnRevision(SvnRevisionType.Head))); var sua = new SvnUpdateArgs { Revision = new SvnRevision(0) }; Collection <SvnLogEventArgs> logitems; long version = 0; ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(string.Format("{0}:{1}.", svnService.GetNotifyAction(e.Action), e.FullPath)); Console.WriteLine(e.Revision); version = e.Revision; }; client.Update("d:\\sharpsvn", ua); if (version > 0) { client.GetLog(targetUri, new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; DateTime checkindate = logentry.Time; Console.WriteLine(string.Format("{0} : {1 }: {2}", author, message, checkindate)); } } } }
public bool RefreshWorkingCopy() { _Logger.Info("Starting to refresh the working copy folder"); if (!IsSvnControlled(WorkingCopyPath)) { _Logger.Info("No working copy folder or currently not under SVN control. Checking out content"); SvnCheckOutArgs checkoutArgs = new SvnCheckOutArgs(); checkoutArgs.Depth = SvnDepth.Infinity; checkoutArgs.Notify += new EventHandler <SvnNotifyEventArgs>(CheckoutNotificationHandler); try { SvnUpdateResult result; bool returncode = _SvnClient.CheckOut(SvnUriTarget.FromString(RepositoryUri), WorkingCopyPath, out result); if (returncode) { _RepositoryRevision = (int)result.Revision; _Logger.Info(String.Format("Sucessfully checked out revision {0} from {1} to {2}", _RepositoryRevision, RepositoryUri, WorkingCopyPath)); } } catch (Exception ex) { _Logger.Fatal(String.Format("Checkout from {0} to {1} failed! - {2}", RepositoryUri, WorkingCopyPath, ex)); return(false); } } else { _Logger.Info("Updating working copy folder"); SvnUpdateArgs updateArgs = new SvnUpdateArgs(); updateArgs.Depth = SvnDepth.Infinity; updateArgs.Notify += new EventHandler <SvnNotifyEventArgs>(CheckoutNotificationHandler); updateArgs.Conflict += new EventHandler <SvnConflictEventArgs>(ConflictHandler); try { SvnUpdateResult result; bool returncode = _SvnClient.Update(WorkingCopyPath, updateArgs, out result); if (!returncode || (result.Revision < 0)) { _Logger.Error(String.Format("Updating from {0} to {1} failed!", RepositoryUri, WorkingCopyPath)); return(false); } _RepositoryRevision = (int)result.Revision; _Logger.Info(String.Format("Sucessfully updated to revision {0}", _RepositoryRevision)); } catch (Exception ex) { _Logger.Fatal(String.Format("Checkout from {0} to {1} failed! - {2}", RepositoryUri, WorkingCopyPath, ex)); return(false); } } return(true); }
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 bool TryUpdate(int revision) { try { SvnUpdateResult updateResult; var args = new SvnUpdateArgs(); args.Revision = revision; CreateFolder(); var result = _SvnClient.Update(LocalPath, args, out updateResult); return(result && updateResult.HasRevision); } catch (SvnSystemException) { return(false); } }
public static string UpdateToRevision(string[] args, string revision) { Parameters parameters; if (!Parameters.TryParse(args, out parameters)) { return("False"); } using (var client = new SharpSvn.SvnClient()) { SetUpClient(parameters, client); var target = SvnTarget.FromString(parameters.Path); SvnInfoEventArgs svnInfoEventArgs; SvnUpdateResult svnUpdateResult; if (!client.GetInfo(target, out svnInfoEventArgs)) { throw new Exception("SVN info failed"); } Uri svnUrl = svnInfoEventArgs.Uri; long revisionLong = long.Parse(revision); //update to revision //DebugMessage(parameters, "Updating"); SvnUpdateArgs SvnArgs = new SvnUpdateArgs(); //// If args.Revision is not set, it defaults to fetch the HEAD revision. SvnArgs.Revision = revisionLong; if (client.Update(parameters.Path, SvnArgs, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Updated to r" + svnUpdateResult.Revision); return("true"); } throw new Exception("SVN update failed"); } return("jhgjg"); }
protected override void ExecuteSVNTask(SvnClient client) { if (Dir == null) { Dir = new DirectoryInfo(Project.BaseDirectory); } if (!Dir.Exists) { throw new BuildException(string.Format(Resources.MissingDirectory, Dir.FullName), Location); } Log(Level.Info, Resources.SVNUpdateUpdating, Dir.FullName); SvnUpdateArgs args = new SvnUpdateArgs(); args.ThrowOnError = true; args.Depth = SvnDepth.Infinity; args.Revision = SvnRevision.Head; SvnUpdateResult result; bool conflictedFiles = false; client.Conflict += delegate(object sender, SvnConflictEventArgs conflictArgs) { conflictedFiles = true; Log(Level.Warning, string.Concat(@"Conflicted: ", conflictArgs.Path)); }; client.Notify += delegate(object sender, SvnNotifyEventArgs notifyArgs) { Log(Level.Info, string.Concat(notifyArgs.Action, ": ", notifyArgs.Path)); }; client.Update(Dir.FullName, args, out result); if (conflictedFiles) { throw new BuildException(string.Format(Resources.SVNConflict, Dir.FullName)); } if (result != null) { Log(Level.Info, Resources.SVNUpdateResult, Dir.FullName, result.Revision); } }
/// <summary> /// Actual method to be executed for the implementing task /// </summary> /// <param name="client">The instance of the SVN client</param> /// <returns></returns> public override bool ExecuteCommand(SvnClient client) { SvnUpdateArgs args = new SvnUpdateArgs(); args.Depth = Recursive ? SvnDepth.Infinity : SvnDepth.Children; SvnUpdateResult updateResult; bool success = client.Update(RepositoryPath, args, out updateResult); if (updateResult.HasResultMap) { foreach (string key in updateResult.ResultMap.Keys) { SvnUpdateResult result = updateResult.ResultMap[key]; Log.LogMessage(MessageImportance.Normal, "[{0} - {1}]", key, result.Revision); } } return success; }
/// <summary> /// Обновить рабочую копию /// </summary> /// <param name="workingCopyPath">Путь к рабочей копии</param> /// <returns>Результат</returns> private bool UpdateWorkingCopy(string workingCopyPath) { Info(SvnTarget.FromString(workingCopyPath), (sender, args) => Console.WriteLine(args)); var svnUpdateArgs = new SvnUpdateArgs { IgnoreExternals = false, UpdateParents = true }; svnUpdateArgs.Notify += SvnUpdateArgsOnNotify; svnUpdateArgs.Conflict += SvnUpdateArgsOnConflict; svnUpdateArgs.SvnError += SvnUpdateArgsOnSvnError; try { return(Update(workingCopyPath, svnUpdateArgs)); } catch (ArgumentNullException argumentNullException) { Logger.LogError(argumentNullException.Message, $"Parameter {argumentNullException.ParamName} is empty."); return(false); } finally { svnUpdateArgs.Notify -= SvnUpdateArgsOnNotify; svnUpdateArgs.Conflict -= SvnUpdateArgsOnConflict; svnUpdateArgs.SvnError -= SvnUpdateArgsOnSvnError; } }
public void TestUpdateMultipleFiles() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; using (StreamWriter w = new StreamWriter(Path.Combine(WcPath, "Form.cs"))) w.Write("Moo"); using (StreamWriter w = new StreamWriter(Path.Combine(WcPath, "AssemblyInfo.cs"))) w.Write("Moo"); SvnCommitArgs ca = new SvnCommitArgs(); ca.LogMessage = ""; Client.Commit(WcPath, ca); SvnUpdateArgs a = new SvnUpdateArgs(); a.Depth = SvnDepth.Empty; SvnUpdateResult result; Assert.That(Client.Update(new string[] { Path.Combine(WcPath, "Form.cs"), Path.Combine(WcPath, "AssemblyInfo.cs") }, a, out result)); Assert.That(result.ResultMap.Count, Is.EqualTo(2)); string s; using (StreamReader r = new StreamReader(Path.Combine(WcPath, "Form.cs"))) s = r.ReadToEnd(); Assert.That(s, Is.EqualTo("Moo"), "File not updated"); using (StreamReader r = new StreamReader(Path.Combine(WcPath, "AssemblyInfo.cs"))) s = r.ReadToEnd(); Assert.That(s, Is.EqualTo("Moo"), "File not updated"); }
public void RevTests() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string dir = sbox.Wc; SvnUpdateResult result; Assert.That(Client.CheckOut(new SvnUriTarget(new Uri(CollabReposUri, "trunk")), dir, out result)); long head = result.Revision; Assert.That(Client.Update(dir, out result)); Assert.That(result.Revision, Is.EqualTo(head)); SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = head - 5; Assert.That(Client.Update(dir, ua, out result)); Assert.That(result.Revision, Is.EqualTo(head - 5)); }
public void TestUpdateExternal() { SvnSandBox sbox = new SvnSandBox(this); Uri root = sbox.CreateRepository(SandBoxRepository.Empty); Uri trunk = new Uri(root, "trunk/"); Uri alt = new Uri(root, "alt/"); Client.RemoteCreateDirectory(trunk); Client.RemoteCreateDirectory(alt); string dir = sbox.GetTempDir(); Client.CheckOut(trunk, dir); Client.SetProperty(dir, SvnPropertyNames.SvnExternals, string.Format("alt1 {0}\r\n" + "alt2 {0}\n" + "alt3 {0}", alt)); SvnUpdateArgs ua = new SvnUpdateArgs(); SortedList <string, string> paths = new SortedList <string, string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { if (e.Action != SvnNotifyAction.UpdateExternal) { return; } paths.Add(e.FullPath, e.FullPath); }; Client.Update(dir, ua); Assert.That(paths.Count, Is.EqualTo(3)); Assert.That(paths.ContainsKey(Path.Combine(dir, "alt2"))); }
public void TestObstruction() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string tmp = sbox.Wc; Client.CheckOut(new SvnUriTarget(new Uri(CollabReposUri, "trunk/"), 2), tmp); File.WriteAllText(Path.Combine(tmp, "products/medium.html"), "q"); SvnUpdateArgs ua = new SvnUpdateArgs(); bool obstructionFound = false; ua.Notify += delegate(object sender, SvnNotifyEventArgs e) { if (e.Action == SvnNotifyAction.TreeConflict) { obstructionFound = true; } }; ua.AddExpectedError(SvnErrorCode.SVN_ERR_WC_OBSTRUCTED_UPDATE); Assert.That(Client.Update(tmp, ua), "Update ok"); Assert.That(obstructionFound, "Obstruction found"); }
/// <summary> /// While the server isn't up to date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void doSvnUpdate(object sender, DoWorkEventArgs e) { client = new SvnClient(); client.Notify += onSvnNotify; client.Authentication.Clear(); client.Authentication.DefaultCredentials = null; System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory())); Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()); Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/"); if (rep == null || rep != rel) { SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory()); exploreDirectory(rel); download.Maximum = iCount; updating = true; SvnCheckOutArgs args = new SvnCheckOutArgs(); args.AllowObstructions = true; if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult)) { updated = true; } } else { downloadprogress.Text = "Building update list, please be patient..."; updating = true; SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; Collection<SvnStatusEventArgs> r; client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r); foreach (SvnStatusEventArgs i in r) { client.Revert(i.FullPath); if (i.IsRemoteUpdated) iCount++; } download.Maximum = iCount; SvnUpdateArgs args = new SvnUpdateArgs(); args.AllowObstructions = true; if (client.Update(System.IO.Directory.GetCurrentDirectory(), args)) { updated = true; } else { Application.Exit(); } } }
/// <summary> /// svn代码获取 /// </summary> /// <param name="svnuri">svn地址</param> static void SVNUpdate(string svnuri, out string logmessage, out long reversion) { logmessage = ""; reversion = 0; using (SvnClient client = new SvnClient()) { var localpath = "d:\\sharpsvn"; localpath = @"E:\project\ccms\CCMS_V7_HBYD_R"; var username = ""; var pwd = ""; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //如果项目不存在则checkout,否则进行update if (!Directory.Exists(localpath)) { client.CheckOut(new Uri(svnuri), localpath); // Console.WriteLine("svn checkout success"); } else { SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget(svnuri); SvnPathTarget local = new SvnPathTarget(localpath); SvnUpdateArgs args = new SvnUpdateArgs(); args.Depth = SvnDepth.Infinity; var svnService = new SvnService(); long version = 0; long clientVersion = -1; var msg = ""; args.Notify += delegate(object sender, SvnNotifyEventArgs e) { //if (svnService.GetNotifyAction(e.Action) == "添加") //{ // msg += "\r\n添加" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新删除") //{ // msg += "\r\n删除:" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新修改") //{ // msg += "\r\n修改" + e.FullPath; //} msg += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath; version = e.Revision; }; client.GetInfo(repos, out serverInfo); client.GetInfo(local, out clientInfo); clientVersion = clientInfo.Revision; //if (clientVersion < version)//客户端version必须小于服务端才更新 //{ client.CleanUp(localpath); SvnRevertArgs args2 = new SvnRevertArgs() { Depth = SvnDepth.Infinity }; client.Revert(localpath, args2); client.Update(localpath, args); //获取消息 Collection <SvnLogEventArgs> logitems; //if (version > 0 && clientVersion < version) if (msg.Length > 5) { reversion = version; logmessage += "\r\n变更文件:" + msg; client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems); // client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; //DateTime checkindate = logentry.Time; logmessage += "\r\n"; logmessage += string.Format("提交人:{0} ,日志: {1}", author, message) + "\r\n"; } } //} // Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision)); //Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision)); // Console.WriteLine("代码获取成功"); } }// }
public override void Update (FilePath path, bool recurse, IProgressMonitor monitor) { SvnUpdateArgs args = new SvnUpdateArgs (); BindMonitor (args, monitor); args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children; client.Update (path, args); }
public override void Update (FilePath path, bool recurse, IProgressMonitor monitor) { var args = new SvnUpdateArgs { Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children, }; BindMonitor (monitor); lock (client) client.Update (path, args); }
/// <summary> /// While the server isn't up to date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void doSvnUpdate(object sender, DoWorkEventArgs e) { client = new SvnClient(); client.Notify += onSvnNotify; client.Authentication.Clear(); client.Authentication.DefaultCredentials = null; System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory())); Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()); Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/"); if (rep == null || rep != rel) { SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory()); exploreDirectory(rel); download.Maximum = iCount; updating = true; SvnCheckOutArgs args = new SvnCheckOutArgs(); args.AllowObstructions = true; if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult)) { updated = true; } } else { downloadprogress.Text = "Building update list, please be patient..."; updating = true; SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; Collection <SvnStatusEventArgs> r; client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r); foreach (SvnStatusEventArgs i in r) { client.Revert(i.FullPath); if (i.IsRemoteUpdated) { iCount++; } } download.Maximum = iCount; SvnUpdateArgs args = new SvnUpdateArgs(); args.AllowObstructions = true; if (client.Update(System.IO.Directory.GetCurrentDirectory(), args)) { updated = true; } else { Application.Exit(); } } }
private static void PerformUpdate(CommandEventArgs e, ProgressWorkerArgs wa, SvnRevision rev, bool allowUnversionedObstructions, bool updateExternals, bool setDepthInfinity, IEnumerable<List<string>> groups, out SvnUpdateResult updateResult) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Revision = rev; ua.AllowObstructions = allowUnversionedObstructions; ua.IgnoreExternals = !updateExternals; ua.KeepDepth = setDepthInfinity; updateResult = null; HybridCollection<string> handledExternals = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); ua.Notify += delegate(object ss, SvnNotifyEventArgs ee) { if (ee.Action == SvnNotifyAction.UpdateExternal) { if (!handledExternals.Contains(ee.FullPath)) handledExternals.Add(ee.FullPath); } }; e.Context.GetService<IConflictHandler>().RegisterConflictHandler(ua, wa.Synchronizer); foreach (List<string> group in groups) { // Currently Subversion runs update per item passed and in // Subversion 1.6 passing each item separately is actually // a tiny bit faster than passing them all at once. // (sleep_for_timestamp fails its fast route) foreach (string path in group) { if (handledExternals.Contains(path)) continue; SvnUpdateResult result; wa.Client.Update(path, ua, out result); if (updateResult == null) updateResult = result; // Return the primary update as version for output } } }
public override string Update(IPackageTree packageTree, FileSystemInfo destination) { SvnUpdateResult result = null; using (var client = new SvnClient()) { try { var svnOptions = new SvnUpdateArgs(); if (UseRevision.HasValue) svnOptions.Revision = new SvnRevision(UseRevision.Value); client.Update(destination.FullName, svnOptions, out result); } catch (SvnRepositoryIOException sre) { HandleExceptions(sre); } catch (SvnObstructedUpdateException sue) { HandleExceptions(sue); } } return result.Revision.ToString(); }
public override void OnExecute(CommandEventArgs e) { SvnRevision updateTo; SvnDepth depth; List<string> files = new List<string>(); if (e.Command == AnkhCommand.UpdateItemSpecific) { IUIShell uiShell = e.GetService<IUIShell>(); PathSelectorInfo info = new PathSelectorInfo("Select Items to Update", e.Selection.GetSelectedSvnItems(true)); info.CheckedFilter += delegate(SvnItem item) { return item.IsVersioned; }; info.VisibleFilter += delegate(SvnItem item) { return item.IsVersioned; }; info.EnableRecursive = true; info.RevisionStart = SvnRevision.Head; info.Depth = SvnDepth.Infinity; PathSelectorResult result = !Shift ? uiShell.ShowPathSelector(info) : info.DefaultResult; if (!result.Succeeded) return; updateTo = result.RevisionStart; depth = result.Depth; List<SvnItem> dirs = new List<SvnItem>(); foreach (SvnItem item in result.Selection) { if (!item.IsVersioned) continue; if (item.IsDirectory) { if (result.Depth < SvnDepth.Infinity) { AnkhMessageBox mb = new AnkhMessageBox(e.Context); DialogResult dr = mb.Show(CommandStrings.CantUpdateDirectoriesNonRecursive, "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning); if (dr != DialogResult.Yes) return; depth = SvnDepth.Infinity; } } bool found = false; foreach (SvnItem dir in dirs) { if (item.IsBelowPath(dir)) { found = true; break; } } if (found) continue; files.Add(item.FullPath); if (item.IsDirectory) dirs.Add(item); } } else { updateTo = SvnRevision.Head; depth = SvnDepth.Infinity; List<SvnItem> dirs = new List<SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsVersioned) continue; bool found = false; foreach (SvnItem p in dirs) { if (item.IsBelowPath(p) && p.WorkingCopy == item.WorkingCopy) { found = true; break; } } if (found) continue; files.Add(item.FullPath); if (item.IsDirectory) dirs.Add(item); } } IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>(); tracker.SaveDocuments(e.Selection.GetSelectedFiles(true)); using (DocumentLock lck = tracker.LockDocuments(files, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { SvnUpdateResult ur; ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; e.GetService<IProgressRunner>().RunModal(CommandStrings.UpdatingTitle, pa, delegate(object sender, ProgressWorkerArgs ee) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Depth = depth; ua.Revision = updateTo; e.GetService<IConflictHandler>(). RegisterConflictHandler(ua, ee.Synchronizer); ee.Client.Update(files, ua, out ur); }); } }
/// <summary> /// svn代码获取 /// </summary> /// <param name="svnuri">svn地址</param> static void SVNUpdate(string svnuri, out string logmessage, out long reversion) { logmessage = ""; reversion = 0; long clientVersion = -1; using (SvnClient client = new SvnClient()) { try { var localpath = WorkPath + @"\" + ProjCode + @"\" + BranchName; var username = ConfigHelper.GetValue("SVNUser"); var pwd = ConfigHelper.GetValue("SVNpwd"); client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //notiny = "正在检查本地版本..."; //ShowInfo(); //SvnInfoEventArgs clientInfo; //bool okc = SC.GetInfo(local, out clientInfo); //if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令 //{ // result = (serverInfo.Revision > clientInfo.Revision); //} //如果项目不存在则checkout,否则进行update if (!Directory.Exists(localpath)) { client.CheckOut(new Uri(svnuri), localpath); Console.WriteLine("svn checkout success"); } else { SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget(svnuri); SvnPathTarget local = new SvnPathTarget(localpath); SvnUpdateArgs args = new SvnUpdateArgs(); args.Depth = SvnDepth.Infinity; var svnService = new SvnService(); long version = 0; var msg = ""; args.Notify += delegate(object sender, SvnNotifyEventArgs e) { //if (svnService.GetNotifyAction(e.Action) == "添加") //{ // msg += "\r\n添加" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新删除") //{ // msg += "\r\n删除:" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新修改") //{ // msg += "\r\n修改" + e.FullPath; //} msg += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath; version = e.Revision; Console.WriteLine(msg); }; client.GetInfo(repos, out serverInfo); client.GetInfo(local, out clientInfo); clientVersion = clientInfo.Revision; //if (clientVersion < version)//客户端version必须小于服务端才更新 //{ //client.Resolve(localpath, SvnAccept.Base);//解决冲突 ////解决冲突 //Collection<SvnStatusEventArgs> statuses; //client.GetStatus(localpath, out statuses); //foreach (var item in statuses) //{ // if (item.Conflicted) // { // client.Resolve(item.FullPath, SvnAccept.Working); // Console.WriteLine("处理冲突文件:" + item.FullPath); // logmessage += "处理冲突文件:" + item.FullPath; // } //} client.CleanUp(localpath); SvnRevertArgs revertArgs = new SvnRevertArgs() { Depth = SvnDepth.Infinity }; //撤销本地所做的修改 client.Revert(localpath, revertArgs); client.Update(localpath, args); //获取消息 Collection <SvnLogEventArgs> logitems; //if (version > 0 && clientVersion < version) logmessage += "变更文件:" + msg; if (version > 0 && clientVersion < version) { reversion = version; client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems); //client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; //DateTime checkindate = logentry.Time; logmessage += string.Format("\r\n提交人:{0} ,日志: {1}", author, message); } } //} } } catch (Exception ex) { Logger.Error(ex); logmessage = ex.ToString(); } } }
public bool Update(int i) { bool ok = false; try { var sua = new SvnUpdateArgs { Revision = new SvnRevision(i) }; events(); ok = SC.CleanUp(GetAppLoc()); ok = SC.Update(GetAppLoc(), sua); } catch (Exception ex) { ShowInfo("更新时遇到问题:" + ex.Message + "\r\n"); WriteError(ex); } ShowInfo("更新完成...."); return ok; }
public Boolean GetAmendCode() { Boolean Result = false; log.WriteFileLog("文件版本:" + Version + " SvnUri:" + Uri + " 本地路径:" + Path); uritarget = new SvnUriTarget(Uri); pathtarget = new SvnPathTarget(Path); // Get Info //log.WriteLog("取服务端信息......"); long endRevision = 0; try { client.GetInfo(uritarget, out uriinfo); endRevision = uriinfo.LastChangeRevision; // Revision代表整个版本库的当前版本,LastChangeRevision 表示这个文件最后的版本 } catch (Exception e) { log.WriteLog("取版本库信息异常: " + uritarget.Uri + " 错误信息:" + e.Message, LogLevel.Error); return false; } //log.WriteLog("取本地文件信息......"); long startRevision = 0; try { client.GetInfo(pathtarget, out pathinfo); startRevision = pathinfo.LastChangeRevision; } catch (Exception e) { log.WriteLog(",取本地版本库信息异常:" + pathtarget.FileName + " 错误信息:" + e.Message, LogLevel.Error); return false; } // 本地文件版本已经最新,不重新获取服务器版本 if (startRevision >= endRevision) { log.WriteLog(pathtarget.FileName + ",本地文件与服务器版本一致,不检查Svn服务器版本。" + "Revision = " + startRevision.ToString()); return true; } // Get Log System.Collections.ObjectModel.Collection<SvnLogEventArgs> logs; SvnLogArgs arg = new SvnLogArgs(); // 时间正序,版本历史从小到大;时间反向,版本历史从大到小 //arg.Range = new SvnRevisionRange(new SvnRevision(DateTime.Now.AddDays(-10)), new SvnRevision(DateTime.Now.AddDays(-20))); arg.Range = new SvnRevisionRange(endRevision, startRevision); //log.WriteLog("取历史......"); client.GetLog(uritarget.Uri, arg, out logs); SvnLogEventArgs l = null; foreach (SvnLogEventArgs g in logs) { // 20111215020-V6.1.4.10-V1,考虑多个修改单递交,文件的修改单号可能不是主修改单号,从修改单列表中检索 // 考虑融资融券和证券公用的修改单资源,按修改单号检查可能会有问题,按照版本直接检查 if (g.LogMessage.IndexOf(Version) >= 0) { l = g; break; } } if (l == null) { log.WriteLog("[无法确认Svn版本信息]," + pathtarget.FileName + ",endRevision = " + endRevision.ToString() + ",startRevision " + startRevision.ToString(), LogLevel.Error); return false; } else if (l.Revision == startRevision) { log.WriteLog("本地文件版本满足,不再检出。Revision = " + l.Revision.ToString()); return true; } else { log.WriteLog("[版本信息] " + pathtarget.FileName + "," + l.LogMessage.Trim() + ",时间:" + l.Time.ToString() + ",版本:" + l.Revision); } // Svn Update //log.WriteLog("更新文件......"); SvnUpdateArgs uarg = new SvnUpdateArgs(); // svn 1.7 使用 uarg.UpdateParents = true; uarg.Depth = SvnDepth.Infinity; uarg.Revision = l.Revision; Result = client.Update(pathtarget.FullPath, uarg); /* Result 更新不到也是true if (Result) { log.WriteLog("更新文件成功!"); } else { log.WriteLog("更新文件失败!"); } * */ return Result; }
public override void OnExecute(CommandEventArgs e) { SvnRevision updateTo; List <string> files = new List <string>(); if (e.Command == AnkhCommand.UpdateItemSpecific || e.Command == AnkhCommand.UpdateProjectFileSpecific) { updateTo = SvnRevision.Head; List <SvnItem> items = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (item.IsFile && item.IsVersioned) { items.Add(item); } } using (CommonFileSelectorDialog dlg = new CommonFileSelectorDialog()) { dlg.Text = CommandStrings.UpdateFilesTitle; dlg.Items = items; dlg.RevisionStart = updateTo; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } files.AddRange(SvnItem.GetPaths(dlg.GetCheckedItems())); updateTo = dlg.RevisionStart; } } else { updateTo = SvnRevision.Head; List <SvnItem> dirs = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { if (!item.IsVersioned) { continue; } bool found = false; foreach (SvnItem p in dirs) { if (item.IsBelowPath(p) && p.WorkingCopy == item.WorkingCopy) { found = true; break; } } if (found) { continue; } files.Add(item.FullPath); if (item.IsDirectory) { dirs.Add(item); } } } IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); tracker.SaveDocuments(e.Selection.GetSelectedFiles(true)); using (DocumentLock lck = tracker.LockDocuments(files, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { SvnUpdateResult ur; ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; e.GetService <IProgressRunner>().RunModal(CommandStrings.UpdatingTitle, pa, delegate(object sender, ProgressWorkerArgs ee) { SvnUpdateArgs ua = new SvnUpdateArgs(); ua.Depth = SvnDepth.Infinity; ua.Revision = updateTo; e.GetService <IConflictHandler>(). RegisterConflictHandler(ua, ee.Synchronizer); ee.Client.Update(files, ua, out ur); }); } }
public Boolean GetAmendCode() { Boolean Result = false; log.WriteFileLog("文件版本:" + Version + " SvnUri:" + Uri + " 本地路径:" + Path); uritarget = new SvnUriTarget(Uri); pathtarget = new SvnPathTarget(Path); // Get Info //log.WriteLog("取服务端信息......"); long endRevision = 0; try { client.GetInfo(uritarget, out uriinfo); endRevision = uriinfo.LastChangeRevision; // Revision代表整个版本库的当前版本,LastChangeRevision 表示这个文件最后的版本 } catch (Exception e) { log.WriteLog("取版本库信息异常: " + uritarget.Uri + " 错误信息:" + e.Message, LogLevel.Error); return(false); } //log.WriteLog("取本地文件信息......"); long startRevision = 0; try { client.GetInfo(pathtarget, out pathinfo); startRevision = pathinfo.LastChangeRevision; } catch (Exception e) { log.WriteLog(",取本地版本库信息异常:" + pathtarget.FileName + " 错误信息:" + e.Message, LogLevel.Error); return(false); } // 本地文件版本已经最新,不重新获取服务器版本 if (startRevision >= endRevision) { log.WriteLog(pathtarget.FileName + ",本地文件与服务器版本一致,不检查Svn服务器版本。" + "Revision = " + startRevision.ToString()); return(true); } // Get Log System.Collections.ObjectModel.Collection <SvnLogEventArgs> logs; SvnLogArgs arg = new SvnLogArgs(); // 时间正序,版本历史从小到大;时间反向,版本历史从大到小 //arg.Range = new SvnRevisionRange(new SvnRevision(DateTime.Now.AddDays(-10)), new SvnRevision(DateTime.Now.AddDays(-20))); arg.Range = new SvnRevisionRange(endRevision, startRevision); //log.WriteLog("取历史......"); client.GetLog(uritarget.Uri, arg, out logs); SvnLogEventArgs l = null; foreach (SvnLogEventArgs g in logs) { // 20111215020-V6.1.4.10-V1,考虑多个修改单递交,文件的修改单号可能不是主修改单号,从修改单列表中检索 // 考虑融资融券和证券公用的修改单资源,按修改单号检查可能会有问题,按照版本直接检查 if (g.LogMessage.IndexOf(Version) >= 0) { l = g; break; } } if (l == null) { log.WriteLog("[无法确认Svn版本信息]," + pathtarget.FileName + ",endRevision = " + endRevision.ToString() + ",startRevision " + startRevision.ToString(), LogLevel.Error); return(false); } else if (l.Revision == startRevision) { log.WriteLog("本地文件版本满足,不再检出。Revision = " + l.Revision.ToString()); return(true); } else { log.WriteLog("[版本信息] " + pathtarget.FileName + "," + l.LogMessage.Trim() + ",时间:" + l.Time.ToString() + ",版本:" + l.Revision); } // Svn Update //log.WriteLog("更新文件......"); SvnUpdateArgs uarg = new SvnUpdateArgs(); // svn 1.7 使用 uarg.UpdateParents = true; uarg.Depth = SvnDepth.Infinity; uarg.Revision = l.Revision; Result = client.Update(pathtarget.FullPath, uarg); /* Result 更新不到也是true * if (Result) * { * log.WriteLog("更新文件成功!"); * } * else * { * log.WriteLog("更新文件失败!"); * } * */ return(Result); }