使用 C# 从 SharpSvn 获取凭据

发布于 2024-08-06 08:25:36 字数 484 浏览 2 评论 0原文

我正在编写一些 C# 代码来一次性执行对 SVN 的多次提交,就像工具 svnmucc 一样。到目前为止,我一直在使用 SharpSvn 与 SVN 进行其余必要的通信,因此我想我可以利用它来完成以下任务:

如何获取使用的凭据(用户名、密码)夏普Svn?

我想做这样的事情:

using (SvnClient svnClient = new SvnClient())
{
    SomeFictitiousCredentialsClass credentials = svnClient.Authentication.FictitiousGetCachedCredentialsMethod();

    // Call my code that performs svnmucc-like work here, passing username and password
    // obtained from 'credentials' variable.
}

I am writing some C# code to perform multiple commits to SVN in one pass, much like the tool svnmucc. So far I've been using SharpSvn to do the rest of the necessary communication with SVN, so I'm thinking I can take advantage of it to accomplish the following:

How can I get the credentials (username, password) that are used by SharpSvn?

I'd like to do something like this:

using (SvnClient svnClient = new SvnClient())
{
    SomeFictitiousCredentialsClass credentials = svnClient.Authentication.FictitiousGetCachedCredentialsMethod();

    // Call my code that performs svnmucc-like work here, passing username and password
    // obtained from 'credentials' variable.
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Spring初心 2024-08-13 08:25:36

Sharpsvn 没有为您提供 Subversion 凭据的 API。它主要实现 libsvn_client api,在此级别无法访问此数据。

当需要凭据时,SharpSvn 从颠覆库获取回调;在大多数情况下,内置密码存储无法进行身份验证后。

如果您的 svnmucc 代码也使用 Subversion api,您只需插入 subversion 预定义的身份验证处理程序即可。

SharpSvn 本身尚不支持 svnmucc。 (有一些关于有人喜欢将其添加到 SharpSvn 的讨论,但我最近没有收到任何关于此的消息)

Sharpsvn doesn't have an api that provides you the credentials from Subversion. It mostly implements the libsvn_client api, and at this level there is no access to this data.

SharpSvn gets a callback from the subversion libraries when these need credentials; in most cases after the builtin password store fails to authenticate.

If your svnmucc code also uses the Subversion apis, you can just plugin the subversion predefined authentication handlers..

SharpSvn itself doesn't have svnmucc support yet. (There was some talk about somebody who liked to add this to SharpSvn, but I haven't got any news about this lately)

笑梦风尘 2024-08-13 08:25:36

虽然另一个答案对于 SharpSvn 的所有当前版本仍然有效,但 SvnMucc 支持刚刚登陆 SharpSvn 的开发代码。因此很快就可以从 .Net 执行类似 SvnMucc 的操作。

using SharpSvn;

SvnCommitResult cr;
using (SvnMultiCommandClient mucc = new SvnMultiCommandClient("http://my-repos/svn/"))
{
    mucc.CreateDirectory("trunk");
    mucc.CreateDirectory("branches");
    mucc.CreateDirectory("tags");
    mucc.CreateDirectory("trunk/src");
    mucc.SetProperty("", "svn:auto-props", "*.cs = svn:eol-style=native");
    mucc.SetProperty("", "svn:global-ignores", "bin obj");

    mucc.Commit(out cr); // Commit r1
}
using (SvnClient client = new SvnClient())
{
   client.CheckOut("http://my-repos/svn/", @"C:\wc");
}

如果您想从现有的 SvnClient 执行操作,可以使用稍微不同的语法,但这是总体思路。

While the other answer is still valid for all current versions of SharpSvn, SvnMucc support has just landed in the development code for SharpSvn. So soon it will be possible to perform SvnMucc like operations from .Net.

using SharpSvn;

SvnCommitResult cr;
using (SvnMultiCommandClient mucc = new SvnMultiCommandClient("http://my-repos/svn/"))
{
    mucc.CreateDirectory("trunk");
    mucc.CreateDirectory("branches");
    mucc.CreateDirectory("tags");
    mucc.CreateDirectory("trunk/src");
    mucc.SetProperty("", "svn:auto-props", "*.cs = svn:eol-style=native");
    mucc.SetProperty("", "svn:global-ignores", "bin obj");

    mucc.Commit(out cr); // Commit r1
}
using (SvnClient client = new SvnClient())
{
   client.CheckOut("http://my-repos/svn/", @"C:\wc");
}

There is a slightly different syntax available if you would like to perform the operation from an existing SvnClient, but this is the general idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文