private MemoryStream GetSVNFileStream(SvnRevisionId changeset, string path) { var memoryStream = new MemoryStream(); SvnTarget target; //If you use Uri you should encode '#' as %23, as Uri's define the # as Fragment separator. //And in this case the fragment is not send to the server. path = path.Replace("#", "%23"); if (SvnTarget.TryParse(GetPath(path).AbsolutePath, out target)) { if (FileWasDeleted(path, changeset)) { return(new MemoryStream()); } var uriTarget = new SvnUriTarget(_root + path, changeset.Value); var svnWriteArgs = new SvnWriteArgs { Revision = changeset.Value }; Client.Write(uriTarget, memoryStream, svnWriteArgs); return(memoryStream); } return(new MemoryStream()); }
/// <summary> /// Build the target from a uri. /// </summary> /// <param name="path"></param> /// <returns></returns> private SvnTarget BuildTarget(Uri path) { SvnTarget target; SvnTarget.TryParse(path.OriginalString, out target); return(target); }
public TTarget GetTarget <TTarget>() where TTarget : SvnTarget { SvnTarget rslt; if (SvnTarget.TryParse(Target, out rslt)) { return(rslt as TTarget); } return(null); }
public TSource GetSource <TSource>() where TSource : SvnTarget { SvnTarget rslt; if (SvnTarget.TryParse(Source, out rslt)) { return(rslt as TSource); } return(null); }
/// <summary> /// Build a target for a particular directory or file from the base given by the current /// arguments. /// </summary> /// <param name="v"></param> /// <returns></returns> public static SvnTarget BuildTarget(string path, string MCCampaign) { SvnTarget target; var url = $"https://svn.cern.ch/reps/atlasoff/Generators/{MCCampaign}JobOptions/trunk/{path}"; if (!SvnTarget.TryParse(url, out target)) { var err = new ArgumentException($"Unable to parse svn url {url}."); throw err; } return(target); }
protected Collection <SvnTarget> GetSvnTargets <TTarget>() where TTarget : SvnTarget { Collection <SvnTarget> rslt = new Collection <SvnTarget>(); foreach (string targetName in Targets) { SvnTarget target; if (SvnTarget.TryParse(targetName, out target) && target is TTarget) { rslt.Add(target); } } return(rslt); }
private void GetSource() { // Check if the directory exists and is writeable. if (!CheckDirectory(dependencyDefinition.LocalPath, true)) { throw new DirectoryNotFoundException("The directory \"" + dependencyDefinition.LocalPath + "\" was not found or could not be created."); } // Make sure we can create a target to the SVN repository SvnTarget target; if (!SvnTarget.TryParse(dependencyDefinition.SvnPath, out target)) { throw new Exception("The SVN path you've specified is not valid. " + "Please provide a valid URL or filesystem path pointing to " + "a valid Subversion resource."); } using (SvnClient client = new SvnClient()) { // Bind the GUI interface to the client SharpSvn.UI.SvnUI.Bind(client, this); } }
public void Path_ParsePaths() { SvnUriTarget ut; SvnPathTarget pt; SvnTarget st; Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/", out ut)); Assert.That(ut.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", out ut)); Assert.That(ut.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(ut.TargetName.Contains("@")); Assert.That(SvnUriTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", true, out ut)); Assert.That(ut.Revision, Is.EqualTo((SvnRevision)123L)); Assert.That(SvnPathTarget.TryParse("C:\\A", out pt)); Assert.That(pt.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(SvnPathTarget.TryParse("C:\\A@123", out pt)); Assert.That(pt.Revision, Is.EqualTo(SvnRevision.None)); Assert.That(pt.TargetName.Contains("@")); Assert.That(SvnPathTarget.TryParse("C:\\@123", true, out pt)); Assert.That(pt.Revision, Is.EqualTo((SvnRevision)123L)); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("http://svn.apache.org/repos/asf/subversion/@123", true, out st)); Assert.That(st, Is.InstanceOf(typeof(SvnUriTarget))); Assert.That(SvnTarget.TryParse("C:\\A", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); Assert.That(SvnTarget.TryParse("C:\\A@123", out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); Assert.That(SvnTarget.TryParse("C:\\@123", true, out st)); Assert.That(st, Is.InstanceOf(typeof(SvnPathTarget))); }
private static void GetLogs(bool console_mode, string application_path, string repository_location, long last_revision, Output_Type output_type) { SvnTarget repository; SvnClient client = new SvnClient(); long current_revision = -1; if (SvnTarget.TryParse(repository_location, out repository) == true) { try { SvnInfoEventArgs info; client.GetInfo(new Uri(repository_location), out info); current_revision = info.Revision; } catch (Exception ex) { Debug.WriteLine(ex.Message); if (console_mode == true) { Console.WriteLine(ex.Message); } } if (last_revision < current_revision) { DataTable datatable = new DataTable("log"); datatable.Columns.Add("Revision", typeof(long)); datatable.Columns.Add("Author", typeof(string)); datatable.Columns.Add("Time", typeof(DateTime)); datatable.Columns.Add("ChangedPaths", typeof(string)); datatable.Columns.Add("LogMessage", typeof(string)); try { System.Collections.ObjectModel.Collection <SvnLogEventArgs> logitems = new System.Collections.ObjectModel.Collection <SvnLogEventArgs>(); SvnLogArgs logargs = new SvnLogArgs(new SvnRevisionRange(current_revision, last_revision + 1)); client.GetLog(new Uri(repository_location), logargs, out logitems); datatable.BeginLoadData(); foreach (SvnLogEventArgs logitem in logitems) { StringBuilder ChangedPaths = new StringBuilder(); if (logitem.ChangedPaths != null) { foreach (SvnChangeItem path in logitem.ChangedPaths) { ChangedPaths.AppendFormat("{1} {2}{0}", Environment.NewLine, path.Action, path.Path); if (path.CopyFromRevision != -1) { ChangedPaths.AppendFormat("{1} -> {2}{0}", Environment.NewLine, path.CopyFromPath, path.CopyFromRevision); } } } DataRow datarow = datatable.NewRow(); datarow["Revision"] = logitem.Revision; datarow["Author"] = logitem.Author; datarow["Time"] = logitem.Time.ToLocalTime(); datarow["ChangedPaths"] = ChangedPaths.ToString(); datarow["LogMessage"] = logitem.LogMessage; datatable.Rows.Add(datarow); } datatable.EndLoadData(); datatable.AcceptChanges(); switch (output_type) { case Output_Type.Console: OutputToConsole(console_mode, application_path, datatable); break; case Output_Type.Txt: OutputToTxt(console_mode, application_path, datatable); break; case Output_Type.XML: OutputToXML(console_mode, application_path, datatable); break; case Output_Type.XMLTransform: OutputToXMLTransform(console_mode, application_path, datatable); break; case Output_Type.RSS: OutputToRSS(console_mode, application_path, datatable); break; default: break; } last_revision = Convert.ToInt32(datatable.Compute("max(Revision)", string.Empty)); System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings.Remove("last_revision"); config.AppSettings.Settings.Add("last_revision", last_revision.ToString()); config.Save(); } catch (Exception ex) { Debug.WriteLine(ex.Message); if (console_mode == true) { Console.WriteLine(ex.Message); } } } client.Dispose(); } else { Debug.WriteLine("Unable to connect to repository"); if (console_mode == true) { Console.WriteLine("Unable to connect to repository"); } } }