gpt4 book ai didi

C# SvnClient 获取授权用户名

转载 作者:行者123 更新时间:2023-11-30 12:55:13 25 4
gpt4 key购买 nike

我似乎找不到通过 C# SvnClient 获取用户名的方法。

在命令行中,您可以在命令提示符中键入“svn auth”,它会在那里显示用户名。

但是,在C# SvnClient API 中就没那么简单了。

API 确实有一个“授权”属性——不幸的是,它没有直接的函数调用来获取用户名。

有人知道吗?

最佳答案

经过长时间的单独搜索,我发现这是可能的。 -- 虽然不漂亮

var cachedItems = SvnClient.Authentication.GetCachedProperties(SvnAuthenticationCacheType.UserNamePassword)

不幸的是,这不会返回用户名或密码的任何公共(public)字段。但是,这确实有一个名为“_filename”的私有(private)字段,可用于获取用户名/密码。 --- 可以使用反射访问。

foreach (var item in cachedItems)
{
///find the matching Uri to the repository you want
if (item.RealmUri.AbsoluteUri == ...)
{
var type = item.GetType();
var fields = type.GetFields();

var filename = fields.First(x => x.Name == "_filename").GetValue(item);

///Now just need to parse the file
using (var streamReader = new StreamReader(new FileStream(filename, FileMode.Open)))
{
while (streamReader.ReadLine() != "username") {}
streamReader.ReadLine(); ///There is 1 garbage line after username before the actual username
return streamReader.ReadLine();
}
}
}

关于C# SvnClient 获取授权用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50732115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com